From 4e4b916cbb989886b276c4c4e908c2cb59c0b53c Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 7 Sep 2023 11:18:26 +0200 Subject: [PATCH] Add Lexer emoji test case --- crates/ruff_python_parser/src/lexer.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index 167250179dcec1..2f8db084978e2b 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -1716,4 +1716,22 @@ def f(arg=%timeit a = b): let source = "[1"; let _ = lex(source, Mode::Module).collect::>(); } + + /// Emoji identifiers are a non-standard python feature and are not supported by our lexer. + #[test] + fn test_emoji_identifier() { + let source = "\u{0000}"; + + let lexed: Vec<_> = lex(source, Mode::Module).collect(); + + match lexed.as_slice() { + [Err(error), Ok((Tok::Newline, _))] => { + assert_eq!( + error.error, + LexicalErrorType::UnrecognizedToken { tok: '\u{0000}' } + ) + } + result => panic!("Expected an error token followed by a newline but found {result:?}"), + } + } }