-
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.
- Loading branch information
1 parent
59b978f
commit d23d4b2
Showing
1 changed file
with
19 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
|
||
use super::{Token, scanner}; | ||
use std::fs; | ||
use std::io::prelude::*; | ||
use std::fs::File; | ||
|
||
#[test] | ||
fn scan_tests(){ | ||
verify_token_count(4, "print(\"Hello World!\""); | ||
verify_token_count(17, "name = John\nage = 5\nprint(name)\nprint(age)") | ||
} | ||
fn test(){ | ||
let paths = fs::read_dir("assets").unwrap(); | ||
|
||
for path in paths { | ||
let path = path.unwrap().path(); | ||
|
||
fn verify_token_count(num: usize, src: &str){ | ||
let tokens = scanner::scan(src.to_string()); | ||
println!("Testing file: {}", path.display()); | ||
|
||
super::run(load_file(path.display().to_string())); | ||
} | ||
} | ||
|
||
assert_eq!(num, tokens.len()); | ||
fn load_file(path: String) -> String{ | ||
let mut file = File::open(&path).expect(&format!("Unable to open lua source file: {}", path)); | ||
let mut contents = String::new(); | ||
file.read_to_string(&mut contents).expect("Unable to read the file"); | ||
|
||
contents | ||
} |