Пример #1
0
    def test_tokenize(self):
        # type: () -> None
        tag = '<meta whatever>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_special')

        tag = '<a>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_start')
        self.assertEqual(token.tag, 'a')

        tag = '<br />bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'br')

        tag = '<input>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'input')

        tag = '<input />bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'input')

        tag = '</a>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_end')
        self.assertEqual(token.tag, 'a')

        tag = '{{#with foo}}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'handlebars_start')
        self.assertEqual(token.tag, 'with')

        tag = '{{/with}}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'handlebars_end')
        self.assertEqual(token.tag, 'with')

        tag = '{% if foo %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'django_start')
        self.assertEqual(token.tag, 'if')

        tag = '{% endif %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'django_end')
        self.assertEqual(token.tag, 'if')
Пример #2
0
    def test_tokenize(self) -> None:
        tag = '<meta whatever>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_special')

        tag = '<a>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_start')
        self.assertEqual(token.tag, 'a')

        tag = '<br />bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'br')

        tag = '<input>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'input')

        tag = '<input />bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'input')

        tag = '</a>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_end')
        self.assertEqual(token.tag, 'a')

        tag = '{{#with foo}}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'handlebars_start')
        self.assertEqual(token.tag, 'with')

        tag = '{{/with}}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'handlebars_end')
        self.assertEqual(token.tag, 'with')

        tag = '{% if foo %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'django_start')
        self.assertEqual(token.tag, 'if')

        tag = '{% endif %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'django_end')
        self.assertEqual(token.tag, 'if')
Пример #3
0
    def test_tokenize(self) -> None:
        tag = "<!DOCTYPE html>"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "html_doctype")

        tag = "<a>bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "html_start")
        self.assertEqual(token.tag, "a")

        tag = "<br />bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "html_singleton")
        self.assertEqual(token.tag, "br")

        tag = "<input>bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind,
                         "html_start")  # We later mark this an error.
        self.assertEqual(token.tag, "input")

        tag = "<input />bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "html_singleton")
        self.assertEqual(token.tag, "input")

        tag = "</a>bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "html_end")
        self.assertEqual(token.tag, "a")

        tag = "{{#with foo}}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "handlebars_start")
        self.assertEqual(token.tag, "with")

        tag = "{{/with}}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "handlebars_end")
        self.assertEqual(token.tag, "with")

        tag = "{% if foo %}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "django_start")
        self.assertEqual(token.tag, "if")

        tag = "{% endif %}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "django_end")
        self.assertEqual(token.tag, "if")

        tag = "{% if foo -%}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "jinja2_whitespace_stripped_start")
        self.assertEqual(token.tag, "if")

        tag = "{%- endif %}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "jinja2_whitespace_stripped_end")
        self.assertEqual(token.tag, "if")

        tag = "{%- if foo -%}bla"
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, "jinja2_whitespace_stripped_type2_start")
        self.assertEqual(token.tag, "if")
Пример #4
0
    def test_tokenize(self) -> None:
        tag = '<meta whatever>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_special')

        tag = '<a>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_start')
        self.assertEqual(token.tag, 'a')

        tag = '<br>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'br')

        tag = '<input>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'input')

        tag = '<input />bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_singleton')
        self.assertEqual(token.tag, 'input')

        tag = '</a>bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'html_end')
        self.assertEqual(token.tag, 'a')

        tag = '{{#with foo}}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'handlebars_start')
        self.assertEqual(token.tag, 'with')

        tag = '{{/with}}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'handlebars_end')
        self.assertEqual(token.tag, 'with')

        tag = '{% if foo %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'django_start')
        self.assertEqual(token.tag, 'if')

        tag = '{% endif %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'django_end')
        self.assertEqual(token.tag, 'if')

        tag = '{% if foo -%}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'jinja2_whitespace_stripped_start')
        self.assertEqual(token.tag, 'if')

        tag = '{%- endif %}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'jinja2_whitespace_stripped_end')
        self.assertEqual(token.tag, 'if')

        tag = '{%- if foo -%}bla'
        token = tokenize(tag)[0]
        self.assertEqual(token.kind, 'jinja2_whitespace_stripped_type2_start')
        self.assertEqual(token.tag, 'if')