Add chrono dependency and example files
This commit introduces the `chrono` dependency to the project, enabling the use of time-related functionalities. Additionally, it adds several example files (`closure.myc`, `fib.myc`, `hof.myc`) to showcase the language's features like closures, recursion, and higher-order functions. The `Cargo.lock` and `Cargo.toml` files have been updated to reflect the new dependency. The `integration_test.rs` file now includes a test to run all `.myc` files found in the `examples` directory, ensuring their correctness. The `main.rs` file has also been updated to load and display these examples in the UI.
This commit is contained in:
+37
-1
@@ -6,8 +6,9 @@ mod tests {
|
||||
use crate::ast::compiler::binder::Binder;
|
||||
use crate::ast::vm::VM;
|
||||
use crate::ast::types::Value;
|
||||
|
||||
use crate::ast::nodes::UntypedKind;
|
||||
use crate::ast::environment::Environment;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn test_parse_integer_constant() {
|
||||
@@ -89,4 +90,39 @@ mod tests {
|
||||
Err(e) => panic!("VM Error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
let entries = fs::read_dir("examples").expect("Could not read examples directory");
|
||||
for entry in entries {
|
||||
let entry = entry.expect("Invalid entry");
|
||||
let path = entry.path();
|
||||
if path.extension().map_or(false, |ext| ext == "myc") {
|
||||
let content = fs::read_to_string(&path).expect("Could not read file");
|
||||
|
||||
// Skip benchmarks during normal functional tests
|
||||
if content.contains(";; Benchmark") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find expected output tag: ;; Output: <value>
|
||||
let expected_output = content.lines()
|
||||
.find(|line| line.starts_with(";; Output:"))
|
||||
.map(|line| line.replace(";; Output:", "").trim().to_string());
|
||||
|
||||
if let Some(expected) = expected_output {
|
||||
let env = Environment::new();
|
||||
let result = env.run_script(&content);
|
||||
|
||||
match result {
|
||||
Ok(val) => {
|
||||
let val_str = format!("{}", val);
|
||||
assert_eq!(val_str, expected, "Example {:?} failed: expected {}, got {}", path, expected, val_str);
|
||||
}
|
||||
Err(e) => panic!("Example {:?} failed with error: {}", path, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user