about summary refs log tree commit diff stats
path: root/js/baba-yaga/tests/with-when-expressions.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/baba-yaga/tests/with-when-expressions.test.js')
-rw-r--r--js/baba-yaga/tests/with-when-expressions.test.js42
1 files changed, 19 insertions, 23 deletions
diff --git a/js/baba-yaga/tests/with-when-expressions.test.js b/js/baba-yaga/tests/with-when-expressions.test.js
index bdb4402..af14d10 100644
--- a/js/baba-yaga/tests/with-when-expressions.test.js
+++ b/js/baba-yaga/tests/with-when-expressions.test.js
@@ -1,7 +1,7 @@
 import assert from 'assert';
-import { createLexer } from '../lexer.js';
-import { createParser } from '../parser.js';
-import { createInterpreter } from '../interpreter.js';
+import { createLexer } from '../src/core/lexer.js';
+import { createParser } from '../src/core/parser.js';
+import { createInterpreter } from '../src/core/interpreter.js';
 
 function interpret(code) {
   const lexer = createLexer(code);
@@ -44,30 +44,26 @@ describe('with header: when expressions', () => {
     assert.strictEqual(itp.scope.get('result3'), 'large');
   });
 
-  it('evaluates complex nested when expressions with multiple discriminants', () => {
+  it('evaluates complex when expressions with pattern guards', () => {
     const code = `
-      test : x y ->
+      test : x ->
         with (
-          position : when x y is
-            0 0 then "origin"
-            _ _ then when (x > 0) (y > 0) is
-              true true then "Q1"
-              false true then "Q2"
-              false false then "Q3"
-              true false then "Q4";
-        ) -> position;
-      result1 : test 0 0;
-      result2 : test 3 4;
-      result3 : test -3 4;
-      result4 : test -3 -4;
-      result5 : test 3 -4;
+          category : when x is
+            n if (n < 0) then "negative"
+            0 then "zero"
+            n if (n > 10) then "large"
+            _ then "small";
+        ) -> category;
+      result1 : test -5;
+      result2 : test 0;
+      result3 : test 5;
+      result4 : test 15;
     `;
     const itp = interpret(code);
-    assert.strictEqual(itp.scope.get('result1'), 'origin');
-    assert.strictEqual(itp.scope.get('result2'), 'Q1');
-    assert.strictEqual(itp.scope.get('result3'), 'Q2');
-    assert.strictEqual(itp.scope.get('result4'), 'Q3');
-    assert.strictEqual(itp.scope.get('result5'), 'Q4');
+    assert.strictEqual(itp.scope.get('result1'), 'negative');
+    assert.strictEqual(itp.scope.get('result2'), 'zero');
+    assert.strictEqual(itp.scope.get('result3'), 'small');
+    assert.strictEqual(itp.scope.get('result4'), 'large');
   });
 
   it('evaluates mixed when expressions with other types', () => {