Updated tests and fixed grammar

This commit is contained in:
2026-06-23 03:44:54 +02:00
parent 2ae4ca510d
commit 2f6303ba30
14 changed files with 135 additions and 134 deletions
+13 -13
View File
@@ -1,60 +1,60 @@
pub module function_test;
fn void greet() {
void greet() {
let mut x = 1;
x++;
}
pub fn void test_basic_function() {
pub void test_basic_function() {
greet();
}
fn i32 add(a i32, b i32) {
i32 add(i32 a, i32 b) {
a + b
}
pub fn void test_fn_params() {
pub void test_fn_params() {
assert_eq!(add(2, 3), 5);
}
pub fn i32 test_fn_return() {
pub i32 test_fn_return() {
42
}
pub fn i32 test_fn_early_return() {
pub i32 test_fn_early_return() {
return 100;
0
}
pub fn i32 test_fn_mut_param(mut x i32) {
pub i32 test_fn_mut_param(i32 mut x) {
x = x + 10;
x
}
pub fn void test_method_call() {
pub void test_method_call() {
let s = "hello";
assert_eq!(s.len(), 5);
assert_eq!(s.to_uppercase(), "HELLO");
}
fn i32 triple(x i32) {
i32 triple(i32 x) {
add(x, add(x, x))
}
pub fn void test_nested_fn_calls() {
pub void test_nested_fn_calls() {
assert_eq!(triple(5), 15);
}
fn i32 factorial(n i32) {
i32 factorial(i32 n) {
if n <= 1 { 1 }
else { n * factorial(n - 1) }
}
pub fn void test_recursive_fn() {
pub void test_recursive_fn() {
assert_eq!(factorial(5), 120);
}
pub fn void run_tests() {
pub void run_tests() {
test_basic_function();
test_fn_params();
assert_eq!(test_fn_return(), 42);