Added more tests

This commit is contained in:
2026-07-04 21:55:29 +02:00
parent a1fd169568
commit f30613f094
10 changed files with 367 additions and 0 deletions
+13
View File
@@ -22,8 +22,21 @@ pub void test_allow_attribute()
assert_eq!(x, 42);
}
#[allow(dead_code)]
pub struct Tagged
{
i32 id;
}
pub void test_attribute_with_args()
{
Tagged t = Tagged { id: 1 };
assert_eq!(t.id, 1);
}
pub void run_tests()
{
test_derive_attribute();
test_allow_attribute();
test_attribute_with_args();
}
+63
View File
@@ -59,10 +59,73 @@ pub class Dog : Mammal
}
}
pub class Counter
{
pub i32 count;
constructor()
{
self.count = 42;
}
i32 get_count(&self)
{
self.count
}
pub i32 static_fn()
{
99
}
}
pub void test_class_no_inheritance()
{
Counter c = Counter::new();
assert_eq!(c.get_count(), 42);
}
pub class WithDefault
{
pub String name = "default".to_string();
pub i32 value = 42;
constructor()
{
}
pub String get_name(&self)
{
self.name.clone()
}
}
pub void test_class_field_default()
{
WithDefault w = WithDefault::new();
assert_eq!(w.get_name(), "default");
assert_eq!(w.value, 42);
}
pub class EmptyClass
{
constructor()
{
}
}
pub void test_class_empty()
{
EmptyClass e = EmptyClass::new();
}
pub void run_tests()
{
let dawg = Dog::new();
dawg.args_test(10, "hello");
dawg.test_speak();
assert_eq!(format!("{dawg}"), "🐾 Rex");
test_class_no_inheritance();
test_class_field_default();
test_class_empty();
}
+30
View File
@@ -90,10 +90,40 @@ pub void test_enum_eq()
}
}
enum Option<T>
{
None;
Some(T);
}
pub void test_generic_enum()
{
Option<i32> x = Option::Some(42);
match x {
Option::Some(v) => {
assert_eq!(v, 42);
}
_ => {
assert_eq!(0, 1);
}
}
Option<bool> y = Option::None;
match y {
Option::None => {
assert_eq!(1, 1);
}
_ => {
assert_eq!(0, 1);
}
}
}
pub void run_tests()
{
test_enum_named();
test_enum_tuple();
test_enum_struct();
test_enum_eq();
test_generic_enum();
}
+12
View File
@@ -69,6 +69,17 @@ pub void test_recursive_fn()
assert_eq!(factorial(5), 120);
}
T identity<T>(T x)
{
x
}
pub void test_fn_generic()
{
assert_eq!(identity(42), 42);
assert_eq!(identity("hello"), "hello");
}
pub void run_tests()
{
test_basic_function();
@@ -79,4 +90,5 @@ pub void run_tests()
test_method_call();
test_nested_fn_calls();
test_recursive_fn();
test_fn_generic();
}
+20
View File
@@ -72,9 +72,29 @@ pub void test_multiple_impls()
assert_eq!(c.y, 6);
}
struct Wrapper<T>
{
T value;
}
impl<T: Copy> Wrapper<T>
{
pub T get(&self)
{
self.value
}
}
pub void test_impl_generic()
{
Wrapper<i32> w = Wrapper { value: 42 };
assert_eq!(w.get(), 42);
}
pub void run_tests()
{
test_inherent_impl();
test_trait_impl_block();
test_multiple_impls();
test_impl_generic();
}
+45
View File
@@ -59,10 +59,55 @@ pub void test_struct_nested()
assert_eq!(l.end.y, 10);
}
struct Empty {}
pub void test_empty_struct()
{
let e = Empty {};
}
struct Pair<T>
{
T first;
T second;
}
pub void test_generic_struct()
{
Pair<i32> p = Pair<i32> { first: 1, second: 2 };
assert_eq!(p.first, 1);
assert_eq!(p.second, 2);
}
pub void test_struct_partial_destructure()
{
let p = Point {
x: 10,
y: 20,
};
let Point {x, ..} = p;
assert_eq!(x, 10);
}
pub void test_struct_destructure_rename()
{
let p = Point {
x: 5,
y: 15,
};
let Point {x: a, y: b} = p;
assert_eq!(a, 5);
assert_eq!(b, 15);
}
pub void run_tests()
{
test_struct_create_access();
test_struct_mut_field();
test_struct_destructure();
test_struct_nested();
test_empty_struct();
test_generic_struct();
test_struct_partial_destructure();
test_struct_destructure_rename();
}