def test_match_bracket(self): doc = dedent("""\ hello { world { some test } { okay { } this is a test }} test """) parser = QqParser() parser.parse_init(doc) start = parser.position(0, 6) stop = parser.position(None, 0) out = parser.match_bracket(start, stop) self.assertEqual(out.clipped_line(stop), "} test\n")
def test_scan_after_attribute_tag2(self): doc = dedent("""\ test \\tag this \\tag{inline \\tag{} \\tag}\\tag other tag """) parser = QqParser(allowed_tags={"tag"}) parser.parse_init(doc) start = parser.position(0, 0) stop = parser.position(None, 0) tag_positoin, tag, type, after = parser.locate_tag(start, stop) start = after.copy() before = parser.scan_after_attribute_tag(start, stop) self.assertEqual(start.clipped_line(before), 'this \\tag{inline \\tag{} \\tag}')
def test_inline_tag_contents(self): doc = dedent("""\ haha \\tag{this}{ that}[another]{this }[okay test] stop """) parser = QqParser(allowed_tags={"tag"}) parser.parse_init(doc) start = parser.position(0, 0) stop = parser.position(None, 0) tag_position, tag, type, after = parser.locate_tag(start, stop) self.assertEqual(start.clipped_line(tag_position), "haha ") self.assertEqual(tag, "tag") self.assertEqual(type, "inline") items = parser.inline_tag_contents(after, stop) contents = ["".join(item['start'].lines_before(item['stop'])) for item in items] self.assertEqual(contents, ["this", "\n that", "another", "this\n ", "okay test"]) self.assertEqual([item['type'] for item in items], ['{', '{', '[', '{', '['])