use test_each_file::test_each_file; use crate::{ debug::{debug_ast, debug_token_array}, run_lexer, run_parser, }; test_each_file! { for ["kab", "out"] in "./crates/kabel/test/runtime/" => test } test_each_file! { for ["kab", "out"] in "./crates/kabel/test/lexer/" => test_lexer } test_each_file! { for ["kab", "out"] in "./crates/kabel/test/syntax/" => test_parser } fn test_lexer([program, out]: [&str; 2]) { let mut output = "".to_string(); let lexer = run_lexer(program.to_string()); for error in lexer.errors.clone() { output += &error.to_string(); output += "\n"; } if !lexer.errors.is_empty() || lexer.output.is_empty() { assert_eq!(output, out); return; } output += &debug_token_array(lexer.output.clone()); assert_eq!(output.trim(), out.trim()); } fn test_parser([program, out]: [&str; 2]) { let mut output = "".to_string(); let lexer = run_lexer(program.to_string()); for error in lexer.errors.clone() { output += &error.to_string(); output += "\n"; } if !lexer.errors.is_empty() || lexer.output.is_empty() { panic!("lexer error"); } let (ast, parser) = run_parser(program.to_string(), lexer.output); for error in parser.errors.clone() { output += &error.to_string(); output += "\n"; } if !parser.errors.is_empty() { assert_eq!(output, out); return; } output += &debug_ast(ast, 0); /*let analyzer = run_semantic_analysis(program.to_string(), ast); for error in analyzer.errors.clone() { output += &error.to_string(); output += "\n"; } assert_eq!(kabel::compile(program.to_string()), output);*/ assert_eq!(output.trim(), out.trim()); } fn test([program, out]: [&str; 2]) { assert_eq!(crate::compile(program.to_string()).trim(), out.trim()); }