Fix type-of and comparison for new Value variants
This commit is contained in:
@@ -138,6 +138,103 @@ fn test_environments_from_shared_rtl_are_independent() {
|
||||
assert_eq!(format!("{}", env2.run_script("(+ 1 2)").unwrap()), "3");
|
||||
}
|
||||
|
||||
// --- Bug fixes for wildcard matches ---
|
||||
|
||||
/// `type-of` must return :function for native functions (e.g. `print`).
|
||||
/// Previously returned :unknown because Value::Function.static_type() yields Any,
|
||||
/// and the type-of match did not handle Any.
|
||||
#[test]
|
||||
fn test_type_of_native_function() {
|
||||
let env = Environment::new();
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(type-of print)").unwrap()),
|
||||
":function",
|
||||
);
|
||||
}
|
||||
|
||||
/// `type-of` must return :function for closures, not :closure.
|
||||
/// Closures are functions from the user's perspective.
|
||||
#[test]
|
||||
fn test_type_of_closure() {
|
||||
let env = Environment::new();
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(type-of (fn [x] x))").unwrap()),
|
||||
":function",
|
||||
);
|
||||
}
|
||||
|
||||
/// `type-of` must return :field-accessor for field accessors.
|
||||
#[test]
|
||||
fn test_type_of_field_accessor() {
|
||||
let env = Environment::new();
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(type-of .name)").unwrap()),
|
||||
":field-accessor",
|
||||
);
|
||||
}
|
||||
|
||||
/// The `=` operator must compare tuples structurally, not return false.
|
||||
#[test]
|
||||
fn test_equality_tuples() {
|
||||
let env = Environment::new();
|
||||
// Use def bindings because vector literals in call position get flattened.
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a [1 2 3]) (def b [1 2 3]) (= a b))").unwrap()),
|
||||
"true",
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a [1 2 3]) (def b [1 2 4]) (= a b))").unwrap()),
|
||||
"false",
|
||||
);
|
||||
// Nested tuples
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a [[1 2] [3 4]]) (def b [[1 2] [3 4]]) (= a b))").unwrap()),
|
||||
"true",
|
||||
);
|
||||
}
|
||||
|
||||
/// The `<>` operator must compare tuples structurally.
|
||||
#[test]
|
||||
fn test_inequality_tuples() {
|
||||
let env = Environment::new();
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a [1 2 3]) (def b [1 2 3]) (<> a b))").unwrap()),
|
||||
"false",
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a [1 2 3]) (def b [1 2 4]) (<> a b))").unwrap()),
|
||||
"true",
|
||||
);
|
||||
}
|
||||
|
||||
/// The `=` operator must compare field accessors by identity.
|
||||
#[test]
|
||||
fn test_equality_field_accessors() {
|
||||
let env = Environment::new();
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a .name) (def b .name) (= a b))").unwrap()),
|
||||
"true",
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a .name) (def b .age) (= a b))").unwrap()),
|
||||
"false",
|
||||
);
|
||||
}
|
||||
|
||||
/// The `<>` operator must compare field accessors by identity.
|
||||
#[test]
|
||||
fn test_inequality_field_accessors() {
|
||||
let env = Environment::new();
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a .name) (def b .age) (<> a b))").unwrap()),
|
||||
"true",
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", env.run_script("(do (def a .name) (def b .name) (<> a b))").unwrap()),
|
||||
"false",
|
||||
);
|
||||
}
|
||||
|
||||
/// Arithmetic operators with incompatible types (e.g. Float - Record)
|
||||
/// must be caught at compile time, not silently return Void at runtime.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user