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.
- package/dist/index.browser.js +15 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +15 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/patterns/composite/RepeatComposite.ts +2 -1
- package/src/patterns/value/RepeatValue.ts +1 -0
- package/src/tests/RepeatComposite.test.ts +12 -0
- package/src/tests/TextSuggester.test.ts +19 -0
|
@@ -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
|
});
|