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 -1
View File
@@ -1,6 +1,6 @@
#[derive(Debug)]
pub struct Debuggable {
Int value,
i32 value,
}
pub void test_derive_attribute() {
+7 -7
View File
@@ -1,7 +1,7 @@
pub class Counter {
pub Int count;
pub i32 count;
pub constructor(Int start) {
pub constructor(i32 start) {
self.count = start;
}
@@ -9,7 +9,7 @@ pub class Counter {
self.count++;
}
pub Int get(self*) -> Int {
pub i32 get(self*) {
self.count
}
}
@@ -33,17 +33,17 @@ pub void test_class_field_access() {
class NamedCounter : Counter {
pub String name;
pub constructor(Int start, String name) {
pub constructor(i32 start, String name) {
self.name = name;
}
pub String get_name(self*) -> String {
self.name
pub String get_name(self*) {
self.name.clone()
}
}
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.count, 10);
}
+3 -3
View File
@@ -1,6 +1,6 @@
enum OptionInt {
None,
Some(Int),
Some[i32],
}
pub void test_enum_named() {
@@ -20,8 +20,8 @@ pub void test_enum_tuple() {
}
enum Shape {
Circle { Int radius },
Rect { Int w, Int h },
Circle { i32 radius },
Rect { i32 w, i32 h },
}
pub void test_enum_struct() {
+22 -20
View File
@@ -1,52 +1,54 @@
void greet() {
let mut x = 1;
x++;
}
pub void test_basic_function() {
void greet() {
let x = 1;
x++;
}
greet();
}
i32 add(i32 a, i32 b) {
a + b
}
pub void test_fn_params() {
Int add(Int a, Int b) {
a + b
}
assert_eq!(add(2, 3), 5);
}
pub void test_fn_return() -> Int {
pub i32 test_fn_return() {
42
}
pub void test_fn_early_return() -> Int {
pub i32 test_fn_early_return() {
return 100;
0
}
pub void test_fn_mut_param(Int mut x) -> Int {
pub i32 test_fn_mut_param(i32 mut x) {
x = x + 10;
x
}
pub void test_method_call() {
String s = "hello";
str* s = "hello";
assert_eq!(s.len(), 5);
assert_eq!(s.to_uppercase(), "HELLO");
}
i32 triple(i32 x) {
add(x, add(x, x))
}
pub void test_nested_fn_calls() {
Int add(Int a, Int b) {
a + b
}
Int triple(Int x) {
add(x, add(x, x))
}
assert_eq!(triple(5), 15);
}
i32 factorial(i32 n) {
if (n <= 1) 1
else (n) * (factorial(n - 1))
}
pub void test_recursive_fn() {
Int factorial(Int n) {
if (n <= 1) { 1 } else { n * factorial(n - 1) }
}
assert_eq!(factorial(5), 120);
}
+3 -3
View File
@@ -1,10 +1,10 @@
struct Vector2 {
Int x,
Int y,
i32 x,
i32 y,
}
impl Vector2 {
pub Int magnitude(self*) -> Int {
pub i32 magnitude(self*) {
self.x * self.x + self.y * self.y
}
}
+7 -7
View File
@@ -1,6 +1,6 @@
struct Point {
Int x,
Int y,
i32 x,
i32 y,
}
pub void test_struct_create_access() {
@@ -22,12 +22,12 @@ pub void test_struct_destructure() {
assert_eq!(y, 4);
}
pub void test_struct_nested() {
struct Line {
Point start,
Point end,
}
struct Line {
Point start,
Point end,
}
pub void test_struct_nested() {
let l = Line {
start: Point { x: 0, y: 0 },
end: Point { x: 5, y: 10 },
+4 -4
View File
@@ -8,12 +8,12 @@ struct Dog {
impl Speak for Dog {
String speak(self*) {
"woof"
"woof".to_string()
}
}
pub void test_trait_impl() {
let d = Dog { name: "Rex" };
let d = Dog { name: "Rex".to_string() };
assert_eq!(d.speak(), "woof");
}
@@ -23,12 +23,12 @@ trait Greet : Speak {
impl Greet for Dog {
String greet(self*) {
"hello"
"hello".to_string()
}
}
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.greet(), "hello");
}