Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mathics_scanner/escape_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def parse_escape_sequence(
if i == len(source_text):
# Note: named characters do not have \n's in them. (Is this right)?
# FIXME: decide what to do here.
raise NamedCharacterSyntaxError("Syntax", "sntufn", source_text[pos:])
raise NamedCharacterSyntaxError("sntufn", source_text[pos:])

named_character = parse_named_character(source_text, pos, i)
if named_character is None:
raise NamedCharacterSyntaxError("Syntax", "sntufn", source_text[pos:i])
raise NamedCharacterSyntaxError("sntufn", source_text[pos:i])

result += named_character
pos = i + 1
Expand Down
20 changes: 20 additions & 0 deletions test/test_escape_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ def test_invalid_named_character_sequences():
parse_escape_sequence(text, 1, is_in_string=False)


@pytest.mark.parametrize(
("text", "name"),
[
(r"\[Fake]", "Fake"),
(r"\[Alpha\]", "Alpha\\"),
(r"\[\Sigma]", "\\Sigma"),
(r"\[Theta", "Theta"),
],
)
def test_invalid_named_character_message(text, name):
"""The error carries the "sntufn" tag and the unknown name as its first argument,
which is what the Syntax::sntufn message template expects."""
with pytest.raises(NamedCharacterSyntaxError) as excinfo:
parse_escape_sequence(text, 1, is_in_string=False)
error = excinfo.value
assert error.name == "Syntax"
assert error.tag == "sntufn"
assert error.args[0] == name


def test_invalid_number_encoding():
for text in (
# Octal
Expand Down
Loading