resolve multiple chars in a char, tests for it

This commit is contained in:
gluax 2021-05-25 12:18:01 -04:00
parent f36d9b960f
commit 53a668ae14
3 changed files with 20 additions and 2 deletions

View File

@ -114,6 +114,10 @@ impl Token {
if unicode {
let string = input_tendril.to_string();
let unicode_number = &string[3..string.len() - 1];
let len = unicode_number.len();
if !(1..=6).contains(&len) {
return None;
}
if let Ok(hex) = u32::from_str_radix(&unicode_number, 16) {
if let Some(character) = std::char::from_u32(hex) {
@ -122,7 +126,9 @@ impl Token {
}
}
if let Some(character) = input_tendril.to_string().chars().next() {
if input_tendril.to_string().chars().count() != 1 {
return None;
} else if let Some(character) = input_tendril.to_string().chars().next() {
return Some(character);
}

View File

@ -6,3 +6,7 @@ outputs:
- " --> test:1:1\n |\n 1 | 'a\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | ''\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\x9'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | 'abcdefg'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\t\\t'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u{bbbbb}\\u{aaaa}'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '😭😂😘'\n | ^\n |\n = unexpected token: '''"

View File

@ -10,3 +10,11 @@ expectation: Fail
''
'\x9'
'abcdefg'
'\t\t'
'\u{bbbbb}\u{aaaa}'
'😭😂😘'