forked from SpaceManiac/SpacemanDMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helpers.rs
83 lines (69 loc) · 2.48 KB
/
test_helpers.rs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use dm::objtree::Code;
use dm::Context;
use std::borrow::Cow;
use crate::{check_var_defs, AnalyzeObjectTree};
pub const NO_ERRORS: &[(u32, u16, &str)] = &[];
pub fn parse_a_file_for_test<S: Into<Cow<'static, str>>>(buffer: S) -> Context {
let context = Context::default();
let pp = dm::preprocessor::Preprocessor::from_buffer(&context, "unit_tests.rs".into(), buffer);
let indents = dm::indents::IndentProcessor::new(&context, pp);
let mut parser = dm::parser::Parser::new(&context, indents);
parser.enable_procs();
let tree = parser.parse_object_tree();
check_var_defs(&tree, &context);
let mut analyzer = AnalyzeObjectTree::new(&context, &tree);
tree.root().recurse(&mut |ty| {
for proc in ty.iter_self_procs() {
if let Code::Present(ref code) = proc.get().code {
analyzer.gather_settings(proc, code);
}
}
});
tree.root().recurse(&mut |ty| {
for proc in ty.iter_self_procs() {
match proc.get().code {
Code::Present(ref code) => {
analyzer.check_proc(proc, code);
}
Code::Invalid(_) => {}
Code::Builtin => {}
Code::Disabled => {
panic!("proc parsing was enabled, but also disabled. this is a bug")
}
}
}
});
analyzer.check_proc_call_tree();
tree.root().recurse(&mut |ty| {
for proc in ty.iter_self_procs() {
analyzer.check_kwargs(proc);
}
});
analyzer.finish_check_kwargs();
context
}
pub fn check_errors_match<S: Into<Cow<'static, str>>>(buffer: S, errorlist: &[(u32, u16, &str)]) {
let context = parse_a_file_for_test(buffer);
let errors = context.errors();
let mut iter = errors.iter();
for (line, column, desc) in errorlist {
let nexterror = iter.next().unwrap();
if nexterror.location().line != *line
|| nexterror.location().column != *column
|| nexterror.description() != *desc
{
panic!(format!(
"possible feature regression in dreamchecker, expected {}:{}:{}, found {}:{}:{}",
*line,
*column,
*desc,
nexterror.location().line,
nexterror.location().column,
nexterror.description()
));
}
}
if iter.next().is_some() {
panic!("found more errors than was expected");
}
}