def expand_to_nodes(self, token, content): node = nodes.List() node.token = token self.builder.append(node, move_actual=True) parse(content, self.register_map, self.register, builder=self.builder, state=self.state) assert self.builder.actual_node == node self.builder.move_up()
def expand_to_nodes(self, level, content): node = nodes.Nadpis() node.level = level self.builder.append(node, move_actual = True) parse(content, self.register_map, self.register, builder=self.builder, state=self.state) assert node == self.builder.actual_node self.builder.move_up()
def expand_to_nodes(self, content): node = nodes.Odstavec() self.builder.append(node, move_actual=False) if isinstance(node.parent, nodes.TextNode): self.builder.replace(node) self.builder.set_actual_node(node) parse(content, self.register_map, self.register, builder=self.builder, state=self.state) assert node == self.builder.actual_node self.builder.move_up()
def expand_to_nodes(self, link, content): node = nodes.Hyperlink() node.link = link self.builder.append(node, move_actual = True) if link == content: tn = nodes.TextNode() tn.content = content self.builder.append(tn, move_actual=False) else: parse(content, self.register_map, self.register, builder=self.builder, state=self.state) self.builder.move_up()
def testProperResolving(self): s = '((odstavec text odstavce))' o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, ParagraphNode) self.assertEquals(o.children[0].children[0].__class__, TextNode) self.assertEquals(o.children[0].children[0].content, 'text odstavce')
def testProperMultipleNested(self): s = "((container ((container ((container text))))))" o = parse(s, self.register_map, document_root=True) self.assertEquals(o.children[0].__class__, DummyNode) self.assertEquals(o.children[0].children[0].__class__, DummyNode) self.assertEquals(o.children[0].children[0].children[0].__class__, DummyNode) self.assertEquals(o.children[0].children[0].children[0].children[0].__class__, TextNode) self.assertEquals(o.children[0].children[0].children[0].children[0].content, "text")
def testProperNestedQuoted(self): # we cannot use odstavec as macro, because it is not parsing it's args s = '((silne "silne silny)) text odstavce"))' o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, StrongNode) self.assertEquals(o.children[0].children[0].__class__, TextNode) self.assertEquals(o.children[0].children[0].content, 'silne silny)) text odstavce')
def testProperNested(self): s = '((odstavec ((silne silny)) text odstavce))' o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, ParagraphNode) self.assertEquals(o.children[0].children[0].__class__, StrongNode) self.assertEquals(o.children[0].children[0].children[0].__class__, TextNode) self.assertEquals(o.children[0].children[0].children[0].content, 'silny') self.assertEquals(o.children[0].children[1].__class__, TextNode) self.assertEquals(o.children[0].children[1].content, ' text odstavce')
def testBadCall(self): s = '((odstavec))' o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, TextNode) self.assertEquals(o.children[0].content, '((odstavec))')
def testCallWithoutMacroName(self): s = "(())" o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, TextNode) self.assertEquals(o.children[0].content, "(())")
def expand_to_nodes(self, content): node = nodes.Article() self.builder.append(node, move_actual = True) parse(content, self.register_map, self.register, builder=self.builder, state=self.state) self.wrap_text_nodes(node) self.builder.move_up()
def expand_to_nodes(self, content): node = nodes.ListItem() self.builder.append(node, move_actual=True) parse(content, self.register_map, self.register, builder=self.builder, state=self.state) self.builder.move_up()
def testManyMacroBeginsEven(self): s = "(((((((()))" o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, TextNode) self.assertEquals(o.children[0].content, "(((((((()))")
def testNegateMacroSyntaxWithTwoNegationsChars(self): s = 2*NEGATION_CHAR+'((odstavec text !odstavce))' o = parse(s, self.register_map, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, TextNode) self.assertEquals(o.children[0].content, NEGATION_CHAR+'((odstavec text !odstavce))')
def test_kwargs_resolved(self): s = '((picture http://pic.png title="My picture"))' o = parse(s, self.register_map, document_root=True) self.assertEquals(1, len(o.children)) self.assertEquals(PictureNode, o.children[0].__class__) self.assertEquals(u"My picture", o.children[0].kwargs['title'])
def testParsingShortArgument(self): s = "((onearg test))" o = parse(s, RegisterMap({OneArgumentMacro: Register()}), document_root=True) self.assertEquals(DummyNode, o.children[0].__class__) self.assertEquals(u"test", o.children[0].children[0].content)
def testNegateParserSyntax(self): s = NEGATION_CHAR+'""strong""' o = parse(s, self.register_map, parsers=parsers_list, document_root=True) self.assertEquals(len(o.children), 1) self.assertEquals(o.children[0].__class__, TextNode) self.assertEquals(o.children[0].content, '""strong""')
def testParsingLongArgumentWithTrailingSlash(self): s = '((onearg "long argument "))' o = parse(s, RegisterMap({OneArgumentMacro : Register()}), document_root = True) self.assertEquals(u"long argument ", o.children[0].children[0].content)
def testParsingLongArgument(self): s = '((onearg "long argument"))' o = parse(s, RegisterMap({OneArgumentMacro : Register()}), document_root = True) self.assertEquals(DummyNode, o.children[0].__class__) self.assertEquals(u"long argument", o.children[0].children[0].content)