|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +test_note_blocks_extension |
| 5 | +---------------------------------- |
| 6 | +
|
| 7 | +Tests for `docdown.note_blocks` module. |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import absolute_import, print_function, unicode_literals |
| 11 | + |
| 12 | +import unittest |
| 13 | + |
| 14 | +import markdown |
| 15 | + |
| 16 | + |
| 17 | +class PlatformSectionExtensionTest(unittest.TestCase): |
| 18 | + """ |
| 19 | + Integration test with markdown for :class:`docdown.platform_section.PlatformSectionExtension` |
| 20 | + """ |
| 21 | + MARKDOWN_EXTENSIONS = ['docdown.platform_section'] |
| 22 | + |
| 23 | + def build_config_for_platform_section(self, section): |
| 24 | + return { |
| 25 | + 'docdown.platform_section': { |
| 26 | + 'platform_section': section, |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + def test_section_does_not_match(self): |
| 31 | + text = ('@![asdf]\n' |
| 32 | + 'some content\nnot shown\n\n' |
| 33 | + '!@') |
| 34 | + |
| 35 | + html = markdown.markdown( |
| 36 | + text, |
| 37 | + extension_configs=self.build_config_for_platform_section('Android'), |
| 38 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 39 | + output_format='html5' |
| 40 | + ) |
| 41 | + expected_output = '' |
| 42 | + self.assertEqual(expected_output, html) |
| 43 | + |
| 44 | + def test_section_does_match(self): |
| 45 | + text = ('@![asdf]\n' |
| 46 | + 'some content\nshown\n\n' |
| 47 | + '!@ \n') |
| 48 | + |
| 49 | + html = markdown.markdown( |
| 50 | + text, |
| 51 | + extension_configs=self.build_config_for_platform_section('asdf'), |
| 52 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 53 | + output_format='html5' |
| 54 | + ) |
| 55 | + expected_output = '<p>some content\nshown</p>' |
| 56 | + self.assertEqual(expected_output, html) |
| 57 | + |
| 58 | + def test_section_markdown_case_insensitive(self): |
| 59 | + text = ('@![ASDF]\n' |
| 60 | + 'some content\nshown\n\n' |
| 61 | + '!@\n') |
| 62 | + |
| 63 | + html = markdown.markdown( |
| 64 | + text, |
| 65 | + extension_configs=self.build_config_for_platform_section('asdf'), |
| 66 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 67 | + output_format='html5' |
| 68 | + ) |
| 69 | + expected_output = '<p>some content\nshown</p>' |
| 70 | + self.assertEqual(expected_output, html) |
| 71 | + |
| 72 | + def test_section_config_case_insensitive(self): |
| 73 | + text = ('@![asdf]\n' |
| 74 | + 'some content\nshown\n\n' |
| 75 | + '!@ \n') |
| 76 | + |
| 77 | + html = markdown.markdown( |
| 78 | + text, |
| 79 | + extension_configs=self.build_config_for_platform_section('ASDF'), |
| 80 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 81 | + output_format='html5' |
| 82 | + ) |
| 83 | + expected_output = '<p>some content\nshown</p>' |
| 84 | + self.assertEqual(expected_output, html) |
| 85 | + |
| 86 | + def test_multiple_platforms_section(self): |
| 87 | + text = ('@![asdf,QwErTy]\n' |
| 88 | + 'some content\nshown\n\n' |
| 89 | + '!@\n') |
| 90 | + |
| 91 | + html = markdown.markdown( |
| 92 | + text, |
| 93 | + extension_configs=self.build_config_for_platform_section('qwerty'), |
| 94 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 95 | + output_format='html5' |
| 96 | + ) |
| 97 | + expected_output = '<p>some content\nshown</p>' |
| 98 | + self.assertEqual(expected_output, html) |
| 99 | + |
| 100 | + def test_multiple_sections(self): |
| 101 | + text = ('@![asdf,QwErTy]\n' |
| 102 | + 'some content\nnot shown\n\n' |
| 103 | + '!@\n' |
| 104 | + '\n' |
| 105 | + '@![zxcv]\n' |
| 106 | + 'some content\nshown\n\n' |
| 107 | + '!@\n') |
| 108 | + |
| 109 | + html = markdown.markdown( |
| 110 | + text, |
| 111 | + extension_configs=self.build_config_for_platform_section('zxcv'), |
| 112 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 113 | + output_format='html5' |
| 114 | + ) |
| 115 | + expected_output = '<p>some content\nshown</p>' |
| 116 | + self.assertEqual(expected_output, html) |
| 117 | + |
| 118 | + def test_multiple_sections_with_code_snippet(self): |
| 119 | + text = ('@![iOS]\n' |
| 120 | + 'some iOS content not shown\n\n' |
| 121 | + '!@\n' |
| 122 | + '\n' |
| 123 | + '@![Android]\n' |
| 124 | + 'some Android content shown\n\n' |
| 125 | + '``` java\n' |
| 126 | + 'String java = "asdf";\n' |
| 127 | + '```\n' |
| 128 | + '!@\n') |
| 129 | + |
| 130 | + html = markdown.markdown( |
| 131 | + text, |
| 132 | + extension_configs=self.build_config_for_platform_section('Android'), |
| 133 | + extensions=self.MARKDOWN_EXTENSIONS, |
| 134 | + output_format='html5' |
| 135 | + ) |
| 136 | + expected_output = '<p>some Android content shown</p>\n<p>``` java\nString java = "asdf";</p>' |
| 137 | + self.assertEqual(expected_output, html) |
0 commit comments