summaryrefslogtreecommitdiff
path: root/tests/test_yang.py
blob: 1de57d0510ac6dd25d4f94642356077ef33020e2 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
"""
    Basic Yang Test
    ~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import pytest

from pygments.token import Operator, Number, Text, Token
from pygments.lexers import YangLexer

@pytest.fixture(scope='module')
def lexer():
    yield YangLexer()

def test_namespace_1(lexer):
    """
    Namespace `urn:test:std:yang` should not be explicitly highlighted
    """
    fragment = u'namespace urn:test:std:yang;\n'
    tokens = [
        (Token.Keyword, u'namespace'),
        (Token.Text.Whitespace, u' '),
        (Token.Name.Variable, u'urn:test:std:yang'),
        (Token.Punctuation, u';'),
        (Token.Text.Whitespace, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens

def test_namespace_2(lexer):
    """
    namespace-prefix `yang` should be explicitly highlighted
    """
    fragment = u'type yang:counter64;\n'
    tokens = [
        (Token.Keyword, u'type'),
        (Token.Text.Whitespace, u' '),
        (Token.Name.Namespace, u'yang'),
        (Token.Punctuation, u':'),
        (Token.Name.Variable, u'counter64'),
        (Token.Punctuation, u';'),
        (Token.Text.Whitespace, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens

def test_revision_date(lexer):
    """
    Revision-date `2020-08-03` should be explicitly highlighted
    """
    fragment = u'revision 2020-03-08{\n'
    tokens = [
        (Token.Keyword, u'revision'),
        (Token.Text.Whitespace, u' '),
        (Token.Name.Label, u'2020-03-08'),
        (Token.Punctuation, u'{'),
        (Token.Text.Whitespace, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens

def test_integer_value(lexer):
    """
    Integer value `5` should be explicitly highlighted
    """
    fragment = u'value 5;\n'
    tokens = [
        (Token.Keyword, u'value'),
        (Token.Text.Whitespace, u' '),
        (Token.Number.Integer, u'5'),
        (Token.Punctuation, u';'),
        (Token.Text.Whitespace, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens

def test_string_value(lexer):
    """
    String value `"5"` should be not explicitly highlighted
    """
    fragment = u'value "5";\n'
    tokens = [
        (Token.Keyword, u'value'),
        (Token.Text.Whitespace, u' '),
        (Token.String.Double, u'"5"'),
        (Token.Punctuation, u';'),
        (Token.Text.Whitespace, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens

def test_float_value(lexer):
    """
    Float value `1.1` should be explicitly highlighted
    """
    fragment = u'yang-version 1.1;\n'
    tokens = [
        (Token.Keyword, u'yang-version'),
        (Token.Text.Whitespace, u' '),
        (Token.Number.Float, u'1.1'),
        (Token.Punctuation, u';'),
        (Token.Text.Whitespace, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens