use crate::test_utils::eval;
#[test]
fn test_typed_struct_field_access_number() {
let v = eval(r#"
type Point { x: number, y: number }
let p = Point { x: 3.5, y: 4.5 }
p.x
"#);
assert_eq!(v.as_f64(), Some(3.5));
}
#[test]
fn test_typed_struct_field_access_single() {
let v = eval(r#"
type Single { v: number }
let s = Single { v: 42.0 }
s.v
"#);
assert_eq!(v.as_f64(), Some(42.0));
}
#[test]
fn test_typed_struct_with_int_fields() {
let v = eval(r#"
type Counter { count: int }
let c = Counter { count: 100 }
c.count
"#);
assert_eq!(v.as_i64(), Some(100));
}
#[test]
fn test_typed_struct_mutation() {
let v = eval(r#"
type Counter { count: int }
let mut c = Counter { count: 1 }
c.count = 99
c.count
"#);
assert_eq!(v.as_i64(), Some(99));
}
#[test]
fn test_multiple_struct_types() {
let v = eval(r#"
type A { v: int }
type B { v: int }
let a = A { v: 10 }
let b = B { v: 20 }
a.v + b.v
"#);
assert_eq!(v.as_i64(), Some(30));
}
#[test]
fn test_typed_struct_in_function() {
let v = eval(r#"
type Pair { first: int, second: int }
fn make() -> Pair {
Pair { first: 7, second: 13 }
}
let p = make()
p.first + p.second
"#);
assert_eq!(v.as_i64(), Some(20));
}
#[test]
fn test_typed_struct_mixed_fields() {
let v = eval(r#"
type Record { id: int, score: number, active: bool }
let r = Record { id: 7, score: 99.5, active: true }
r.id
"#);
assert_eq!(v.as_i64(), Some(7));
}
#[test]
fn test_typed_struct_mixed_fields_number() {
let v = eval(r#"
type Record { id: int, score: number, active: bool }
let r = Record { id: 7, score: 99.5, active: true }
r.score
"#);
assert_eq!(v.as_f64(), Some(99.5));
}
#[test]
fn test_typed_struct_distance_calc() {
let v = eval(r#"
type Vec2 { x: number, y: number }
let a = Vec2 { x: 3.0, y: 4.0 }
a.x * a.x + a.y * a.y
"#);
assert_eq!(v.as_f64(), Some(25.0));
}
#[test]
fn test_anonymous_object_still_works() {
let v = eval(r#"
let obj = { x: 10, y: 20 }
obj.x + obj.y
"#);
assert_eq!(v.as_i64(), Some(30));
}