diff options
author | Molly Miller <33266253+sysvinit@users.noreply.github.com> | 2020-01-19 19:38:18 +0000 |
---|---|---|
committer | Matthäus G. Chajdas <Anteru@users.noreply.github.com> | 2020-01-19 20:38:18 +0100 |
commit | c786e452f08840d4cc5ac8b3fcb001a218b7a56b (patch) | |
tree | d7257ee1f8a764ca0cb4da4f1044fdecd902a74a /tests | |
parent | 142f6c5938d2c7156bebb0b63b6a404876169143 (diff) | |
download | pygments-git-c786e452f08840d4cc5ac8b3fcb001a218b7a56b.tar.gz |
Correct lexing of Idris compiler directives (#1363)
* Fix lexing of Idris compiler pragmas.
The regex for capturing Idris compiler pragmas did not separate the leading
percent sign from the disjunction of compiler directives correctly, which caused
issues such as "import" or "namespace" keywords to be mishighlighted, due to
confusion with the "%import" and "%name" compiler pragmas.
* Add unit test for Idris compiler directive lexing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_idris.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/test_idris.py b/tests/test_idris.py new file mode 100644 index 00000000..8580bde4 --- /dev/null +++ b/tests/test_idris.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +""" + Basic IdrisLexer Test + ~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2020 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest + +from pygments.token import Keyword, Text, Name, Operator, Literal +from pygments.lexers import IdrisLexer + + +@pytest.fixture(scope='module') +def lexer(): + yield IdrisLexer() + +def test_reserved_word(lexer): + fragment = u'namespace Foobar\n links : String\n links = "abc"' + tokens = [ + (Keyword.Reserved, u'namespace'), + (Text, u' '), + (Keyword.Type, u'Foobar'), + (Text, u'\n'), + (Text, u' '), + (Name.Function, u'links'), + (Text, u' '), + (Operator.Word, u':'), + (Text, u' '), + (Keyword.Type, u'String'), + (Text, u'\n'), + (Text, u' '), + (Text, u' '), + (Text, u'links'), + (Text, u' '), + (Operator.Word, u'='), + (Text, u' '), + (Literal.String, u'"'), + (Literal.String, u'abc'), + (Literal.String, u'"'), + (Text, u'\n') + ] + assert list(lexer.get_tokens(fragment)) == tokens + +def test_compiler_directive(lexer): + fragment = u'%link C "object.o"\n%name Vect xs' + tokens = [ + (Keyword.Reserved, u'%link'), + (Text, u' '), + (Keyword.Type, u'C'), + (Text, u' '), + (Literal.String, u'"'), + (Literal.String, u'object.o'), + (Literal.String, u'"'), + (Text, u'\n'), + (Keyword.Reserved, u'%name'), + (Text, u' '), + (Keyword.Type, u'Vect'), + (Text, u' '), + (Text, u'xs'), + (Text, u'\n') + ] + assert list(lexer.get_tokens(fragment)) == tokens |