Skip to content

Commit e838e53

Browse files
committed
fix: fix testing issues
1 parent e28aeca commit e838e53

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

python/test_grammar.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@
66

77
TEST_MODELS_DIR = os.path.join(os.path.dirname(__file__), "..", "test_models")
88

9+
# Semantic errors that the parser cannot detect (only syntax errors are caught)
10+
SEMANTIC_ERROR_FILES = {
11+
"missingreference.uvl",
12+
"wrong_attribute_name.uvl",
13+
"same_feature_names.uvl",
14+
}
15+
916

1017
def get_valid_files():
1118
all_files = glob.glob(os.path.join(TEST_MODELS_DIR, "**", "*.uvl"), recursive=True)
1219
return [f for f in all_files if os.sep + "faulty" + os.sep not in f]
1320

1421

15-
def get_faulty_files():
16-
return glob.glob(os.path.join(TEST_MODELS_DIR, "faulty", "*.uvl"))
22+
def get_faulty_syntax_files():
23+
"""Only return files with syntax errors (not semantic errors)."""
24+
all_faulty = glob.glob(os.path.join(TEST_MODELS_DIR, "faulty", "*.uvl"))
25+
return [f for f in all_faulty if os.path.basename(f) not in SEMANTIC_ERROR_FILES]
1726

1827

1928
def relative_path(file):
@@ -26,7 +35,7 @@ def test_valid_model(uvl_file):
2635
assert tree is not None
2736

2837

29-
@pytest.mark.parametrize("uvl_file", get_faulty_files(), ids=relative_path)
38+
@pytest.mark.parametrize("uvl_file", get_faulty_syntax_files(), ids=relative_path)
3039
def test_faulty_model(uvl_file):
3140
with pytest.raises(Exception):
3241
get_tree(uvl_file)

python/uvl/UVLCustomLexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def atStartOfInput(self):
7373
def handleNewline(self):
7474
new_line = re.sub(r"[^\r\n\f]+", "", self._interp.getText(self._input)) #.replaceAll("[^\r\n\f]+", "")
7575
spaces = re.sub(r"[\r\n\f]+", "", self._interp.getText(self._input)) #.replaceAll("[\r\n\f]+", "")
76-
next = self._input.LA(1)
76+
next_code = self._input.LA(1)
77+
next_char = chr(next_code) if next_code != -1 else ''
7778

78-
if self.opened > 0 or next == '\r' or next == '\n' or next == '\f' or next == '#':
79+
if self.opened > 0 or next_char == '\r' or next_char == '\n' or next_char == '\f' or next_char == '#':
7980
self.skip()
8081
else:
8182
self.emitToken(self.common_token(self.NEWLINE, new_line))

0 commit comments

Comments
 (0)