Exemplo n.º 1
0
 def testParse02(self):
     node=S.RootNode(globalTagDict=S.BaseTags)
     node.parse(S.lex("Pooh, ahoy!\n<:set x y:>\n"))
     self.assert_(len(node.children)==3, "expected 3 children, got: %d" % len(node.children))
     k=node.children[1]
     self.assert_(k.tagName=='set', "expected tagName 'set', got: %s" % k.tagName)
     self.failUnless(k.args==['x', 'y'], "unexpected args: %s" % str(k.args))
     self.failUnless(k._parsed_args=={'name' : 'x', 'value' : 'y'},
                     "unexpected _parsed_args: %s" % str(k._parsed_args))        
Exemplo n.º 2
0
 def testParseVal03(self):
     node=S.ValTag()
     expr='"this is a quoted string"'
     s='<:val %s:>' % expr
     g=S.lex(s)
     self.assertEquals(g.next().tokenType, S.t_START_TAG)
     self.assertEquals(g.next().text, 'val')
     node.parse(g)
     c=S.PythonCodeOutputStream()
     node.genCode(c)
     self.assertEquals(c.getvalue().strip(), "__h.stml.write_val('this is a quoted string', OUTPUT, None)")
Exemplo n.º 3
0
 def testParseVal02(self):
     node=S.ValTag()
     expr="4"
     s='<:val `%s` html:>' % expr
     g=S.lex(s)
     self.assertEquals(g.next().tokenType, S.t_START_TAG)
     self.assertEquals(g.next().text, 'val')
     node.parse(g)
     c=S.PythonCodeOutputStream()
     node.genCode(c)
     self.assertEquals(c.getvalue().strip(), "__h.stml.write_val(4, OUTPUT, 'html')")
Exemplo n.º 4
0
 def testParseSet01(self):
     node=S.SetTag()
     name="angst"
     value="pooh"
     s='<:set %s %s:>' % (name, value)
     g=S.lex(s)
     self.assertEquals(g.next().tokenType, S.t_START_TAG)
     self.assertEquals(g.next().text, 'set')
     node.parse(g)
     c=S.PythonCodeOutputStream()
     node.genCode(c)
     self.assertEquals(c.getvalue().strip(), "angst=('pooh')")
Exemplo n.º 5
0
 def testParseFor01(self):
     node=S.ForTag()
     expr='range(3)'
     name='x'
     s="<:for `%s` %s:>.<:else:>+<:/for:>" % (expr, name)
     g=S.lex(s)
     self.assertEquals(g.next().tokenType, S.t_START_TAG)
     self.assertEquals(g.next().text, 'for')
     node.parse(g)
     c=S.PythonCodeOutputStream()
     node.genCode(c)
     output=c.getvalue()
     expected="for %s in %s:\n    pass\n    OUTPUT.write('.')\nelse:\n    pass\n    OUTPUT.write('+')\n" % (name, expr)
     self.assertEquals(output, expected)
Exemplo n.º 6
0
 def testParseCall01(self):
     node=S.CallTag()
     expr="x+=3"
     s="<:call `%s`:>" % expr
     g=S.lex(s)
     self.assertEquals(g.next().tokenType, S.t_START_TAG)
     self.assertEquals(g.next().text, 'call')
     node.parse(g)
     self.assertEquals(len(node.args), 1)
     self.assertEquals(node.args[0].text, expr )
     c=S.PythonCodeOutputStream()
     node.genCode(c)
     self.assertEquals(c.getvalue().strip(),
                       expr)
Exemplo n.º 7
0
    def testLex2(self):
        g=S.lex(_stml2)
        expected=[S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_TAGWORD,
                  S.t_EXPR, 
                  S.t_END_TAG,
                  S.t_TEXT,
                  S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_EXPR,
                  S.t_END_TAG,
                  S.t_TEXT,
                  S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_EXPR,
                  S.t_END_TAG,
                  S.t_TEXT,
                  S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_EXPR,
                  S.t_END_TAG,
                  S.t_TEXT,
                  S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_EXPR,
                  S.t_TAGWORD,
                  S.t_END_TAG,
                  S.t_TEXT,
                  S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_EXPR,
                  S.t_END_TAG,
                  S.t_TEXT,
                  S.t_START_TAG,
                  S.t_TAGNAME,
                  S.t_END_TAG,
                  ]

        for e in expected:
            self.assertTokenType(e, g.next())
        self.assertRaises(StopIteration, g.next)
Exemplo n.º 8
0
 def testParse04(self):
     node=S.RootNode(globalTagDict=S.BaseTags)
     node.parse(S.lex(_stml2))
     k=[x for x in node.children if isinstance(x, S.parser.Node)]
     self.failUnless(len(k)==5, "expected 5 children, got: %d" % len(k))
Exemplo n.º 9
0
 def testParse03(self):
     node=S.RootNode(globalTagDict=S.BaseTags)
     self.assertRaises(S.ParseError,
                       node.parse,
                       S.lex(_stml1))