Refactor name-analysis tests.
This commit is contained in:
parent
0c2d9f8b2f
commit
02d6a16cf8
@ -43,7 +43,11 @@ mod tests {
|
|||||||
use pest::Parser;
|
use pest::Parser;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn assert_no_diagnostics(sources: HashMap<&str, &str>, symbol_table: &mut SymbolTable) {
|
fn assert_number_of_diagnostics(
|
||||||
|
sources: HashMap<&str, &str>,
|
||||||
|
symbol_table: &mut SymbolTable,
|
||||||
|
n_diagnostics: usize,
|
||||||
|
) {
|
||||||
let mut files = SimpleFiles::new();
|
let mut files = SimpleFiles::new();
|
||||||
let mut compilation_units = vec![];
|
let mut compilation_units = vec![];
|
||||||
|
|
||||||
@ -63,6 +67,8 @@ mod tests {
|
|||||||
|
|
||||||
let diagnostics = analyze_names(&mut compilation_units, symbol_table);
|
let diagnostics = analyze_names(&mut compilation_units, symbol_table);
|
||||||
|
|
||||||
|
assert_eq!(n_diagnostics, diagnostics.len());
|
||||||
|
|
||||||
if !diagnostics.is_empty() {
|
if !diagnostics.is_empty() {
|
||||||
let writer = StandardStream::stderr(ColorChoice::Always);
|
let writer = StandardStream::stderr(ColorChoice::Always);
|
||||||
let config = term::Config::default();
|
let config = term::Config::default();
|
||||||
@ -72,7 +78,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("{}", symbol_table);
|
eprintln!("{}", symbol_table);
|
||||||
panic!("Diagnostics was not empty!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for compilation_unit in &compilation_units {
|
for compilation_unit in &compilation_units {
|
||||||
@ -80,6 +85,10 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn assert_no_diagnostics(sources: HashMap<&str, &str>, symbol_table: &mut SymbolTable) {
|
||||||
|
assert_number_of_diagnostics(sources, symbol_table, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn params_seen() {
|
fn params_seen() {
|
||||||
let sources: HashMap<&str, &str> = HashMap::from([(
|
let sources: HashMap<&str, &str> = HashMap::from([(
|
||||||
@ -130,4 +139,29 @@ mod tests {
|
|||||||
add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols.");
|
add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols.");
|
||||||
assert_no_diagnostics(sources, &mut symbol_table);
|
assert_no_diagnostics(sources, &mut symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sees_duplicate_fn() {
|
||||||
|
let sources: HashMap<&str, &str> = HashMap::from([(
|
||||||
|
"main.dm",
|
||||||
|
indoc! {"
|
||||||
|
fn main(args: Array<String>) {}
|
||||||
|
fn main(args: Array<String>) {}
|
||||||
|
"},
|
||||||
|
)]);
|
||||||
|
assert_number_of_diagnostics(sources, &mut SymbolTable::new(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn symbol_shadows_import() {
|
||||||
|
let sources: HashMap<&str, &str> = HashMap::from([(
|
||||||
|
"main.dm",
|
||||||
|
indoc! {"
|
||||||
|
platform fn println(msg: Any) -> Void;
|
||||||
|
"}
|
||||||
|
)]);
|
||||||
|
let mut symbol_table = SymbolTable::new();
|
||||||
|
add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols.");
|
||||||
|
assert_no_diagnostics(sources, &mut symbol_table);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user