summaryrefslogtreecommitdiff
path: root/tests/test_templates.py
blob: 326aecbd5b62c82cbc63ad888422cabf2ef29e47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pytest

from pygments.lexers.templates import JavascriptDjangoLexer, MasonLexer, VelocityLexer
from pygments.token import Comment, Token


@pytest.fixture(scope="module")
def lexer():
    yield JavascriptDjangoLexer()

@pytest.fixture(scope='module')
def lexerMason():
    yield MasonLexer()

@pytest.fixture(scope='module')
def lexerVelocity():
    yield VelocityLexer()

def test_do_not_mistake_JSDoc_for_django_comment(lexer):
    """
    Test to make sure the lexer doesn't mistake
    {* ... *} to be a django comment
    """
    text = """/**
               * @param {*} cool
               */
              func = function(cool) {
              };

              /**
               * @param {*} stuff
               */
              fun = function(stuff) {
              };"""
    tokens = lexer.get_tokens(text)
    assert not any(t[0] == Comment for t in tokens)

def test_mason_unnamed_block(lexerMason):
    text = """
            <%class>
            has 'foo';
            has 'bar' => (required => 1);
            has 'baz' => (isa => 'Int', default => 17);
            </%class>
            """
    res = lexerMason.analyse_text(text)
    assert res == 1.0

def test_velocity_macro(lexerVelocity):
    text = """
            #macro(getBookListLink, $readingTrackerResult)
              $readingTrackerResult.getBookListLink()
            #end
            """
    res = lexerVelocity.analyse_text(text)
    assert res == 0.26

def test_velocity_foreach(lexerVelocity):
    text = """
            <ul>
            #foreach( $product in $allProducts )
              <li>$product</li>
            #end
            </ul>
            """
    res = lexerVelocity.analyse_text(text)
    assert res == 0.16

def test_velocity_if(lexerVelocity):
    text = """
            #if( $display )
              <strong>Velocity!</strong>
            #end
            """
    res = lexerVelocity.analyse_text(text)
    assert res == 0.16

def test_velocity_reference(lexerVelocity):
    text = """
            Hello $name!  Welcome to Velocity!
            """
    res = lexerVelocity.analyse_text(text)
    assert res == 0.01