1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
use typstc::syntax::*;
use Token::{
Space as S, Newline as N, LeftBracket as LB,
RightBracket as RB, Text as T, *
};
/// Parses the test syntax.
macro_rules! tokens {
($($src:expr =>($line:expr)=> $tokens:expr)*) => ({
#[allow(unused_mut)]
let mut cases = Vec::new();
$(cases.push(($line, $src, $tokens.to_vec()));)*
cases
});
}
fn main() {
let tests = include!("cache/parse");
let mut errors = false;
let len = tests.len();
println!();
println!("Running {} test{}", len, if len > 1 { "s" } else { "" });
// Go through all test files.
for (file, cases) in tests.into_iter() {
print!("Testing: {}. ", file);
let mut okay = 0;
let mut failed = 0;
// Go through all tests in a test file.
for (line, src, expected) in cases.into_iter() {
let found: Vec<_> = tokenize(src).map(Spanned::value).collect();
// Check whether the tokenization works correctly.
if found == expected {
okay += 1;
} else {
if failed == 0 {
println!();
}
println!(" - Case failed in file {}.rs in line {}.", file, line);
println!(" - Source: {:?}", src);
println!(" - Expected: {:?}", expected);
println!(" - Found: {:?}", found);
failed += 1;
errors = true;
}
}
// Print a small summary.
print!("{} okay, {} failed.", okay, failed);
if failed == 0 {
print!(" ✔")
}
println!();
}
println!();
if errors {
std::process::exit(-1);
}
}
|