summaryrefslogtreecommitdiff
path: root/tests/features
diff options
context:
space:
mode:
Diffstat (limited to 'tests/features')
-rw-r--r--tests/features/_opaque_alias_lib.zc13
-rw-r--r--tests/features/_opaque_lib.zc15
-rw-r--r--tests/features/test_build_directives.zc21
-rw-r--r--tests/features/test_implicit_fstring.zc19
-rw-r--r--tests/features/test_opaque.zc18
-rw-r--r--tests/features/test_opaque_alias.zc13
-rw-r--r--tests/features/test_traits_suite.zc2
7 files changed, 84 insertions, 17 deletions
diff --git a/tests/features/_opaque_alias_lib.zc b/tests/features/_opaque_alias_lib.zc
new file mode 100644
index 0000000..7ca4abc
--- /dev/null
+++ b/tests/features/_opaque_alias_lib.zc
@@ -0,0 +1,13 @@
+opaque alias Handle = int;
+
+fn new_handle(v: int) -> Handle {
+ return v; // Implicit cast int -> Handle (OK in module)
+}
+
+fn get_val(h: Handle) -> int {
+ return h; // Implicit cast Handle -> int (OK in module)
+}
+
+fn compare_handles(a: Handle, b: Handle) -> bool {
+ return a == b; // Strict equality (OK)
+}
diff --git a/tests/features/_opaque_lib.zc b/tests/features/_opaque_lib.zc
new file mode 100644
index 0000000..de4d4c4
--- /dev/null
+++ b/tests/features/_opaque_lib.zc
@@ -0,0 +1,15 @@
+opaque struct SecretBox {
+ value: int;
+}
+
+fn new_box(v: int) -> SecretBox {
+ return SecretBox { value: v };
+}
+
+fn get_value(b: SecretBox*) -> int {
+ return b.value;
+}
+
+fn set_value(b: SecretBox*, v: int) {
+ b.value = v;
+}
diff --git a/tests/features/test_build_directives.zc b/tests/features/test_build_directives.zc
index 7edd317..d3f1cba 100644
--- a/tests/features/test_build_directives.zc
+++ b/tests/features/test_build_directives.zc
@@ -1,19 +1,8 @@
-//> link: -lm
-//> cflags: -O2
-// Declare C math function (since we don't have a math stdlib module yet)
-extern fn sin(x: double) -> double;
+//> shell: echo "Env Worked" > ${PWD}/build_dir_env.txt
+//> linux: shell: echo "Linux Worked" > ${PWD}/build_dir_linux.txt
+//> windows: shell: echo "Windows Worked" > ${PWD}/build_dir_windows.txt
-test "test_build_directives" {
- println "Running Build Directives Test...";
- let x = 3.14159 / 2.0; // PI/2
- let s = sin(x);
- // sin(PI/2) should be 1.0
- println "sin(PI/2) = {s}";
-
- if (s > 0.99 && s < 1.01) {
- println "Math Link Success!";
- } else {
- println "Math Link Failure (Value wrong)";
- }
+fn main() {
+ return 0;
}
diff --git a/tests/features/test_implicit_fstring.zc b/tests/features/test_implicit_fstring.zc
new file mode 100644
index 0000000..85a6c86
--- /dev/null
+++ b/tests/features/test_implicit_fstring.zc
@@ -0,0 +1,19 @@
+
+test "implicit_fstring_interpolation" {
+ let result = 123;
+ let s = "{result}";
+ // Should be "123"
+ assert(strcmp(s, "123") == 0, "Implicit f-string failed");
+}
+
+test "implicit_fstring_complex" {
+ let a = 10;
+ let b = 20;
+ let s = "Sum: {a + b}";
+ assert(strcmp(s, "Sum: 30") == 0, "Complex implicit f-string failed");
+}
+
+test "no_interpolation" {
+ let s = "Hello World";
+ assert(strcmp(s, "Hello World") == 0, "Plain string failed");
+}
diff --git a/tests/features/test_opaque.zc b/tests/features/test_opaque.zc
new file mode 100644
index 0000000..5c84b2a
--- /dev/null
+++ b/tests/features/test_opaque.zc
@@ -0,0 +1,18 @@
+import "_opaque_lib.zc";
+
+fn main() {
+ let b = new_box(42);
+
+ // Stack allocation should work (size known)
+ let b2: SecretBox;
+ b2 = b;
+
+ // Public methods should work
+ let v = get_value(&b2);
+ assert(v == 42, "Value should be 42");
+
+ set_value(&b2, 100);
+ assert(get_value(&b2) == 100, "Value should be 100");
+
+ println "Opaque struct test passed";
+}
diff --git a/tests/features/test_opaque_alias.zc b/tests/features/test_opaque_alias.zc
new file mode 100644
index 0000000..062fa1f
--- /dev/null
+++ b/tests/features/test_opaque_alias.zc
@@ -0,0 +1,13 @@
+import "_opaque_alias_lib.zc";
+
+fn main() {
+ let h = new_handle(42);
+ let v = get_val(h);
+
+ assert(v == 42, "Opaque Alias FAIL");
+
+ let h2 = new_handle(42);
+ assert(compare_handles(h, h2), "Equality FAIL");
+
+ println "Opaque Alias OK";
+}
diff --git a/tests/features/test_traits_suite.zc b/tests/features/test_traits_suite.zc
index 205bdf6..2ff8378 100644
--- a/tests/features/test_traits_suite.zc
+++ b/tests/features/test_traits_suite.zc
@@ -90,7 +90,7 @@ test "test_derive" {
// Debug
let s = p1.to_string();
- assert(strcmp(s, "Point { ... }") == 0, "Debug string matches");
+ assert(strcmp(s, "Point {{ ... }}") == 0, "Debug string matches");
// Clone
let p2 = p1.clone();