about summary refs log tree commit diff stats
path: root/js/scripting-lang/tests/20_via_operator.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/tests/20_via_operator.txt')
-rw-r--r--js/scripting-lang/tests/20_via_operator.txt31
1 files changed, 31 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/20_via_operator.txt b/js/scripting-lang/tests/20_via_operator.txt
new file mode 100644
index 0000000..afdc4c3
--- /dev/null
+++ b/js/scripting-lang/tests/20_via_operator.txt
@@ -0,0 +1,31 @@
+/* Unit Test: Via Operator */
+/* Tests: Function composition using the 'via' keyword */
+
+/* Basic functions for testing */
+double : x -> x * 2;
+increment : x -> x + 1;
+square : x -> x * x;
+
+/* Test 1: Basic via composition */
+result1 : double via increment 5;
+..assert result1 = 12;  /* (5+1)*2 = 12 */
+
+/* Test 2: Chained via composition */
+result2 : double via increment via square 3;
+..assert result2 = 20;  /* (3^2+1)*2 = (9+1)*2 = 20 */
+
+/* Test 3: Function references with via */
+result3 : @double via @increment 4;
+..assert result3 = 10;  /* (4+1)*2 = 10 */
+
+/* Test 4: Right-associative behavior */
+step1 : increment via square 3;  /* (3^2)+1 = 10 */
+step2 : double via increment 3;  /* (3+1)*2 = 8 */
+..assert step1 = 10;
+..assert step2 = 8;
+
+/* Test 5: Precedence - via binds tighter than function application */
+precedence_test : double via increment 5;
+..assert precedence_test = 12;  /* (5+1)*2 = 12 */
+
+..out "Via operator test completed"; 
\ No newline at end of file