Exemple #1
0
 def test_html_entity(self):
     """tests for building HTMLEntity nodes"""
     tests = [
         ([
             tokens.HTMLEntityStart(),
             tokens.Text(text="nbsp"),
             tokens.HTMLEntityEnd()
         ], wrap([HTMLEntity("nbsp", named=True, hexadecimal=False)])),
         ([
             tokens.HTMLEntityStart(),
             tokens.HTMLEntityNumeric(),
             tokens.Text(text="107"),
             tokens.HTMLEntityEnd()
         ], wrap([HTMLEntity("107", named=False, hexadecimal=False)])),
         ([
             tokens.HTMLEntityStart(),
             tokens.HTMLEntityNumeric(),
             tokens.HTMLEntityHex(char="X"),
             tokens.Text(text="6B"),
             tokens.HTMLEntityEnd()
         ],
          wrap([
              HTMLEntity("6B", named=False, hexadecimal=True, hex_char="X")
          ])),
     ]
     for test, valid in tests:
         self.assertWikicodeEqual(valid, self.builder.build(test))
Exemple #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))