Ejemplo n.º 1
0
    def test_comment(self):
        """tests for building Comment nodes"""
        tests = [
            ([tokens.CommentStart(), tokens.Text(text="foobar"),
              tokens.CommentEnd()],
             wrap([Comment("foobar")])),

            ([tokens.CommentStart(), tokens.Text(text="spam"),
              tokens.Text(text="eggs"), tokens.CommentEnd()],
             wrap([Comment("spameggs")])),
        ]
        for test, valid in tests:
            self.assertWikicodeEqual(valid, self.builder.build(test))
Ejemplo n.º 2
0
 def test_integration2(self):
     """an even more audacious test for building a horrible wikicode mess"""
     # {{a|b|{{c|[[d]]{{{e}}}}}}}[[f|{{{g}}}<!--h-->]]{{i|j=&nbsp;}}
     test = [tokens.TemplateOpen(), tokens.Text(text="a"),
             tokens.TemplateParamSeparator(), tokens.Text(text="b"),
             tokens.TemplateParamSeparator(), tokens.TemplateOpen(),
             tokens.Text(text="c"), tokens.TemplateParamSeparator(),
             tokens.WikilinkOpen(), tokens.Text(text="d"),
             tokens.WikilinkClose(), tokens.ArgumentOpen(),
             tokens.Text(text="e"), tokens.ArgumentClose(),
             tokens.TemplateClose(), tokens.TemplateClose(),
             tokens.WikilinkOpen(), tokens.Text(text="f"),
             tokens.WikilinkSeparator(), tokens.ArgumentOpen(),
             tokens.Text(text="g"), tokens.ArgumentClose(),
             tokens.CommentStart(), tokens.Text(text="h"),
             tokens.CommentEnd(), tokens.WikilinkClose(),
             tokens.TemplateOpen(), tokens.Text(text="i"),
             tokens.TemplateParamSeparator(), tokens.Text(text="j"),
             tokens.TemplateParamEquals(), tokens.HTMLEntityStart(),
             tokens.Text(text="nbsp"), tokens.HTMLEntityEnd(),
             tokens.TemplateClose()]
     valid = wrap(
         [Template(wraptext("a"), params=[Parameter(wraptext("1"), wraptext(
         "b"), showkey=False), Parameter(wraptext("2"), wrap([Template(
         wraptext("c"), params=[Parameter(wraptext("1"), wrap([Wikilink(
         wraptext("d")), Argument(wraptext("e"))]), showkey=False)])]),
         showkey=False)]), Wikilink(wraptext("f"), wrap([Argument(wraptext(
         "g")), Comment("h")])), Template(wraptext("i"), params=[
         Parameter(wraptext("j"), wrap([HTMLEntity("nbsp",
         named=True)]))])])
     self.assertWikicodeEqual(valid, self.builder.build(test))
Ejemplo n.º 3
0
 def test_contents(self):
     """test getter/setter for the contents attribute"""
     node = Comment("foobar")
     self.assertEqual("foobar", node.contents)
     node.contents = "barfoo"
     self.assertEqual("barfoo", node.contents)
Ejemplo n.º 4
0
 def test_showtree(self):
     """test Comment.__showtree__()"""
     output = []
     node = Comment("foobar")
     node.__showtree__(output.append, None, None)
     self.assertEqual(["<!--foobar-->"], output)
Ejemplo n.º 5
0
 def test_strip(self):
     """test Comment.__strip__()"""
     node = Comment("foobar")
     self.assertIs(None, node.__strip__())
Ejemplo n.º 6
0
 def test_children(self):
     """test Comment.__children__()"""
     node = Comment("foobar")
     gen = node.__children__()
     self.assertRaises(StopIteration, next, gen)
Ejemplo n.º 7
0
 def test_unicode(self):
     """test Comment.__unicode__()"""
     node = Comment("foobar")
     self.assertEqual("<!--foobar-->", str(node))
Ejemplo n.º 8
0
 def test_contents(self):
     """test getter/setter for the contents attribute"""
     node = Comment("foobar")
     self.assertEqual("foobar", node.contents)
     node.contents = "barfoo"
     self.assertEqual("barfoo", node.contents)
Ejemplo n.º 9
0
 def test_showtree(self):
     """test Comment.__showtree__()"""
     output = []
     node = Comment("foobar")
     node.__showtree__(output.append, None, None)
     self.assertEqual(["<!--foobar-->"], output)
Ejemplo n.º 10
0
 def test_strip(self):
     """test Comment.__strip__()"""
     node = Comment("foobar")
     self.assertIs(None, node.__strip__())
Ejemplo n.º 11
0
 def test_children(self):
     """test Comment.__children__()"""
     node = Comment("foobar")
     gen = node.__children__()
     self.assertRaises(StopIteration, next, gen)
Ejemplo n.º 12
0
 def test_strip(self):
     """test Comment.__strip__()"""
     node = Comment("foobar")
     for a in (True, False):
         for b in (True, False):
             self.assertIs(None, node.__strip__(a, b))
Ejemplo n.º 13
0
 def test_strip(self):
     """test Comment.__strip__()"""
     node = Comment("foobar")
     for a in (True, False):
         for b in (True, False):
             self.assertIs(None, node.__strip__(a, b))
Ejemplo n.º 14
0
 def test_iternodes(self):
     """test Comment.__iternodes__()"""
     node = Comment("foobar")
     gen = node.__iternodes__(None)
     self.assertEqual((None, node), next(gen))
     self.assertRaises(StopIteration, next, gen)