Skip to content

Commit

Permalink
Add parser tests for pyk.kore.syntax.String (#4588)
Browse files Browse the repository at this point in the history
Demonstrates the correspondence between KORE strings and Python strings.

Co-authored-by: rv-jenkins <admin@runtimeverification.com>
  • Loading branch information
tothtamas28 and rv-jenkins authored Aug 14, 2024
1 parent df56618 commit 079be45
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pyk/src/tests/unit/kore/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,43 @@ def test_multiary(test_id: str, text: str, expected: list[Pattern]) -> None:
# Then
assert parser.eof
assert actual == expected


STRING_TEST_DATA: Final = (
('', ''),
(' ', ' '),
('foo', 'foo'),
(r'\t', '\t'),
(r'\n', '\n'),
(r'\f', '\f'),
(r'\r', '\r'),
(r'\\', '\\'),
(r'\"', '"'),
(r'\x80', '\x80'),
(r'\x0f', '\x0f'),
(r'\x0F', '\x0f'),
(r'\u03b1', '\u03b1'),
(r'\u03B1', '\u03b1'),
(r'\U0001f642', '\U0001f642'),
(r'\U0001F642', '\U0001f642'),
(r'\x80\x80', '\x80\x80'),
(r'a\u03b1\x80\U0001f642b', 'a\u03b1\x80\U0001f642b'),
)


@pytest.mark.parametrize(
'text,expected',
STRING_TEST_DATA,
ids=[text for text, _ in STRING_TEST_DATA],
)
def test_string(text: str, expected: str) -> None:
# Given
pattern = f'"{text}"'
parser = KoreParser(pattern)

# When
actual = parser.string()

# Then
assert parser.eof
assert actual.value == expected

0 comments on commit 079be45

Please sign in to comment.