summaryrefslogtreecommitdiff
path: root/tests/misc
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 15:12:12 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 15:12:12 +0000
commit7d1944ab9d2307f2736afe8520436872db1c7617 (patch)
tree7380a4f148f9ce0b70ed9f02cfa5e8561c783a7a /tests/misc
parent8b720543f538862796fec0ff6b7ea12cb140bf0f (diff)
'let' it be
Diffstat (limited to 'tests/misc')
-rw-r--r--tests/misc/test_advanced.zc50
-rw-r--r--tests/misc/test_chained.zc4
-rw-r--r--tests/misc/test_edge_cases.zc32
-rw-r--r--tests/misc/test_mix.zc16
4 files changed, 51 insertions, 51 deletions
diff --git a/tests/misc/test_advanced.zc b/tests/misc/test_advanced.zc
index 8b5b466..e985758 100644
--- a/tests/misc/test_advanced.zc
+++ b/tests/misc/test_advanced.zc
@@ -8,7 +8,7 @@ fn fibonacci(n: int) -> int {
}
fn test_recursion() {
- var fib10 = fibonacci(10);
+ let fib10 = fibonacci(10);
if (fib10 != 55) {
println "FAIL: fibonacci(10) should be 55";
@@ -23,7 +23,7 @@ fn add_three(a: int, b: int, c: int) -> int {
}
fn test_multi_params() {
- var result = add_three(1, 2, 3);
+ let result = add_three(1, 2, 3);
if (result != 6) {
println "FAIL: add_three(1,2,3) should be 6";
@@ -38,7 +38,7 @@ fn double_val(x: int) -> int {
}
fn test_nested_calls() {
- var result = double_val(double_val(double_val(2)));
+ let result = double_val(double_val(double_val(2)));
if (result != 16) {
println "FAIL: nested calls failed";
@@ -67,7 +67,7 @@ impl Counter {
}
fn test_struct_methods() {
- var c = Counter::new();
+ let c = Counter::new();
c.increment();
c.increment();
c.increment();
@@ -81,16 +81,16 @@ fn test_struct_methods() {
}
fn test_casting() {
- var f: float = 3.7;
- var i: int = (int)f;
+ let f: float = 3.7;
+ let i: int = (int)f;
if (i != 3) {
println "FAIL: float to int cast failed";
exit(1);
}
- var i2: int = 42;
- var f2: float = (float)i2;
+ let i2: int = 42;
+ let f2: float = (float)i2;
if (f2 < 41.9 || f2 > 42.1) {
println "FAIL: int to float cast failed";
@@ -101,12 +101,12 @@ fn test_casting() {
}
fn test_bitwise() {
- var a = 0b1010; // 10
- var b = 0b1100; // 12
+ let a = 0b1010; // 10
+ let b = 0b1100; // 12
- var and_result = a & b; // 0b1000 = 8
- var or_result = a | b; // 0b1110 = 14
- var xor_result = a ^ b; // 0b0110 = 6
+ let and_result = a & b; // 0b1000 = 8
+ let or_result = a | b; // 0b1110 = 14
+ let xor_result = a ^ b; // 0b0110 = 6
if (and_result != 8) {
println "FAIL: bitwise AND failed";
@@ -127,16 +127,16 @@ fn test_bitwise() {
}
fn test_shift() {
- var x = 1;
- var left = x << 4; // 16
+ let x = 1;
+ let left = x << 4; // 16
if (left != 16) {
println "FAIL: left shift failed";
exit(1);
}
- var y = 32;
- var right = y >> 2; // 8
+ let y = 32;
+ let right = y >> 2; // 8
if (right != 8) {
println "FAIL: right shift failed";
@@ -147,9 +147,9 @@ fn test_shift() {
}
fn test_modulo() {
- var a = 17;
- var b = 5;
- var result = a % b;
+ let a = 17;
+ let b = 5;
+ let result = a % b;
if (result != 2) {
println "FAIL: modulo operation failed";
@@ -160,11 +160,11 @@ fn test_modulo() {
}
fn test_compound_expr() {
- var x = 5;
- var y = 10;
- var z = 3;
+ let x = 5;
+ let y = 10;
+ let z = 3;
- var result = (x + y) * z - (y / 2);
+ let result = (x + y) * z - (y / 2);
// (5 + 10) * 3 - (10 / 2) = 15 * 3 - 5 = 45 - 5 = 40
if (result != 40) {
@@ -176,7 +176,7 @@ fn test_compound_expr() {
}
fn test_increment_style() {
- var x = 5;
+ let x = 5;
x = x + 1;
if (x != 6) {
diff --git a/tests/misc/test_chained.zc b/tests/misc/test_chained.zc
index e758db7..a92ae18 100644
--- a/tests/misc/test_chained.zc
+++ b/tests/misc/test_chained.zc
@@ -2,8 +2,8 @@
import "std/string.zc"
test "test_chained" {
- var s = String::from("hello");
- var opt = s.find('e');
+ let s = String::from("hello");
+ let opt = s.find('e');
if opt.is_some() {
"Found at index: {opt.unwrap()}";
}
diff --git a/tests/misc/test_edge_cases.zc b/tests/misc/test_edge_cases.zc
index 0d50744..79a927f 100644
--- a/tests/misc/test_edge_cases.zc
+++ b/tests/misc/test_edge_cases.zc
@@ -6,8 +6,8 @@ import "std.zc"
struct Empty {}
fn test_empty_struct() {
- var e1 = Empty {};
- var e2 = Empty {};
+ let e1 = Empty {};
+ let e2 = Empty {};
if (!e1.eq(&e2)) {
println "FAIL: Empty struct eq failed";
@@ -31,9 +31,9 @@ struct ManyFields {
}
fn test_many_fields() {
- var m1 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 };
- var m2 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 };
- var m3 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 9 }; // h differs
+ let m1 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 };
+ let m2 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 };
+ let m3 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 9 }; // h differs
if (!m1.eq(&m2)) {
println "FAIL: equal structs not detected as equal";
@@ -55,11 +55,11 @@ struct Point {
}
fn test_pointer_equality() {
- var p1 = Point { x: 1, y: 2 };
- var ptr1: Point* = &p1;
- var ptr2: Point* = &p1;
- var p2 = Point { x: 1, y: 2 };
- var ptr3: Point* = &p2;
+ let p1 = Point { x: 1, y: 2 };
+ let ptr1: Point* = &p1;
+ let ptr2: Point* = &p1;
+ let p2 = Point { x: 1, y: 2 };
+ let ptr3: Point* = &p2;
// Same pointer should be equal
if (ptr1 != ptr2) {
@@ -78,7 +78,7 @@ fn test_pointer_equality() {
// Very long string
fn test_long_string() {
- var s = String::from("This is a very long string that should test the string handling capabilities of the compiler and make sure that buffer allocations are correct and that there are no overflow issues with long strings.");
+ let s = String::from("This is a very long string that should test the string handling capabilities of the compiler and make sure that buffer allocations are correct and that there are no overflow issues with long strings.");
if (s.length() < 100) {
println "FAIL: long string length incorrect";
@@ -90,7 +90,7 @@ fn test_long_string() {
// Null pointer handling
fn test_null_pointer() {
- var ptr: int* = NULL;
+ let ptr: int* = NULL;
if (ptr != NULL) {
println "FAIL: NULL pointer check failed";
@@ -102,8 +102,8 @@ fn test_null_pointer() {
// Numeric edge cases
fn test_numeric_edges() {
- var max_int: int = 2147483647;
- var min_int: int = -1000000000;
+ let max_int: int = 2147483647;
+ let min_int: int = -1000000000;
if (max_int <= 0) {
println "FAIL: max_int is wrong";
@@ -120,8 +120,8 @@ fn test_numeric_edges() {
// Boolean operations
fn test_boolean_ops() {
- var a = true;
- var b = false;
+ let a = true;
+ let b = false;
if (!(a && !b)) {
println "FAIL: boolean AND failed";
diff --git a/tests/misc/test_mix.zc b/tests/misc/test_mix.zc
index b4edca4..f2880e9 100644
--- a/tests/misc/test_mix.zc
+++ b/tests/misc/test_mix.zc
@@ -13,12 +13,12 @@ fn square(x: int) -> int {
}
test "test_result_constructors" {
- var res = Result_Ok(42);
+ let res = Result_Ok(42);
assert(res.tag == Result_Ok_Tag, "Expected Ok tag");
assert(res.data.Ok == 42, "Data mismatch");
- var err = Result_Err(500);
+ let err = Result_Err(500);
assert(err.tag == Result_Err_Tag, "Expected Err tag");
}
@@ -26,17 +26,17 @@ test "test_pipelines" {
// Logic: ((5 + 5) * (5 + 5))
// 5 |> add(5) -> 10
// 10 |> square() -> 100
- var val = 5 |> add(5) |> square();
+ let val = 5 |> add(5) |> square();
println "Pipeline result: {val}";
assert(val == 100, "Pipeline calculation failed");
}
test "test_fstrings" {
- var x = 10;
- var name = "ZPrep";
+ let x = 10;
+ let name = "ZPrep";
- var s = f"Hello {name}, x = {x}, x * 2 = {x * 2}";
+ let s = f"Hello {name}, x = {x}, x * 2 = {x * 2}";
println "F-String: {s}";
assert(x == 10, "Sanity check");
@@ -52,8 +52,8 @@ test "test_defer" {
}
test "test_hex_binary" {
- var h = 0xFF; // 255
- var b = 0b1010; // 10
+ let h = 0xFF; // 255
+ let b = 0b1010; // 10
assert(h == 255, "Hex parsing failed");
assert(b == 10, "Binary parsing failed");
}