Fixed test

This commit is contained in:
2026-06-05 12:56:14 +02:00
parent 595ddc789d
commit b311dbd16c
12 changed files with 72 additions and 77 deletions
+1
View File
@@ -590,6 +590,7 @@ prefix = {
bin_op = { bin_op = {
"+=" "+="
| "-=" | "-="
| "*="
| "/=" | "/="
| "%=" | "%="
| "&=" | "&="
+6 -6
View File
@@ -4,16 +4,16 @@ pub void test_let_basic() {
} }
pub void test_let_typed() { pub void test_let_typed() {
Int x = 42; i32 x = 42;
assert_eq!(x, 42); assert_eq!(x, 42);
String s = "hello"; str* s = "hello";
assert_eq!(s, "hello"); assert_eq!(s, "hello");
Bool b = true; bool b = true;
assert_eq!(b, true); assert_eq!(b, true);
Float f = 3.14; f64 f = 3.14;
assert_eq!(f, 3.14); assert_eq!(f, 3.14);
} }
@@ -52,8 +52,8 @@ pub void test_multiple_decls() {
} }
pub void test_let_with_type_and_init() { pub void test_let_with_type_and_init() {
Int x = 10; f64 x = 10.0;
assert_eq!(x, 10); assert_eq!(x, 10.0);
} }
pub void test_string_literal() { pub void test_string_literal() {
+1 -1
View File
@@ -88,7 +88,7 @@ pub void test_as_cast() {
} }
pub void test_closure() { pub void test_closure() {
let add = fn(a, b) a + b; let add = fn(let a, let b) a + b;
assert_eq!(add(2, 3), 5); assert_eq!(add(2, 3), 5);
} }
+4 -2
View File
@@ -2,10 +2,10 @@ pub void test_var_decl() {
let x = 42; let x = 42;
assert_eq!(x, 42); assert_eq!(x, 42);
Int y = 10; i32 y = 10;
assert_eq!(y, 10); assert_eq!(y, 10);
String name = "mist"; str* name = "mist";
assert_eq!(name, "mist"); assert_eq!(name, "mist");
} }
@@ -109,6 +109,7 @@ pub void test_match_literal() {
1 => { result = 10; } 1 => { result = 10; }
2 => { result = 20; } 2 => { result = 20; }
3 => { result = 30; } 3 => { result = 30; }
_ => panic!();
} }
assert_eq!(result, 20); assert_eq!(result, 20);
} }
@@ -120,6 +121,7 @@ pub void test_match_or_pattern() {
match (x) { match (x) {
1 | 2 => { result = 100; } 1 | 2 => { result = 100; }
3 => { result = 200; } 3 => { result = 200; }
_ => panic!();
} }
assert_eq!(result, 100); assert_eq!(result, 100);
} }
+13 -23
View File
@@ -1,64 +1,55 @@
pub void test_integer_type() { pub void test_integer_type() {
Int x = 42; i32 x = 42;
assert_eq!(x, 42); assert_eq!(x, 42);
} }
pub void test_float_type() { pub void test_float_type() {
Float x = 3.14; f64 x = 3.14;
assert_eq!(x, 3.14); assert_eq!(x, 3.14);
} }
pub void test_bool_type() { pub void test_bool_type() {
Bool x = true; bool x = true;
assert_eq!(x, true); assert_eq!(x, true);
Bool y = false; bool y = false;
assert_eq!(y, false); assert_eq!(y, false);
} }
pub void test_string_type() { pub void test_string_type() {
String s = "hello"; str* s = "hello";
assert_eq!(s, "hello"); assert_eq!(s, "hello");
} }
pub void test_tuple_type() { pub void test_tuple_type() {
[Int, String] t = (42, "answer"); [i32, str*] t = (42, "answer");
assert_eq!(t.0, 42); assert_eq!(t.0, 42);
assert_eq!(t.1, "answer"); assert_eq!(t.1, "answer");
} }
pub void test_ref_type() { pub void test_ref_type() {
Int x = 42; i32 x = 42;
Int* r = &x; i32* r = &x;
assert_eq!(*r, 42); assert_eq!(*r, 42);
} }
pub void test_mut_ref_type() { pub void test_mut_ref_type() {
let mut x = 42; let mut x = 42;
Int mut* r = &mut x; i32 mut* r = &mut x;
*r = 100; *r = 100;
assert_eq!(x, 100); assert_eq!(x, 100);
} }
pub void test_void_type() { pub void test_void_type() {}
void nothing() {
} i32 add(i32 a, i32 b) {
nothing(); a + b
} }
pub void test_fn_return_type() { pub void test_fn_return_type() {
Int add(Int a, Int b) {
a + b
}
assert_eq!(add(3, 4), 7); assert_eq!(add(3, 4), 7);
} }
pub void test_fn_return_void() {
void do_nothing() {
}
do_nothing();
}
pub void run_tests() { pub void run_tests() {
test_integer_type(); test_integer_type();
test_float_type(); test_float_type();
@@ -69,5 +60,4 @@ pub void run_tests() {
test_mut_ref_type(); test_mut_ref_type();
test_void_type(); test_void_type();
test_fn_return_type(); test_fn_return_type();
test_fn_return_void();
} }
+1 -1
View File
@@ -1,6 +1,6 @@
#[derive(Debug)] #[derive(Debug)]
pub struct Debuggable { pub struct Debuggable {
Int value, i32 value,
} }
pub void test_derive_attribute() { pub void test_derive_attribute() {
+7 -7
View File
@@ -1,7 +1,7 @@
pub class Counter { pub class Counter {
pub Int count; pub i32 count;
pub constructor(Int start) { pub constructor(i32 start) {
self.count = start; self.count = start;
} }
@@ -9,7 +9,7 @@ pub class Counter {
self.count++; self.count++;
} }
pub Int get(self*) -> Int { pub i32 get(self*) {
self.count self.count
} }
} }
@@ -33,17 +33,17 @@ pub void test_class_field_access() {
class NamedCounter : Counter { class NamedCounter : Counter {
pub String name; pub String name;
pub constructor(Int start, String name) { pub constructor(i32 start, String name) {
self.name = name; self.name = name;
} }
pub String get_name(self*) -> String { pub String get_name(self*) {
self.name self.name.clone()
} }
} }
pub void test_class_inherit() { pub void test_class_inherit() {
let nc = NamedCounter::new(10, "test"); let nc = NamedCounter::new(10, "test".to_string());
assert_eq!(nc.get_name(), "test"); assert_eq!(nc.get_name(), "test");
assert_eq!(nc.count, 10); assert_eq!(nc.count, 10);
} }
+3 -3
View File
@@ -1,6 +1,6 @@
enum OptionInt { enum OptionInt {
None, None,
Some(Int), Some[i32],
} }
pub void test_enum_named() { pub void test_enum_named() {
@@ -20,8 +20,8 @@ pub void test_enum_tuple() {
} }
enum Shape { enum Shape {
Circle { Int radius }, Circle { i32 radius },
Rect { Int w, Int h }, Rect { i32 w, i32 h },
} }
pub void test_enum_struct() { pub void test_enum_struct() {
+22 -20
View File
@@ -1,52 +1,54 @@
pub void test_basic_function() { void greet() {
void greet() { let mut x = 1;
let x = 1;
x++; x++;
} }
pub void test_basic_function() {
greet(); greet();
} }
pub void test_fn_params() { i32 add(i32 a, i32 b) {
Int add(Int a, Int b) {
a + b a + b
} }
pub void test_fn_params() {
assert_eq!(add(2, 3), 5); assert_eq!(add(2, 3), 5);
} }
pub void test_fn_return() -> Int { pub i32 test_fn_return() {
42 42
} }
pub void test_fn_early_return() -> Int { pub i32 test_fn_early_return() {
return 100; return 100;
0 0
} }
pub void test_fn_mut_param(Int mut x) -> Int { pub i32 test_fn_mut_param(i32 mut x) {
x = x + 10; x = x + 10;
x x
} }
pub void test_method_call() { pub void test_method_call() {
String s = "hello"; str* s = "hello";
assert_eq!(s.len(), 5); assert_eq!(s.len(), 5);
assert_eq!(s.to_uppercase(), "HELLO"); assert_eq!(s.to_uppercase(), "HELLO");
} }
pub void test_nested_fn_calls() { i32 triple(i32 x) {
Int add(Int a, Int b) {
a + b
}
Int triple(Int x) {
add(x, add(x, x)) add(x, add(x, x))
} }
pub void test_nested_fn_calls() {
assert_eq!(triple(5), 15); assert_eq!(triple(5), 15);
} }
i32 factorial(i32 n) {
if (n <= 1) 1
else (n) * (factorial(n - 1))
}
pub void test_recursive_fn() { pub void test_recursive_fn() {
Int factorial(Int n) {
if (n <= 1) { 1 } else { n * factorial(n - 1) }
}
assert_eq!(factorial(5), 120); assert_eq!(factorial(5), 120);
} }
+3 -3
View File
@@ -1,10 +1,10 @@
struct Vector2 { struct Vector2 {
Int x, i32 x,
Int y, i32 y,
} }
impl Vector2 { impl Vector2 {
pub Int magnitude(self*) -> Int { pub i32 magnitude(self*) {
self.x * self.x + self.y * self.y self.x * self.x + self.y * self.y
} }
} }
+5 -5
View File
@@ -1,6 +1,6 @@
struct Point { struct Point {
Int x, i32 x,
Int y, i32 y,
} }
pub void test_struct_create_access() { pub void test_struct_create_access() {
@@ -22,12 +22,12 @@ pub void test_struct_destructure() {
assert_eq!(y, 4); assert_eq!(y, 4);
} }
pub void test_struct_nested() { struct Line {
struct Line {
Point start, Point start,
Point end, Point end,
} }
pub void test_struct_nested() {
let l = Line { let l = Line {
start: Point { x: 0, y: 0 }, start: Point { x: 0, y: 0 },
end: Point { x: 5, y: 10 }, end: Point { x: 5, y: 10 },
+4 -4
View File
@@ -8,12 +8,12 @@ struct Dog {
impl Speak for Dog { impl Speak for Dog {
String speak(self*) { String speak(self*) {
"woof" "woof".to_string()
} }
} }
pub void test_trait_impl() { pub void test_trait_impl() {
let d = Dog { name: "Rex" }; let d = Dog { name: "Rex".to_string() };
assert_eq!(d.speak(), "woof"); assert_eq!(d.speak(), "woof");
} }
@@ -23,12 +23,12 @@ trait Greet : Speak {
impl Greet for Dog { impl Greet for Dog {
String greet(self*) { String greet(self*) {
"hello" "hello".to_string()
} }
} }
pub void test_trait_with_requirement() { pub void test_trait_with_requirement() {
let d = Dog { name: "Buddy" }; let d = Dog { name: "Buddy".to_string() };
assert_eq!(d.speak(), "woof"); assert_eq!(d.speak(), "woof");
assert_eq!(d.greet(), "hello"); assert_eq!(d.greet(), "hello");
} }