diff --git a/mathics_scanner/escape_sequences.py b/mathics_scanner/escape_sequences.py index b0675b9..ef9b3e1 100644 --- a/mathics_scanner/escape_sequences.py +++ b/mathics_scanner/escape_sequences.py @@ -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 diff --git a/test/test_escape_sequences.py b/test/test_escape_sequences.py index f963108..4b912e4 100644 --- a/test/test_escape_sequences.py +++ b/test/test_escape_sequences.py @@ -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