Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support indented entries in IniLexer (#1624)
- Loading branch information
1 parent
f8b097c
commit 9b0218e
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Pygments INI lexer tests | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
:copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
|
||
import pytest | ||
from pygments.lexers.configs import IniLexer | ||
from pygments.token import Token, String, Keyword, Name, Operator | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def lexer(): | ||
yield IniLexer() | ||
|
||
|
||
def test_indented_entries(lexer): | ||
fragment = \ | ||
'[section]\n' \ | ||
' key1=value1\n' \ | ||
' key2=value2\n' | ||
tokens = [ | ||
(Keyword, '[section]'), | ||
(Token.Text, '\n '), | ||
(Name.Attribute, 'key1'), | ||
(Operator, '='), | ||
(String, 'value1'), | ||
(Token.Text, '\n '), | ||
(Name.Attribute, 'key2'), | ||
(Operator, '='), | ||
(String, 'value2'), | ||
(Token.Text, '\n'), | ||
] | ||
assert list(lexer.get_tokens(fragment)) == tokens | ||
|
||
fragment = \ | ||
'[section]\n' \ | ||
' key1 = value1\n' \ | ||
' key2 = value2\n' | ||
tokens = [ | ||
(Keyword, '[section]'), | ||
(Token.Text, '\n '), | ||
(Name.Attribute, 'key1'), | ||
(Token.Text, ' '), | ||
(Operator, '='), | ||
(Token.Text, ' '), | ||
(String, 'value1'), | ||
(Token.Text, '\n '), | ||
(Name.Attribute, 'key2'), | ||
(Token.Text, ' '), | ||
(Operator, '='), | ||
(Token.Text, ' '), | ||
(String, 'value2'), | ||
(Token.Text, '\n'), | ||
] | ||
assert list(lexer.get_tokens(fragment)) == tokens | ||
|
||
fragment = \ | ||
'[section]\n' \ | ||
' key 1 = value 1\n' \ | ||
' key 2 = value 2\n' | ||
tokens = [ | ||
(Keyword, '[section]'), | ||
(Token.Text, '\n '), | ||
(Name.Attribute, 'key 1'), | ||
(Token.Text, ' '), | ||
(Operator, '='), | ||
(Token.Text, ' '), | ||
(String, 'value 1'), | ||
(Token.Text, '\n '), | ||
(Name.Attribute, 'key 2'), | ||
(Token.Text, ' '), | ||
(Operator, '='), | ||
(Token.Text, ' '), | ||
(String, 'value 2'), | ||
(Token.Text, '\n'), | ||
] | ||
assert list(lexer.get_tokens(fragment)) == tokens |