summaryrefslogtreecommitdiff
path: root/tests/features
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-23 12:22:57 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-23 12:22:57 +0000
commitf73df8d5de30a7f3f320fccf5f57c13094940a6a (patch)
tree877fda85fa3c4a906d6943ac7b7836886bc4140a /tests/features
parent98623f2fdd63232edf0ebab1b9680cf4e33e6f10 (diff)
Variadic functions + more docs
Diffstat (limited to 'tests/features')
-rw-r--r--tests/features/test_varargs.zc22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/features/test_varargs.zc b/tests/features/test_varargs.zc
new file mode 100644
index 0000000..b06f66e
--- /dev/null
+++ b/tests/features/test_varargs.zc
@@ -0,0 +1,22 @@
+
+test "Variadic Sum" {
+ // We can't define full variadic functions inside tests easily due to closure wrapping in some contexts?
+ // Actually, global functions are better. But tests usually run in main.
+ // Let's rely on declared test function below.
+ assert(sum_all(3, 10, 20, 30) == 60);
+ assert(sum_all(5, 1, 1, 1, 1, 1) == 5);
+ puts("OK");
+}
+
+fn sum_all(count: int, ...) -> int {
+ var total = 0;
+ var ap: va_list;
+ va_start(ap, count);
+
+ for (var i = 0; i < count; i = i + 1) {
+ total = total + va_arg(ap, int);
+ }
+
+ va_end(ap);
+ return total;
+}