Test for modules in symbol table

This commit is contained in:
greg 2019-10-24 03:02:52 -07:00
parent c96644ddce
commit 4a1987b5a2

View File

@ -14,10 +14,10 @@ fn add_symbols_from_source(src: &str) -> (SymbolTable, Result<(), String>) {
} }
macro_rules! values_in_table { macro_rules! values_in_table {
($source:literal, $single_value:expr) => { ($source:expr, $single_value:expr) => {
values_in_table!($source | $single_value); values_in_table!($source => $single_value);
}; };
($source:literal | $( $value:expr ),* ) => { ($source:expr => $( $value:expr ),* ) => {
{ {
let (symbol_table, _) = add_symbols_from_source($source); let (symbol_table, _) = add_symbols_from_source($source);
$( $(
@ -33,7 +33,7 @@ macro_rules! values_in_table {
#[test] #[test]
fn basic_symbol_table() { fn basic_symbol_table() {
values_in_table! { "let a = 10; fn b() { 20 }", &fqsn!("b"; tr) }; values_in_table! { "let a = 10; fn b() { 20 }", &fqsn!("b"; tr) };
values_in_table! { "type Option<T> = Some(T) | None" | values_in_table! { "type Option<T> = Some(T) | None" =>
&fqsn!("Option"; tr), &fqsn!("Option"; tr),
&fqsn!("Option"; ty, "Some"; tr), &fqsn!("Option"; ty, "Some"; tr),
&fqsn!("Option"; ty, "None"; tr) }; &fqsn!("Option"; ty, "None"; tr) };
@ -155,6 +155,22 @@ inner_func(x)
assert!(output.unwrap_err().contains("Duplicate")) assert!(output.unwrap_err().contains("Duplicate"))
} }
#[test]
fn modules() {
let source = r#"
module stuff {
fn item() {
}
}
fn item()
"#;
values_in_table! { source =>
&fqsn!("item"; tr),
&fqsn!("stuff"; tr, "item"; tr)
};
}
#[test] #[test]
fn duplicate_modules() { fn duplicate_modules() {
let source = r#" let source = r#"