def test_spaces_around_header_string_SHOULD_not_appear_in_header(self): expected = [lists.HeaderContentList([_list_item('item 1'), _list_item('item 2')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' * item 1', ' * item 2 ']) check(self, expected, actual)
def test_single_line_text_blocks(self): check(self, [Paragraph([StringText('text in para 1')]), Paragraph([StringText('text in para 2')])], sut.parse(['text in para 1'] + sut.PARAGRAPH_SEPARATOR_LINES + ['text in para 2']))
def test_list_with_item_multiple_paragraphs_contents_in_middle_of_paragraphs(self): expected = [ Paragraph([StringText('first paragraph')]), lists.HeaderContentList([ _list_item('item 1', [ Paragraph([StringText('line 1 in contents paragraph 1'), StringText('line 2 in contents paragraph 1')]), Paragraph([StringText('line 1 in contents paragraph 2')]), ]), ], self.EXPECTED_LIST_FORMAT), Paragraph([StringText('last paragraph')]), ] actual = sut.parse(['first paragraph', '', '', ' * item 1', '', ' line 1 in contents paragraph 1', '', ' line 2 in contents paragraph 1', '', '', ' line 1 in contents paragraph 2', '', '', 'last paragraph']) check(self, expected, actual)
def test_single_literal_block_w_class(self): check(self, [sut.LiteralLayout(lines_content(['literal line']), 'the-class')], sut.parse(['```:the-class', 'literal line', '```', ]))
def test_list_with_item_multiple_paragraphs_contents_before_other_item(self): expected = [ lists.HeaderContentList([ _list_item('item 1', [ Paragraph([StringText('item 1 contents paragraph 1')]), Paragraph([StringText('item 1 contents paragraph 2')]), ]), _list_item('item 2', [ Paragraph([StringText('item 2 contents paragraph 1')]), ]), ], self.EXPECTED_LIST_FORMAT), Paragraph([StringText('last paragraph')]), ] actual = sut.parse([' * item 1', '', ' item 1 contents paragraph 1', '', '', ' item 1 contents paragraph 2', '', ' * item 2', '', ' item 2 contents paragraph 1', '', 'last paragraph']) check(self, expected, actual)
def test_single_line_text_blocks(self): check(self, [Paragraph([StringText('text 1'), StringText('text 2')])], sut.parse(['text 1'] + sut.TEXT_SEPARATOR_LINES + ['text 2']))
def test_escaping_markup_token_inside_literal_block(self): check(self, [sut.LiteralLayout(lines_content(['```']))], sut.parse(['```', '\\```', '```', ]))
def test_single_list_with_multiple_items_with_other_indentation_level(self): expected = [lists.HeaderContentList([_list_item('item 1'), _list_item('item 2')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' * item 1', ' * item 2']) check(self, expected, actual)
def test_single_list_with_multiple_items_with_trailing_blank_lines(self): expected = [lists.HeaderContentList([_list_item('item 1'), _list_item('item 2')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' * item 1', ' * item 2', '']) check(self, expected, actual)
def test_larger_paragraph_separator(self): check(self, [Paragraph([StringText('text in para 1')]), Paragraph([StringText('text in para 2')])], sut.parse(['text in para 1'] + sut.PARAGRAPH_SEPARATOR_LINES + sut.PARAGRAPH_SEPARATOR_LINES + ['text in para 2']))
def test_single_list_with_multiple_items_separated_by_empty_line(self): expected = [lists.HeaderContentList([_list_item('item 1'), _list_item('item 2')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' * item 1', '', ' * item 2']) check(self, expected, actual)
def test_single_text_block_on_multiple_lines(self): input_lines = ['the', 'text', 'block' ] check(self, [Paragraph([StringText(' '.join(input_lines))])], sut.parse(input_lines))
def test_multi_line_text_blocks(self): input_lines = ['text', '1'] + \ sut.TEXT_SEPARATOR_LINES + \ ['text', '2'] check(self, [Paragraph([StringText('text 1'), StringText('text 2')])], sut.parse(input_lines))
def test_single_list_with_single_item_with_contents_on_next_line(self): expected = [lists.HeaderContentList([ _list_item('item', [ Paragraph([StringText('contents')]), ])], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' 1. item', ' contents', ]) check(self, expected, actual)
def test_literal_block_with_blank_lines_should_not_split_block(self): check(self, [sut.LiteralLayout(lines_content(['first line'] + sut.PARAGRAPH_SEPARATOR_LINES + ['last line']))], sut.parse(['```', 'first line'] + sut.PARAGRAPH_SEPARATOR_LINES + ['last line', '```', ]))
def test_multiple_text_blocks(self): check(self, [Paragraph([StringText('text 1 in para 1'), StringText('text 2 in para 1')]), Paragraph([StringText('text 1 in para 2'), StringText('text 2 in para 2')])], sut.parse(['text 1 in para 1'] + sut.TEXT_SEPARATOR_LINES + ['text 2 in para 1'] + sut.PARAGRAPH_SEPARATOR_LINES + ['text 1 in para 2'] + sut.TEXT_SEPARATOR_LINES + ['text 2 in para 2']))
def test_literal_block_between_paragraph_blocks(self): check(self, [ Paragraph([StringText('para 1')]), sut.LiteralLayout(lines_content(['literal line'])), Paragraph([StringText('para 2')]), ], sut.parse(['para 1'] + sut.PARAGRAPH_SEPARATOR_LINES + ['```', 'literal line', '```'] + sut.PARAGRAPH_SEPARATOR_LINES + ['para 2']))
def test_list_in_middle_of_paragraphs(self): expected = [ Paragraph([StringText('first paragraph')]), lists.HeaderContentList([_list_item('item 1'), _list_item('item 2')], self.EXPECTED_LIST_FORMAT), Paragraph([StringText('last paragraph')]), ] actual = sut.parse(['first paragraph', '', '', ' * item 1', ' * item 2', '', '', 'last paragraph']) check(self, expected, actual)
def test_single_list_with_with_contents(self): expected = [lists.HeaderContentList([ _list_item('item 1', [ Paragraph([StringText('contents 1')]), ]), _list_item('item 2', [ Paragraph([StringText('contents 2')]), ]), ], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' * item 1', ' contents 1', ' * item 2', ' contents 2', ]) check(self, expected, actual)
def test_nested_lists(self): expected = [ lists.HeaderContentList([ _list_item('itemized item 1', [ Paragraph([StringText('item 1 contents paragraph')]), lists.HeaderContentList( [ _list_item('ordered item 1/1', [ Paragraph([StringText('item 1/1 contents paragraph')]), ]), _list_item('ordered item 1/2', []), ], self.EXPECTED_ORDERED_LIST_FORMAT), ]), _list_item('itemized item 2', []), ], self.EXPECTED_ITEMIZED_LIST_FORMAT), ] actual = sut.parse([' * itemized item 1', '', ' item 1 contents paragraph', '', '', ' 1. ordered item 1/1', '', ' item 1/1 contents paragraph', '', ' 1. ordered item 1/2', '', ' * itemized item 2', ]) check(self, expected, actual)
def test_strip_text_strings(self): check(self, [Paragraph([StringText('the text block')])], sut.parse([' the text block ']))
def test_single_text_block_on_single_line(self): check(self, [Paragraph([StringText('the text block')])], sut.parse(['the text block']))
def test_empty_input(self): check(self, [], sut.parse([]))
def test_escaping_markup_token_should_make_contents_be_treated_as_normal_paragraph(self): check(self, [Paragraph([StringText('``` line')])], sut.parse(['\\```', 'line', ]))
def test_escaping_backslash(self): check(self, [Paragraph([StringText('\\``` line')])], sut.parse(['\\\\```', 'line', ]))
def test_missing_closing_brace_should_raise_exception(self): with self.assertRaises(ValueError): sut.parse(['```', 'literal line', ])
def test_single_list_with_single_item_as_last_line(self): expected = [lists.HeaderContentList([_list_item('item')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' 1. item']) check(self, expected, actual)
def test_single_list_with_single_item_followed_by_empty_line(self): expected = [lists.HeaderContentList([_list_item('item')], self.EXPECTED_LIST_FORMAT)] actual = sut.parse([' * item', '']) check(self, expected, actual)