-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add information about documentplacement in tokens
- Loading branch information
1 parent
7e6e004
commit 4d7fc86
Showing
22 changed files
with
1,007 additions
and
475 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::{fs, path::PathBuf, sync::Once}; | ||
|
||
use interpreter::parser::{ParsedProgram, Parser}; | ||
use tracing_subscriber::FmtSubscriber; | ||
|
||
static TRACING: Once = Once::new(); | ||
pub fn setup_logger() { | ||
let subscriber = FmtSubscriber::builder() | ||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | ||
.finish(); | ||
|
||
TRACING.call_once(|| { | ||
tracing::subscriber::set_global_default(subscriber) | ||
.expect("setting default subscriber failed"); | ||
}) | ||
} | ||
|
||
#[test] | ||
fn test_error_message() { | ||
setup_logger(); | ||
|
||
let mut test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
test_file_path.push("tests/test_error.las"); | ||
let file_name = test_file_path.to_str().unwrap(); | ||
|
||
let file_content = fs::read_to_string(file_name).expect("Should be able to read string"); | ||
|
||
let mut parser = Parser::new(&file_content); | ||
let program = parser.parse_program(); | ||
|
||
let first_expected_parse_error = "Error on line 2: expected binding to let statement\n"; | ||
let second_expected_parse_error = "Error on line 4: expected identifier in let statement\n"; | ||
match program { | ||
ParsedProgram::InvalidProgram(parse_errors) => { | ||
if parse_errors.len() != 2 { | ||
for ele in parse_errors { | ||
println!("{ele}"); | ||
} | ||
panic!("Expected 2 parse errors, but got the above ones instaed"); | ||
} | ||
|
||
assert_eq!( | ||
first_expected_parse_error, | ||
parse_errors.first().unwrap().to_string() | ||
); | ||
assert_eq!( | ||
second_expected_parse_error, | ||
parse_errors.get(1).unwrap().to_string() | ||
); | ||
} | ||
_ => panic!("Should return error"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let foo: "bar" | ||
let bar: | ||
let hehe: "test" | ||
let : "test" | ||
let ok: "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.