actually added the test case
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Jan 2021 02:46:13 +0000 (20:46 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Jan 2021 02:46:13 +0000 (20:46 -0600)
tests/named_arguments_test [new file with mode: 0644]
tests/named_arguments_test.onyx [new file with mode: 0644]

diff --git a/tests/named_arguments_test b/tests/named_arguments_test
new file mode 100644 (file)
index 0000000..7943503
--- /dev/null
@@ -0,0 +1,28 @@
+x is 10
+y is 20.0
+x is 20
+y is 10.0
+
+
+=========================
+10
+10 20 30
+10.0
+10.0 20.0 30.0
+
+
+=========================
+MATCHED Y: 10 20
+MATCHED X: 10
+MATCHED Z: 10
+
+
+=========================
+10
+20
+30.0 40.0 50.0 
+
+
+=========================
+false true false true true false true
+true false false true true false true
diff --git a/tests/named_arguments_test.onyx b/tests/named_arguments_test.onyx
new file mode 100644 (file)
index 0000000..a995a6d
--- /dev/null
@@ -0,0 +1,73 @@
+#load "core/std/js"
+
+use package core
+
+main :: proc (args: [] cstr) {
+    foo :: proc (x: i32, y: f32) {
+        printf("x is %i\n", x);
+        printf("y is %f\n", y);
+    }
+
+    foo(10, 20);
+    foo(y = 10, x = 20);
+
+
+    println("\n\n=========================");
+
+    poly_named :: proc (x: $T, y: [$N] T) {
+        println(x);
+        print_array(y);
+    }
+
+    poly_named(10, ~~ u32.[ 10, 20, 30 ]);
+    poly_named(y = ~~ f32.[ 10, 20, 30 ], 10.0f);
+
+
+    println("\n\n=========================");
+
+    poly_overloaded :: proc {
+        proc (y: [$N] $T) { print("MATCHED Y: "); print_array(y); },
+        proc (x: $T)      { print("MATCHED X: "); println(x); },
+        proc (z: $T)      { print("MATCHED Z: "); println(z); },
+    }
+
+    poly_overloaded(u32.[ 10, 20 ]);
+    poly_overloaded(10);
+    poly_overloaded(z = 10);
+
+
+    println("\n\n=========================");
+
+    overload_with_varargs :: proc (x: i32, y: i32, z: ..f32) {
+        println(x);
+        println(y);
+
+        for elem: z do printf("%f ", elem);
+        printf("\n");
+    }
+
+    overload_with_varargs(10, 20, 30, 40, 50);
+
+
+
+    println("\n\n=========================");
+
+    lotza_options :: proc (
+        options_a : bool,
+        options_b := false,
+        options_c := true,
+        options_d := true,
+        options_e := false,
+        options_f := false,
+        options_g := true,
+        ) {
+        printf("%b %b %b %b %b %b %b\n",
+            options_a, options_b,
+            options_c, options_d,
+            options_e, options_f,
+            options_g);
+    }
+
+    lotza_options(options_e = true, options_c = false, /* option_a */ false, /* option_b */ true);
+    lotza_options(options_e = true, options_c = false, options_a = true);
+}
\ No newline at end of file