Skip to content

Commit 8e18b4a

Browse files
committed
cleanup tests/identifiers.rs
1 parent a61eb7e commit 8e18b4a

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed
Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
// cspell: words aname groupsocket typesocket groupsocket
22

33
mod common;
4-
use common::{identifiers::*, CDDLTestParser, Rule};
5-
use pest::Parser;
4+
use common::{identifiers::*, Rule};
65

7-
#[test]
86
/// 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<_>>();
1417

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);
2619
}
2720

21+
/// Check if the name components pass properly.
2822
#[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+
2938
/// Test if the `id` rule passes properly.
39+
#[test]
3040
fn check_id() {
3141
common::check_tests_rule(Rule::id_TEST, ID_PASSES, ID_FAILS);
3242
}

0 commit comments

Comments
 (0)