summaryrefslogtreecommitdiff
path: root/tests/features
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-02-01 14:01:51 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-02-01 14:01:51 +0000
commitfbfce63744882d48ea2fc514ab1594000254db80 (patch)
treecc7949dab2149d829d3c04e3d542553ed883593f /tests/features
parenteafd8c67012ea253436b79f703dc0702046703f8 (diff)
Related to #138
Diffstat (limited to 'tests/features')
-rw-r--r--tests/features/test_portable_types.zc46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/features/test_portable_types.zc b/tests/features/test_portable_types.zc
new file mode 100644
index 0000000..8f54fcb
--- /dev/null
+++ b/tests/features/test_portable_types.zc
@@ -0,0 +1,46 @@
+
+import "std/io.zc";
+
+// This test verifies the new portable integer types and C interop types.
+
+extern fn abs(x: c_int) -> c_int;
+extern fn labs(x: c_long) -> c_long;
+
+fn main() -> int {
+ // Portable types
+ let a: i32 = -42;
+ let b: u32 = 42;
+ let c: i64 = -1000000;
+ let d: u64 = 1000000;
+
+ if (a != -42) return 1;
+ if (b != 42) return 2;
+ if (c != -1000000) return 3;
+ if (d != 1000000) return 4;
+
+ // C Types
+ let ca: c_int = -10;
+ let cb: c_long = -20;
+ let cc: c_short = -5;
+ let cd: c_char = 65; // 'A'
+
+ // Test C interaction
+ let abs_val = abs(ca);
+ let expected_abs: c_int = 10;
+ if (abs_val != expected_abs) return 5;
+
+ let labs_val = labs(cb);
+ let expected_labs: c_long = 20;
+ if (labs_val != expected_labs) return 6;
+
+ // Size checks (these are platform dependent but we can check relations)
+ // sizeof(c_char) is always 1
+ if (sizeof(c_char) != 1) return 7;
+
+ // sizeof(c_short) <= sizeof(c_int) <= sizeof(c_long)
+ if (sizeof(c_short) > sizeof(c_int)) return 8;
+ if (sizeof(c_int) > sizeof(c_long)) return 9;
+
+ printf("Portable types test passed.\n");
+ return 0;
+}