summaryrefslogtreecommitdiff
path: root/tests/test_properties.py
blob: 562778baaca88d935a135669ec14ee0e201a0ee5 (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
# -*- coding: utf-8 -*-
"""
    Properties Tests
    ~~~~~~~~~~~~~~~~

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

import unittest

from pygments.lexers.configs import PropertiesLexer
from pygments.token import Token


class PropertiesTest(unittest.TestCase):
    def setUp(self):
        self.lexer = PropertiesLexer()

    def test_comments(self):
        """
        Assures lines lead by either # or ! are recognized as a comment
        """
        fragment = '! a comment\n# also a comment\n'
        tokens = [
            (Token.Comment, '! a comment'),
            (Token.Text, '\n'),
            (Token.Comment, '# also a comment'),
            (Token.Text, '\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

    def test_leading_whitespace_comments(self):
        fragment = '    # comment\n'
        tokens = [
            (Token.Text, '    '),
            (Token.Comment, '# comment'),
            (Token.Text, '\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

    def test_escaped_space_in_key(self):
        fragment = 'key = value\n'
        tokens = [
            (Token.Name.Attribute, 'key'),
            (Token.Text, ' '),
            (Token.Operator, '='),
            (Token.Text, ' '),
            (Token.Literal.String, 'value'),
            (Token.Text, '\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

    def test_escaped_space_in_value(self):
        fragment = 'key = doubleword\\ value\n'
        tokens = [
            (Token.Name.Attribute, 'key'),
            (Token.Text, ' '),
            (Token.Operator, '='),
            (Token.Text, ' '),
            (Token.Literal.String, 'doubleword\\ value'),
            (Token.Text, '\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

    def test_space_delimited_kv_pair(self):
        fragment = 'key value\n'
        tokens = [
            (Token.Name.Attribute, 'key'),
            (Token.Text, ' '),
            (Token.Literal.String, 'value\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

    def test_just_key(self):
        fragment = 'justkey\n'
        tokens = [
            (Token.Name.Attribute, 'justkey'),
            (Token.Text, '\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

    def test_just_key_with_space(self):
        fragment = 'just\\ key\n'
        tokens = [
            (Token.Name.Attribute, 'just\\ key'),
            (Token.Text, '\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))