SymbolTable passing, fix test for duplicate line
This commit is contained in:
parent
a2f30b6136
commit
b38c4b3298
@ -22,7 +22,7 @@ impl ASTVisitor for Tester {
|
||||
#[test]
|
||||
fn foo() {
|
||||
let mut tester = Tester { count: 0, float_count: 0 };
|
||||
let ast = quick_ast(r#"
|
||||
let (ast, _) = quick_ast(r#"
|
||||
import gragh
|
||||
|
||||
let a = 20 + 84
|
||||
|
@ -10,10 +10,10 @@ use crate::reduced_ast::reduce;
|
||||
use crate::eval::State;
|
||||
|
||||
fn evaluate_all_outputs(input: &str) -> Vec<Result<String, String>> {
|
||||
let source_map = Rc::new(RefCell::new(SourceMap::new()));
|
||||
let (mut ast, source_map) = crate::util::quick_ast(input);
|
||||
let source_map = Rc::new(RefCell::new(source_map));
|
||||
let symbol_table = Rc::new(RefCell::new(SymbolTable::new(source_map)));
|
||||
let mut state = State::new(symbol_table);
|
||||
let mut ast = crate::util::quick_ast(input);
|
||||
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap();
|
||||
{
|
||||
let mut scope_resolver = ScopeResolver::new(state.symbol_table_handle.clone());
|
||||
|
@ -7,9 +7,9 @@ use crate::util::quick_ast;
|
||||
use crate::source_map;
|
||||
|
||||
fn add_symbols_from_source(src: &str) -> (SymbolTable, Result<(), String>) {
|
||||
let source_map = Rc::new(RefCell::new(source_map::SourceMap::new()));
|
||||
let (ast, source_map) = quick_ast(src);
|
||||
let source_map = Rc::new(RefCell::new(source_map));
|
||||
let mut symbol_table = SymbolTable::new(source_map);
|
||||
let ast = quick_ast(src);
|
||||
let result = symbol_table.add_top_level_symbols(&ast);
|
||||
(symbol_table, result)
|
||||
}
|
||||
@ -54,15 +54,15 @@ fn no_duplicates() {
|
||||
#[test]
|
||||
fn no_duplicates_2() {
|
||||
let source = r#"
|
||||
let a = 20;
|
||||
let q = 39;
|
||||
let a = 30;
|
||||
let x = 9
|
||||
let a = 20
|
||||
let q = 39
|
||||
let a = 30
|
||||
"#;
|
||||
let (_, output) = add_symbols_from_source(source);
|
||||
let output = output.unwrap_err();
|
||||
println!("OUTPUT: {:?}", output);
|
||||
assert!(output.contains("Duplicate"));
|
||||
assert!(output.contains("Line 3"));
|
||||
assert!(output.contains("Duplicate definition: a"));
|
||||
assert!(output.contains("already defined at 2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -461,7 +461,7 @@ mod typechecking_tests {
|
||||
macro_rules! assert_type_in_fresh_context {
|
||||
($string:expr, $type:expr) => {
|
||||
let mut tc = TypeContext::new();
|
||||
let ref ast = crate::util::quick_ast($string);
|
||||
let (ref ast, _) = crate::util::quick_ast($string);
|
||||
let ty = tc.typecheck(ast).unwrap();
|
||||
assert_eq!(ty, $type)
|
||||
}
|
||||
|
@ -48,11 +48,11 @@ impl<'a, T, V> ScopeStack<'a, T, V> where T: Hash + Eq {
|
||||
|
||||
/// this is intended for use in tests, and does no error-handling whatsoever
|
||||
#[allow(dead_code)]
|
||||
pub fn quick_ast(input: &str) -> crate::ast::AST {
|
||||
pub fn quick_ast(input: &str) -> (crate::ast::AST, crate::source_map::SourceMap) {
|
||||
let mut source_map = crate::source_map::SourceMap::new();
|
||||
let tokens = crate::tokenizing::tokenize(input);
|
||||
let mut parser = crate::parsing::Parser::new(tokens, &mut source_map);
|
||||
parser.parse().unwrap()
|
||||
(parser.parse().unwrap(), source_map)
|
||||
}
|
||||
|
||||
#[allow(unused_macros)]
|
||||
|
Loading…
Reference in New Issue
Block a user