示例#1
0
 def test_var(self):
     content = "<div>{{ bar }}</div>"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(TOKEN_TEXT, '<div>'),
             Token(TOKEN_VAR, "bar"),
             Token(TOKEN_TEXT, '</div>')
         ])
示例#2
0
 def test_str(self):
     t = Token(
         token_type=TOKEN_RAW_HTML,
         contents='<!DOCTYPE html>' +
         '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
         +
         '<title>HTML Document</title></head><body><p><b></b></p></body></html>'
     )
     self.assertEqual('<Raw token: "<!DOCTYPE html><html...">', t.__str__())
示例#3
0
 def test_colon_attr(self):
     content = "<div :html='foo'>"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(token_type=0, contents="<div "),
             Token(TOKEN_DIRECTIVE, "foo")
         ])
     content = '<div :html="bar">'
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(token_type=0, contents="<div "),
             Token(TOKEN_DIRECTIVE, "bar")
         ])
示例#4
0
 def test_token_name(self):
     self.assertEqual(Token(token_type=0, contents='').token_name, 'Text')
     self.assertEqual(Token(token_type=1, contents='').token_name, 'Var')
     self.assertEqual(Token(token_type=2, contents='').token_name, 'Const')
     self.assertEqual(Token(token_type=3, contents='').token_name, 'Comment')
     self.assertEqual(Token(token_type=4, contents='').token_name, 'Raw')
     self.assertEqual(Token(token_type=5, contents='').token_name, 'Binding')
示例#5
0
    def test_combine(self):
        content = "<div>{{ gettext('Hello') }}</div>" \
                  "<div>{{* gettext('Hello') }}</div>" \
                  "<div><!-- Hello -->" \
                  "<span>{{{ Blablabla }}}</span></div>"

        self.assertTokensEqual(
            Lexer(content).tokenize(), [
                Token(token_type=0, contents="<div>"),
                Token(token_type=1, contents="gettext('Hello')"),
                Token(token_type=0, contents="</div><div>"),
                Token(token_type=2, contents="gettext('Hello')"),
                Token(token_type=0, contents="</div><div>"),
                Token(token_type=3, contents="Hello"),
                Token(token_type=0, contents="<span>"),
                Token(token_type=4, contents="Blablabla"),
                Token(token_type=0, contents="</span></div>")
            ])
示例#6
0
 def test_repr(self):
     t = Token(token_type=TOKEN_RAW_HTML, contents='<body><p><b></b></p></body></html>')
     self.assertEqual('Token(token_type=4, contents="<body><p><b></b></p></body></html>")', t.__repr__())
 def test_str(self):
     t = Token(token_type=TOKEN_RAW_HTML, contents='<!DOCTYPE html>' +
           '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' +
           '<title>HTML Document</title></head><body><p><b></b></p></body></html>')
     self.assertEqual('<Raw token: "<!DOCTYPE html><html...">', t.__str__())
示例#8
0
 def test_double_way_binding(self):
     content = "{{@ foo }}"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(TOKEN_DOUBLE_WAY_BINDING, "foo")
         ])
示例#9
0
 def test_const(self):
     content = "{{* bar }}"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(TOKEN_CONST, "bar")
         ])
示例#10
0
 def test_raw_html(self):
     content = "{{{ <div></div> }}}"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(TOKEN_RAW_HTML, "<div></div>")
         ])
示例#11
0
 def test_comments(self):
     content = "<!-- comments -->"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(TOKEN_COMMENT, "comments")
         ])
示例#12
0
 def test_text(self):
     content = "<div></div>"
     self.assertTokensEqual(
         Lexer(content).tokenize(), [
             Token(TOKEN_TEXT, '<div></div>')
         ])