from django.test import TestCase from markdown import Markdown from wiki.core import markdown from wiki.plugins.macros.mdx.toc import WikiTocExtension from tests.base import RequireRootArticleMixin from tests.base import TestBase class TocMacroTests(TestCase): maxDiff = None def test_toc_renders_table_of_content(self): """Verifies that the [TOC] wiki code renders a Table of Content""" md = Markdown(extensions=["extra", WikiTocExtension()]) text = ( "[TOC]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
\n' "\n" "
\n" '

First title.

\n' "

Paragraph 1

\n" '

Subsection

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_with_kwargs(self): """Verifies that the [TOC] wiki code renders a Table of Content""" md = Markdown(extensions=["extra", WikiTocExtension(title="test")]) text = ( "[TOC]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
test\n" "
\n" '

First title.

\n' "

Paragraph 1

\n" '

Subsection

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) class TocMacroTestsInWiki(RequireRootArticleMixin, TestBase): def test_toc_renders_table_of_content_in_wiki(self): md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_with_toc_class(self): md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC toc_class:'nontoc test']\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_with_kwargs(self): md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC title:test]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
test\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_with_depth(self): md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC toc_depth:1]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_with_multi_kwargs(self): md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC title:'test' toc_depth:'1' anchorlink:'True']\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
test\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_wrong_type(self): md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC anchorlink:Yes]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_test_bool_one(self): # Test if the integer is 1 and should be True md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC anchorlink:1]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_test_bool_zero(self): # Test if the integer is zero and should be false md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC anchorlink:0]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output) def test_toc_renders_table_of_content_in_wiki_test_bool_wrong(self): # Test if the integer is wrong value md = markdown.ArticleMarkdown(article=self.root_article) text = ( "[TOC anchorlink:5]\n" "\n" "# First title.\n" "\n" "Paragraph 1\n" "\n" "## Subsection\n" "\n" "Paragraph 2" ) expected_output = ( '
Contents\n" "
\n" '

First title.[edit]

\n' "

Paragraph 1

\n" '

Subsection[edit]

\n' "

Paragraph 2

" ) self.assertEqual(md.convert(text), expected_output)