summaryrefslogtreecommitdiff
path: root/tests/test_properties.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2017-01-22 18:50:35 +0000
committerGeorg Brandl <georg@python.org>2017-01-22 18:50:35 +0000
commit041b80fab1922800ae0618fd4d3d8d78bf7063b4 (patch)
tree79540afc389a29e894804229b6ba2dbc78c67760 /tests/test_properties.py
parent635f722ec3eb791e19f41b3231d74923d73bd729 (diff)
parentdbfa7bbacf9ec1a987f632f01c040285269f690b (diff)
downloadpygments-041b80fab1922800ae0618fd4d3d8d78bf7063b4.tar.gz
Merged in tprynn/pygments-main/command-line-lexer-formatter (pull request #559)
Custom Lexer/Formatter File Loading
Diffstat (limited to 'tests/test_properties.py')
-rw-r--r--tests/test_properties.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/test_properties.py b/tests/test_properties.py
new file mode 100644
index 00000000..562778ba
--- /dev/null
+++ b/tests/test_properties.py
@@ -0,0 +1,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)))