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()); }