Skip to content

Commit

Permalink
Merge pull request #57 from watermarkhu/patch-rlc
Browse files Browse the repository at this point in the history
patch rlc, update test to use fixture
  • Loading branch information
watermarkhu authored May 11, 2024
2 parents efc1dd3 + 4d336d3 commit 1683a2d
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -- Project information -----------------------------------------------------

project = "Texmate Grammar Python"
version = "0.5.1"
version = "0.5.2"
copyright = f"{date.today().year}, Mark Shui Hu"
author = "Mark Shui Hu"

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "textmate-grammar-python"
version = "0.5.1"
version = "0.5.2"
description = "A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python."
authors = ["Mark Shui Hu <watermarkhu@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/textmate_grammar/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.1"
__version__ = "0.5.2"
2 changes: 2 additions & 0 deletions src/textmate_grammar/parsers/matlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def _remove_line_continuations(self, input: str) -> str:
"""
Removes line continuations from the input text.
"""
if "..." not in input:
return input
output = ""
for split in input.split("..."):
matching = re.search(r"\n[\t\f\v ]*", split)
Expand Down
7 changes: 0 additions & 7 deletions test/unit/matlab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
import logging

from textmate_grammar.parsers.matlab import MatlabParser

logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger("textmate_grammar").setLevel(logging.INFO)
parser = MatlabParser()
12 changes: 12 additions & 0 deletions test/unit/matlab/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging

import pytest
from textmate_grammar.parsers.matlab import MatlabParser


@pytest.fixture
def parser():
logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger("textmate_grammar").setLevel(logging.INFO)
return MatlabParser(remove_line_continuations=False)

3 changes: 1 addition & 2 deletions test/unit/matlab/test_anonymous_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -194,7 +193,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_anonymous_function(check, expected):
def test_anonymous_function(parser, check, expected):
"""Test anonymous function"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_comment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -46,7 +45,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_comment(check, expected):
def test_comment(parser, check, expected):
"""Test comment"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
7 changes: 3 additions & 4 deletions test/unit/matlab/test_constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser


@pytest.mark.parametrize(
Expand All @@ -18,23 +17,23 @@
"pi",
],
)
def test_numeric(check):
def test_numeric(parser, check):
"""Test constant numeric"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
assert element.children[0].token == "constant.numeric.matlab", MSG_NOT_PARSED


@pytest.mark.parametrize("check", ["NaN", "nan", "NaT", "nat"])
def test_value_representations(check):
def test_value_representations(parser, check):
"""Test constant value representations"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
assert element.children[0].token == "constant.language.nan.matlab", MSG_NOT_PARSED


@pytest.mark.parametrize("check", ["on", "off", "false", "true"])
def test_binary(check):
def test_binary(parser, check):
"""Test constant binary"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_control_statement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand All @@ -22,7 +21,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_control_statement(check, expected):
def test_control_statement(parser, check, expected):
"""Test control statement"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_global_persistent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand All @@ -23,7 +22,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_global_persistent(check, expected):
def test_global_persistent(parser, check, expected):
"""Test global persistent"""
element = parser.parse_string(check)
assert element is not None, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -41,7 +40,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_imports(check, expected):
def test_imports(parser, check, expected):
"""Test imports"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_line_continuation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand All @@ -15,7 +14,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_line_continuation(check, expected):
def test_line_continuation(parser, check, expected):
"""Test line continuation"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
7 changes: 3 additions & 4 deletions test/unit/matlab/test_numbers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser


@pytest.mark.parametrize(
"check", ["1", ".1", "1.1", ".1e1", "1.1e1", "1e1", "1i", "1j", "1e2j"]
)
def test_decimal(check):
def test_decimal(parser, check):
"""Test numbers decimal"""
element = parser.parse_string(check)
assert element, MSG_NOT_PARSED
Expand All @@ -34,7 +33,7 @@ def test_decimal(check):
"0xFu64",
],
)
def test_hex(check):
def test_hex(parser, check):
"""Test numbers hex"""
element = parser.parse_string(check)
assert element, MSG_NOT_PARSED
Expand All @@ -60,7 +59,7 @@ def test_hex(check):
"0b1u64",
],
)
def test_binary(check):
def test_binary(parser, check):
"""Test numbers binary"""
element = parser.parse_string(check)
element.children[0].flatten()
Expand Down
9 changes: 4 additions & 5 deletions test/unit/matlab/test_operators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -63,7 +62,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_control_statement(check, expected):
def test_control_statement(parser, check, expected):
"""Test operator control statements"""
element = parser.parse_string(check)
if expected:
Expand All @@ -77,7 +76,7 @@ def test_control_statement(check, expected):
"check",
["a+b", "a-b", "a*b", "a.*b", "a/b", "a./b", "a\\b", "a.\\b", "a^b", "a.^b"],
)
def test_arithmetic(check):
def test_arithmetic(parser, check):
"""Test arithmatic operators"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand All @@ -87,15 +86,15 @@ def test_arithmetic(check):


@pytest.mark.parametrize("check", ["a==b", "a~=b", "a&b", "a&&b", "a|b", "a||b"])
def test_logical(check):
def test_logical(parser, check):
"""Test logical operators"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
assert element.children[1].token == "keyword.operator.logical.matlab", MSG_NO_MATCH


@pytest.mark.parametrize("check", ["a>b", "a>=b", "a<b", "a<=b"])
def test_comparative(check):
def test_comparative(parser, check):
"""Test comparative operators"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_punctuation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -32,7 +31,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_punctuation(check, expected):
def test_punctuation(parser, check, expected):
"""Test punctuation"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_readwrite_operations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -73,7 +72,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_readwrite_operation(check, expected):
def test_readwrite_operation(parser, check, expected):
"""Test read/write operations"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
3 changes: 1 addition & 2 deletions test/unit/matlab/test_string.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

test_vector = {}

Expand Down Expand Up @@ -33,7 +32,7 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_string(check, expected):
def test_string(parser, check, expected):
"Test strings"
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
5 changes: 2 additions & 3 deletions test/unit/matlab/test_transpose.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser

conjugate_transpose_test_vector = {}

Expand Down Expand Up @@ -78,15 +77,15 @@


@pytest.mark.parametrize("check,expected", conjugate_transpose_test_vector.items())
def test_conjugate_transpose(check, expected):
def test_conjugate_transpose(parser, check, expected):
"""Test conjugate transpose"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
assert element.to_dict() == expected, MSG_NOT_PARSED


@pytest.mark.parametrize("check,expected", transpose_test_vector.items())
def test_transpose(check, expected):
def test_transpose(parser, check, expected):
"""Test transpose"""
element = parser.parse_string(check)
assert element, MSG_NO_MATCH
Expand Down
8 changes: 3 additions & 5 deletions test/unit/matlab/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from textmate_grammar.handler import ContentHandler

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser as matlabParser

parser = matlabParser.repository["validators"]

test_vector = {}

Expand Down Expand Up @@ -145,9 +142,10 @@


@pytest.mark.parametrize("check,expected", test_vector.items())
def test_validators(check, expected):
def test_validators(parser, check, expected):
"""Test validators"""
parsed, elements, _ = parser.parse(ContentHandler(check))
validatorParser = parser.repository["validators"]
parsed, elements, _ = validatorParser.parse(ContentHandler(check))

assert parsed, MSG_NO_MATCH
assert elements[0].to_dict() == expected, MSG_NOT_PARSED
3 changes: 1 addition & 2 deletions test/unit/matlab/test_variables.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import pytest

from ...unit import MSG_NO_MATCH, MSG_NOT_PARSED
from . import parser


@pytest.mark.parametrize("check", ["nargin", "nargout", "varargin", "varargout"])
def test_variables(check):
def test_variables(parser, check):
"""Test variables"""
element = parser.parse_string(check)
assert element, MSG_NOT_PARSED
Expand Down

0 comments on commit 1683a2d

Please sign in to comment.