yarn-spinner-runner-ts 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +34 -16
  2. package/dist/compile/compiler.js +2 -2
  3. package/dist/compile/compiler.js.map +1 -1
  4. package/dist/compile/ir.d.ts +1 -0
  5. package/dist/markup/parser.js +12 -2
  6. package/dist/markup/parser.js.map +1 -1
  7. package/dist/model/ast.d.ts +1 -0
  8. package/dist/parse/lexer.js +5 -5
  9. package/dist/parse/lexer.js.map +1 -1
  10. package/dist/parse/parser.js +12 -2
  11. package/dist/parse/parser.js.map +1 -1
  12. package/dist/react/DialogueExample.js +12 -10
  13. package/dist/react/DialogueExample.js.map +1 -1
  14. package/dist/react/DialogueView.d.ts +10 -4
  15. package/dist/react/DialogueView.js +38 -12
  16. package/dist/react/DialogueView.js.map +1 -1
  17. package/dist/react/MarkupRenderer.js +1 -1
  18. package/dist/react/MarkupRenderer.js.map +1 -1
  19. package/dist/react/useYarnRunner.js +63 -10
  20. package/dist/react/useYarnRunner.js.map +1 -1
  21. package/dist/runtime/evaluator.js +3 -2
  22. package/dist/runtime/evaluator.js.map +1 -1
  23. package/dist/runtime/runner.d.ts +2 -0
  24. package/dist/runtime/runner.js +66 -10
  25. package/dist/runtime/runner.js.map +1 -1
  26. package/dist/tests/dialogue_view.test.d.ts +1 -0
  27. package/dist/tests/dialogue_view.test.js +18 -0
  28. package/dist/tests/dialogue_view.test.js.map +1 -0
  29. package/dist/tests/markup.test.js +7 -0
  30. package/dist/tests/markup.test.js.map +1 -1
  31. package/dist/tests/options.test.js +164 -9
  32. package/dist/tests/options.test.js.map +1 -1
  33. package/dist/tests/variables_flow_cmds.test.js +52 -10
  34. package/dist/tests/variables_flow_cmds.test.js.map +1 -1
  35. package/docs/markup.md +33 -33
  36. package/eslint.config.cjs +39 -39
  37. package/package.json +6 -6
  38. package/src/compile/compiler.ts +2 -2
  39. package/src/compile/ir.ts +1 -1
  40. package/src/markup/parser.ts +53 -43
  41. package/src/model/ast.ts +1 -0
  42. package/src/parse/lexer.ts +18 -18
  43. package/src/parse/parser.ts +33 -22
  44. package/src/react/DialogueExample.tsx +16 -14
  45. package/src/react/DialogueView.tsx +312 -275
  46. package/src/react/MarkupRenderer.tsx +1 -2
  47. package/src/react/useYarnRunner.tsx +101 -34
  48. package/src/runtime/evaluator.ts +15 -14
  49. package/src/runtime/runner.ts +102 -37
  50. package/src/tests/dialogue_view.test.tsx +26 -0
  51. package/src/tests/markup.test.ts +17 -1
  52. package/src/tests/options.test.ts +206 -36
  53. package/src/tests/variables_flow_cmds.test.ts +72 -28
@@ -2,32 +2,76 @@ import { test } from "node:test";
2
2
  import { strictEqual } from "node:assert";
3
3
  import { parseYarn, compile, YarnRunner } from "../index.js";
4
4
 
5
- test("variables, flow control, and commands", () => {
6
- const script = `
7
- title: Start
8
- ---
9
- <<set $score to 10>>
10
- <<if $score >= 10>>
11
- Narrator: High
12
- <<else>>
13
- Narrator: Low
14
- <<endif>>
15
- ===
16
- `;
17
-
18
- const doc = parseYarn(script);
19
- const ir = compile(doc);
20
- const runner = new YarnRunner(ir, { startAt: "Start" });
21
-
22
- // After command, expect if-branch 'High'
23
- // First result should be command emission
24
- const a = runner.currentResult!;
25
- strictEqual(a.type, "command", "First result should be command");
26
- runner.advance();
27
- const b = runner.currentResult!;
28
- strictEqual(b.type, "text", "Should be text after command");
29
- if (b.type === "text") strictEqual(/High/.test(b.text), true, "Expected High branch");
30
- strictEqual(runner.getVariable("score"), 10, "Variable should be set");
31
- });
32
-
5
+ test("variables, flow control, and commands", () => {
6
+ const script = `
7
+ title: Start
8
+ ---
9
+ <<set $score to 10>>
10
+ <<if $score >= 10>>
11
+ Narrator: High
12
+ <<else>>
13
+ Narrator: Low
14
+ <<endif>>
15
+ ===
16
+ `;
17
+
18
+ const doc = parseYarn(script);
19
+ const ir = compile(doc);
20
+ const runner = new YarnRunner(ir, { startAt: "Start" });
21
+
22
+ // After command, expect if-branch 'High'
23
+ // First result should be command emission
24
+ const a = runner.currentResult!;
25
+ strictEqual(a.type, "command", "First result should be command");
26
+ runner.advance();
27
+ const b = runner.currentResult!;
28
+ strictEqual(b.type, "text", "Should be text after command");
29
+ if (b.type === "text") strictEqual(/High/.test(b.text), true, "Expected High branch");
30
+ strictEqual(runner.getVariable("score"), 10, "Variable should be set");
31
+ });
32
+
33
+ test("equality operators support ==, !=, and single =", () => {
34
+ const script = `
35
+ title: Start
36
+ ---
37
+ <<set $doorOpen to true>>
38
+ <<if $doorOpen = true>>
39
+ Narrator: Single equals ok
40
+ <<endif>>
41
+ <<if $doorOpen == true>>
42
+ Narrator: Double equals ok
43
+ <<endif>>
44
+ <<if $doorOpen != false>>
45
+ Narrator: Not equals ok
46
+ <<endif>>
47
+ ===
48
+ `;
49
+
50
+ const doc = parseYarn(script);
51
+ const ir = compile(doc);
52
+ const runner = new YarnRunner(ir, { startAt: "Start" });
53
+
54
+ const seen: string[] = [];
55
+ let guard = 25;
56
+ while (guard-- > 0) {
57
+ const result = runner.currentResult;
58
+ if (!result) break;
59
+ if (result.type === "text" && result.text.trim()) {
60
+ seen.push(result.text.trim());
61
+ }
62
+ if (result.isDialogueEnd) {
63
+ break;
64
+ }
65
+ if (result.type === "options") {
66
+ runner.advance(0);
67
+ } else {
68
+ runner.advance();
69
+ }
70
+ }
71
+
72
+ strictEqual(seen.includes("Single equals ok"), true, "Single equals comparison should succeed");
73
+ strictEqual(seen.includes("Double equals ok"), true, "Double equals comparison should succeed");
74
+ strictEqual(seen.includes("Not equals ok"), true, "Not equals comparison should succeed");
75
+ });
76
+
33
77