Refactor type variable counter to be shared

This commit is contained in:
2026-03-31 18:06:47 +02:00
parent 7d6e040721
commit 1a4952f055
5 changed files with 82 additions and 9 deletions
+57
View File
@@ -0,0 +1,57 @@
use myc::ast::environment::Environment;
use myc::ast::types::Value;
#[test]
fn repl_preserves_variable_bindings() {
let env = Environment::new();
let r1 = env.run_script("(def x 42)");
assert!(r1.is_ok(), "def should succeed: {:?}", r1.err());
let r2 = env.run_script("(+ x 1)");
assert_eq!(r2.unwrap(), Value::Int(43));
}
#[test]
fn repl_preserves_function_bindings() {
let env = Environment::new();
let r1 = env.run_script("(def double (fn [n] (* n 2)))");
assert!(r1.is_ok(), "def fn should succeed: {:?}", r1.err());
let r2 = env.run_script("(double 21)");
assert_eq!(r2.unwrap(), Value::Int(42));
}
#[test]
fn repl_function_uses_prior_variable() {
let env = Environment::new();
env.run_script("(def x 10)").unwrap();
env.run_script("(def double (fn [n] (* n 2)))").unwrap();
let result = env.run_script("(double x)");
assert_eq!(result.unwrap(), Value::Int(20));
}
#[test]
fn repl_reassign_variable() {
let env = Environment::new();
env.run_script("(def x 1)").unwrap();
env.run_script("(assign x 99)").unwrap();
let result = env.run_script("x");
assert_eq!(result.unwrap(), Value::Int(99));
}
#[test]
fn repl_macro_from_prior_call() {
let env = Environment::new();
env.run_script("(macro unless [c body] `(if ~c ... ~body))")
.unwrap();
let result = env.run_script(r#"(unless false "yes")"#);
assert_eq!(result.unwrap(), Value::Text("yes".into()));
}