49ad76e7c3
This commit refactors the test suite by removing the monolithic `integration_test.rs` file. The tests have been categorized and moved into dedicated modules within the `tests/` directory: - `tests/parser.rs`: Contains tests for parsing various literal values. - `tests/destructuring.rs`: Houses tests related to destructuring syntax. - `tests/closures.rs`: Includes tests for closure behavior and related optimizations. - `tests/optimizer.rs`: Contains tests specifically targeting optimizer logic and regressions. - `tests/records.rs`: Holds tests for record syntax and associated optimizations. - `tests/rtl.rs`: Contains tests for runtime library operators and functions. - `tests/pipeline.rs`: Tests for pipeline functionality. - `tests/macros.rs`: Tests for macro expansion and related issues. - `tests/error_recovery.rs`: Includes tests for compiler error handling and recovery mechanisms. - `tests/examples.rs`: Verifies the execution of example scripts. This reorganization improves test discoverability and maintainability. The `lib.rs` file has also been updated to reflect these changes by removing the reference to the old `integration_test` module. The `type_checker.rs` file has had some tests removed, as they are now covered by the more specific tests in `tests/error_recovery.rs`.
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use myc::ast::environment::Environment;
|
|
|
|
#[test]
|
|
fn test_macro_inlining_identity_collision() {
|
|
let source = r#"
|
|
(do
|
|
(macro wrap [f] `(fn [x] (~f x)))
|
|
|
|
(def add1 (fn [x] (+ x 1)))
|
|
(def add2 (fn [x] (+ x 2)))
|
|
|
|
(def w1 (wrap add1))
|
|
(def w2 (wrap add2))
|
|
|
|
(w1 (w2 10)))
|
|
"#;
|
|
|
|
// 1. Verify the result is correct
|
|
let env_run = Environment::new();
|
|
let res = env_run.run_script(source).expect("Failed to run script");
|
|
assert_eq!(format!("{}", res), "13");
|
|
|
|
// 2. Verify that it was actually folded into a constant by the optimizer
|
|
let env_dump = Environment::new();
|
|
let dump = env_dump.dump_ast(source).expect("Failed to dump AST");
|
|
assert!(
|
|
dump.contains("Constant: 13") || dump.contains("Call"),
|
|
"Macro-wrapped calls should be properly handled. Dump:\n{}",
|
|
dump
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_repro_placeholder_in_template_failure() {
|
|
let env = Environment::new();
|
|
let source = r#"
|
|
(do
|
|
(macro repeat [var limit body]
|
|
`((fn [~var __limit]
|
|
(if (< ~var __limit)
|
|
(do ~body (again (+ ~var 1) __limit))))
|
|
0 ~limit))
|
|
(repeat n 10 42))
|
|
"#;
|
|
let res = env.run_script(source);
|
|
assert!(res.is_ok(), "Expansion failed to strip placeholders: {:?}", res.err());
|
|
}
|