From 70c2ee00fbd0c2326e9f40a1cecce5848e693341 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 14 Jan 2021 20:46:13 -0600 Subject: [PATCH] actually added the test case --- tests/named_arguments_test | 28 +++++++++++++ tests/named_arguments_test.onyx | 73 +++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 tests/named_arguments_test create mode 100644 tests/named_arguments_test.onyx diff --git a/tests/named_arguments_test b/tests/named_arguments_test new file mode 100644 index 00000000..79435032 --- /dev/null +++ b/tests/named_arguments_test @@ -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 index 00000000..a995a6d9 --- /dev/null +++ b/tests/named_arguments_test.onyx @@ -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 -- 2.25.1