summaryrefslogtreecommitdiff
path: root/tests/features/test_default_args.zc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/features/test_default_args.zc')
-rw-r--r--tests/features/test_default_args.zc39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/features/test_default_args.zc b/tests/features/test_default_args.zc
new file mode 100644
index 0000000..cbeba83
--- /dev/null
+++ b/tests/features/test_default_args.zc
@@ -0,0 +1,39 @@
+
+struct Point {
+ x: int;
+ y: int;
+}
+
+fn add_points(p1: Point, p2: Point = Point { x: 10, y: 10 }) -> Point {
+ return Point {
+ x: p1.x + p2.x,
+ y: p1.y + p2.y
+ };
+}
+
+fn operation(a: int, b: int = 5 * 2) -> int {
+ return a + b;
+}
+
+fn main() {
+ var p1 = Point { x: 5, y: 5 };
+ var res1 = add_points(p1);
+
+ println "res1.x: {res1.x}, res1.y: {res1.y}";
+ assert(res1.x == 15, "result is not 15");
+ assert(res1.y == 15, "result is not 15");
+
+ var p2 = Point { x: 1, y: 1 };
+ var p3 = Point { x: 5, y: 5 };
+ var res2 = add_points(p3, p2);
+
+ println "res2.x: {res2.x}, res2.y: {res2.y}";
+ assert(res2.x == 6, "result is not 6");
+ assert(res2.y == 6, "result is not 6");
+
+ println "operation(10): {operation(10)}";
+ assert(operation(10) == 20, "result is not 20");
+
+ println "operation(10, 5): {operation(10, 5)}";
+ assert(operation(10, 5) == 15, "result is not 15");
+}