clarity-pattern-parser 3.0.10 → 3.0.12

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.
@@ -76,6 +76,7 @@ export default class RepeatValue extends ValuePattern {
76
76
  this.nodes.push(node);
77
77
 
78
78
  if (node.endIndex === this.cursor.lastIndex()) {
79
+ this.nodes.length = 0;
79
80
  this._processMatch();
80
81
  break;
81
82
  }
@@ -43,4 +43,16 @@ describe("RepeatComposite", () => {
43
43
  expect(result?.children[2].value).toBe("B");
44
44
  expect(result?.children[2].name).toBe("b");
45
45
  });
46
+
47
+ test("Cannot end on a divider.", () => {
48
+ const a = new Literal("a", "A");
49
+ const b = new Literal("b", "B");
50
+ const space = new Literal("space", " ");
51
+ const or = new OrComposite("names", [a, b]);
52
+
53
+ const repeat = new RepeatComposite("repeat", or, space);
54
+ const result = repeat.parse(new Cursor("A B "));
55
+
56
+ expect(result).toBe(null);
57
+ });
46
58
  });
@@ -5,6 +5,9 @@ import Literal from "../patterns/value/Literal";
5
5
  import AndValue from "../patterns/value/AndValue";
6
6
  import OrValue from "../patterns/value/OrValue";
7
7
  import json from "./javascriptPatterns/json";
8
+ import OrComposite from "../patterns/composite/OrComposite";
9
+ import RepeatComposite from "../patterns/composite/RepeatComposite";
10
+ import Cursor from "../Cursor";
8
11
 
9
12
  describe("TextInspector", () => {
10
13
  test("Partial Match", () => {
@@ -214,4 +217,20 @@ describe("TextInspector", () => {
214
217
  expect(inspection.match?.text).toBe(`{"blah":0.9`);
215
218
  expect(inspection.isComplete).toBe(false);
216
219
  });
220
+
221
+ test("Suggest another item in the repeat.", () => {
222
+ const a = new Literal("a", "A");
223
+ const b = new Literal("b", "B");
224
+ const space = new Literal("space", " ");
225
+ const or = new OrComposite("names", [a, b]);
226
+
227
+ const repeat = new RepeatComposite("repeat", or, space);
228
+
229
+ const result = TextSuggester.suggest("A B ", repeat);
230
+
231
+ expect(result.isComplete).toBe(false);
232
+ expect(result.options.values[0]).toBe("A");
233
+ expect(result.options.values[1]).toBe("B");
234
+ expect(result.options.values.length).toBe(2);
235
+ });
217
236
  });