def test(self): d = token.Document(['# heading 1', '\n', 'hello\n', 'world\n']) output = renderer.get_ast(d) target = { 'type': 'Document', 'footnotes': {}, 'children': [{ 'type': 'Heading', 'level': 1, 'children': [{ 'type': 'RawText', 'content': 'heading 1' }] }, { 'type': 'Paragraph', 'children': [{ 'type': 'RawText', 'content': 'hello world' }] }] } self.assertEqual(output, target)
def test_store(self): lines = ['[key 1]: value1\n', '[key 2]: value2\n'] token = block_token.Document(lines) self.assertEqual(token.footnotes, { "key 1": ("value1", ""), "key 2": ("value2", "") })
def test_parse_opening_bracket_as_paragraph( self): # ... and no error is raised lines = ['[\n'] token = block_token.Document(lines) self.assertEqual(len(token.footnotes), 0) self.assertEqual(len(token.children), 1) self.assertIsInstance(token.children[0], block_token.Paragraph) self.assertEqual(token.children[0].children[0].content, '[')
def test_parse_with_title(self): lines = [ '[key 1]: value1 "title1"\n', '[key 2]: value2\n', '"title2"\n' ] token = block_token.Document(lines) self.assertEqual(token.footnotes, { "key 1": ("value1", "title1"), "key 2": ("value2", "title2") })
def test_parse_opening_brackets_as_paragraph( self): # ... and no lines are skipped lines = ['[\n', '[ \n', ']\n'] token = block_token.Document(lines) self.assertEqual(len(token.footnotes), 0) self.assertEqual(len(token.children), 1) para = token.children[0] self.assertIsInstance(para, block_token.Paragraph) self.assertEqual( len(para.children), 5, 'expected: RawText, LineBreak, RawText, LineBreak, RawText') self.assertEqual(para.children[0].content, '[')
def format_help_text(self, ctx: click.Context, formatter: click.formatting.HelpFormatter): """ Writes the help text to the formatter if it exists. :param ctx: :param formatter: """ doc = block_token.Document(self.help or '') with TerminalRenderer() as renderer: rendered_doc = indent(renderer.render(doc).strip(), " ") if resolve_color_default(self._colour) is False: # Also remove 'COMBINING LONG STROKE OVERLAY', used for strikethrough. rendered_doc = strip_ansi(rendered_doc).replace('̶', '') formatter.write('\n') formatter.write(rendered_doc) formatter.write('\n')
def test_parse_with_para_right_after(self): lines = [ '[key 1]: value1\n', # 'something1\n', # if uncommented, # this and the next line should be treated as a paragraph # - this line gets skipped instead now '[key 2]: value2\n', 'something2\n', '\n', '[key 3]: value3\r\n', # '\r', or any other whitespace 'something3\n' ] token = block_token.Document(lines) self.assertEqual( token.footnotes, { "key 1": ("value1", ""), "key 2": ("value2", ""), "key 3": ("value3", "") }) self.assertEqual(len(token.children), 2) self.assertIsInstance(token.children[0], block_token.Paragraph) self.assertEqual(token.children[0].children[0].content, "something2") self.assertEqual(token.children[1].children[0].content, "something3")
def test_store_footnote(self): lines = ['[key 1]: value 1\n', '[key 2]: value 2\n'] document = block_token.Document(lines) self.assertEqual(document.footnotes['key 1'], 'value 1') self.assertEqual(document.footnotes['key 2'], 'value 2')
def test_contains(self): lines = ['# heading\n', '\n', 'paragraph\n', 'with\n', '`code`\n'] token = block_token.Document(lines) self.assertTrue('heading' in token) self.assertTrue('code' in token) self.assertFalse('foo' in token)
def test_auto_splitlines(self): lines = "some\ncontinual\nlines\n" document = block_token.Document(lines) self.assertIsInstance(document.children[0], block_token.Paragraph) self.assertEqual(len(document.children), 1)