|
1 | 1 | // cspell: words aname groupsocket typesocket groupsocket |
2 | 2 |
|
3 | 3 | mod common; |
4 | | -use common::{identifiers::*, CDDLTestParser, Rule}; |
5 | | -use pest::Parser; |
| 4 | +use common::{identifiers::*, Rule}; |
6 | 5 |
|
7 | | -#[test] |
8 | 6 | /// Check if the name components pass properly. |
9 | | -fn check_name_characters() { |
10 | | - for x in ('\u{0}'..='\u{ff}').map(char::from) { |
11 | | - let test = format!("{x}"); |
12 | | - let parse_start = CDDLTestParser::parse(Rule::NAME_START, &test); |
13 | | - let parse_end = CDDLTestParser::parse(Rule::NAME_END, &test); |
| 7 | +#[test] |
| 8 | +fn check_name_start_characters() { |
| 9 | + let passes = ('\u{0}'..='\u{ff}') |
| 10 | + .filter(|x| x.is_ascii_alphabetic() || matches!(x, '@' | '_' | '$')) |
| 11 | + .map(String::from) |
| 12 | + .collect::<Vec<_>>(); |
| 13 | + let fails = ('\u{0}'..='\u{ff}') |
| 14 | + .filter(|x| !x.is_ascii_alphabetic() && !matches!(x, '@' | '_' | '$')) |
| 15 | + .map(String::from) |
| 16 | + .collect::<Vec<_>>(); |
14 | 17 |
|
15 | | - if x.is_ascii_alphabetic() || matches!(x, '@' | '_' | '$') { |
16 | | - assert!(parse_start.is_ok()); |
17 | | - assert!(parse_end.is_ok()); |
18 | | - } else if x.is_ascii_digit() { |
19 | | - assert!(parse_start.is_err()); |
20 | | - assert!(parse_end.is_ok()); |
21 | | - } else { |
22 | | - assert!(parse_start.is_err()); |
23 | | - assert!(parse_end.is_err()); |
24 | | - } |
25 | | - } |
| 18 | + common::check_tests_rule(Rule::NAME_START, &passes, &fails); |
26 | 19 | } |
27 | 20 |
|
| 21 | +/// Check if the name components pass properly. |
28 | 22 | #[test] |
| 23 | +fn check_name_end_characters() { |
| 24 | + let passes = ('\u{0}'..='\u{ff}') |
| 25 | + .filter(|x| x.is_ascii_alphabetic() || x.is_ascii_digit() || matches!(x, '@' | '_' | '$')) |
| 26 | + .map(String::from) |
| 27 | + .collect::<Vec<_>>(); |
| 28 | + let fails = ('\u{0}'..='\u{ff}') |
| 29 | + .filter(|x| { |
| 30 | + !x.is_ascii_alphabetic() && !x.is_ascii_digit() && !matches!(x, '@' | '_' | '$') |
| 31 | + }) |
| 32 | + .map(String::from) |
| 33 | + .collect::<Vec<_>>(); |
| 34 | + |
| 35 | + common::check_tests_rule(Rule::NAME_END, &passes, &fails); |
| 36 | +} |
| 37 | + |
29 | 38 | /// Test if the `id` rule passes properly. |
| 39 | +#[test] |
30 | 40 | fn check_id() { |
31 | 41 | common::check_tests_rule(Rule::id_TEST, ID_PASSES, ID_FAILS); |
32 | 42 | } |
0 commit comments