added test case for multiple returns/declarations
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 12 Jan 2021 20:33:40 +0000 (14:33 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 12 Jan 2021 20:33:40 +0000 (14:33 -0600)
tests/multiple_returns_robustness [new file with mode: 0644]
tests/multiple_returns_robustness.onyx [new file with mode: 0644]

diff --git a/tests/multiple_returns_robustness b/tests/multiple_returns_robustness
new file mode 100644 (file)
index 0000000..64ec3eb
--- /dev/null
@@ -0,0 +1,6 @@
+60
+50
+110
+-10 to 200
+0 1 2 
+3.0 4.0 5.0 
diff --git a/tests/multiple_returns_robustness.onyx b/tests/multiple_returns_robustness.onyx
new file mode 100644 (file)
index 0000000..cbda0b4
--- /dev/null
@@ -0,0 +1,58 @@
+#load "core/std/js"
+
+use package core
+
+foo :: proc () -> (i32, i32) {
+    return 50, 60;
+}
+
+something :: proc (f: proc () -> ($T, T)) -> T {
+    a, b := f();
+    return a + b;
+}
+
+get_extrema :: proc (arr: [$N] $T) -> (T, T) {
+    min := arr[0];
+    max := arr[0];
+
+    for e: arr {
+        if e < min do min = e;
+        if e > max do max = e;
+    }
+
+    return min, max;
+}
+
+return_multiple_arrays :: proc () -> ([3] i32, [3] f32) {
+    iarr := i32.[ 0, 1, 2 ];
+    farr := f32.[ 3, 4, 5 ];
+    return iarr, farr;
+}
+
+main :: proc (args: [] cstr) {
+    a, b := foo();
+    a, b = b, a;
+
+    c := something(foo);
+
+    println(a);
+    println(b);
+    println(c);
+
+
+    least, greatest := get_extrema(i32.[ -5, 20, 5, -10, 200, 8 ]);
+    printf("%i to %i\n", least, greatest);
+
+    iarr, farr := return_multiple_arrays();
+    array_print(iarr);
+    array_print(farr);
+
+    array_print :: proc (arr: [$N] $T) {
+        for ^e: arr {
+            print(*e);
+            print(" ");
+        }
+
+        print("\n");
+    }
+}