suicmez/tests/generics_comprehensive.sui

28 lines
652 B
Text
Raw Normal View History

2025-12-15 15:26:43 +05:30
# Generic struct specialization test
struct Box<T>
value: T
end
# Generic enum specialization test
enum Option<T>
Some(T),
None,
end
# Generic function specialization test
fn unwrap<T>(opt: Option<T>) -> T
match opt
Option::None() => -1,
Option::Some(v) => v,
end
# Generic struct with generic enum test
fn test_containers() -> int do
let box_int = Box { value: 42 };
let box_string = Box { value: "Fermented" };
let some_int = Option::Some(10);
let some_bool = Option::Some(true);
let unwrapped = unwrap(some_int);
let unwraped_bool = unwrap(some_bool);
box_int.value + unwrapped
end