clarity-pattern-parser 6.0.0 → 7.0.0
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/TODO.md +1 -76
- package/dist/ast/Node.d.ts +1 -0
- package/dist/grammar/Grammar.d.ts +17 -0
- package/dist/grammar/patterns/andLiteral.d.ts +2 -0
- package/dist/grammar/patterns/comment.d.ts +2 -0
- package/dist/grammar/patterns/grammar.d.ts +2 -0
- package/dist/grammar/patterns/literal.d.ts +2 -0
- package/dist/grammar/patterns/name.d.ts +2 -0
- package/dist/grammar/patterns/orLiteral.d.ts +2 -0
- package/dist/grammar/patterns/pattern.d.ts +2 -0
- package/dist/grammar/patterns/regexLiteral.d.ts +2 -0
- package/dist/grammar/patterns/repeatLiteral.d.ts +3 -0
- package/dist/grammar/patterns/spaces.d.ts +2 -0
- package/dist/grammar/patterns/statement.d.ts +2 -0
- package/dist/index.browser.js +1205 -550
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.esm.js +1203 -549
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1203 -548
- package/dist/index.js.map +1 -1
- package/dist/intellisense/AutoComplete.d.ts +9 -7
- package/dist/intellisense/Suggestion.d.ts +1 -2
- package/dist/patterns/And.d.ts +2 -1
- package/dist/patterns/Cursor.d.ts +1 -0
- package/dist/patterns/CursorHistory.d.ts +2 -1
- package/dist/patterns/FiniteRepeat.d.ts +39 -0
- package/dist/patterns/InfiniteRepeat.d.ts +47 -0
- package/dist/patterns/Literal.d.ts +2 -1
- package/dist/patterns/Not.d.ts +2 -1
- package/dist/patterns/Or.d.ts +2 -1
- package/dist/patterns/Pattern.d.ts +3 -2
- package/dist/patterns/Reference.d.ts +2 -1
- package/dist/patterns/Regex.d.ts +2 -1
- package/dist/patterns/Repeat.d.ts +19 -22
- package/jest.config.js +0 -1
- package/jest.coverage.config.js +13 -0
- package/package.json +3 -3
- package/src/ast/Node.test.ts +21 -0
- package/src/ast/Node.ts +12 -6
- package/src/grammar/Grammar.test.ts +288 -0
- package/src/grammar/Grammar.ts +234 -0
- package/src/grammar/patterns/andLiteral.ts +8 -0
- package/src/grammar/patterns/comment.ts +3 -0
- package/src/grammar/patterns/grammar.ts +19 -0
- package/src/grammar/patterns/literal.ts +5 -0
- package/src/grammar/patterns/name.ts +3 -0
- package/src/grammar/patterns/orLiteral.ts +8 -0
- package/src/grammar/patterns/pattern.ts +13 -0
- package/src/grammar/patterns/regexLiteral.ts +4 -0
- package/src/grammar/patterns/repeatLiteral.ts +72 -0
- package/src/grammar/patterns/spaces.ts +4 -0
- package/src/grammar/patterns/statement.ts +35 -0
- package/src/grammar/spec.md +142 -0
- package/src/index.ts +6 -3
- package/src/intellisense/AutoComplete.test.ts +125 -39
- package/src/intellisense/AutoComplete.ts +52 -36
- package/src/intellisense/Suggestion.ts +1 -2
- package/src/intellisense/css/cssValue.ts +1 -1
- package/src/intellisense/css/method.ts +1 -1
- package/src/intellisense/css/values.ts +1 -1
- package/src/intellisense/javascript/Javascript.test.ts +34 -11
- package/src/intellisense/javascript/arrayLiteral.ts +1 -1
- package/src/intellisense/javascript/{expressionStatement.ts → assignment.ts} +7 -8
- package/src/intellisense/javascript/expression.ts +45 -27
- package/src/intellisense/javascript/infixOperator.ts +6 -2
- package/src/intellisense/javascript/invocation.ts +1 -1
- package/src/intellisense/javascript/keywords.ts +3 -0
- package/src/intellisense/javascript/objectAccess.ts +9 -0
- package/src/intellisense/javascript/objectLiteral.ts +3 -3
- package/src/intellisense/javascript/parameters.ts +1 -1
- package/src/intellisense/javascript/propertyAccess.ts +8 -3
- package/src/intellisense/javascript/stringLiteral.ts +14 -8
- package/src/patterns/And.test.ts +16 -3
- package/src/patterns/And.ts +25 -17
- package/src/patterns/Cursor.ts +4 -0
- package/src/patterns/CursorHistory.ts +34 -5
- package/src/patterns/FiniteRepeat.test.ts +481 -0
- package/src/patterns/FiniteRepeat.ts +231 -0
- package/src/patterns/InfiniteRepeat.test.ts +296 -0
- package/src/patterns/InfiniteRepeat.ts +329 -0
- package/src/patterns/Literal.test.ts +13 -4
- package/src/patterns/Literal.ts +5 -1
- package/src/patterns/Not.test.ts +20 -9
- package/src/patterns/Not.ts +5 -1
- package/src/patterns/Or.test.ts +18 -7
- package/src/patterns/Or.ts +11 -1
- package/src/patterns/Pattern.ts +3 -2
- package/src/patterns/Reference.test.ts +18 -8
- package/src/patterns/Reference.ts +5 -1
- package/src/patterns/Regex.test.ts +13 -4
- package/src/patterns/Regex.ts +5 -1
- package/src/patterns/Repeat.test.ts +162 -158
- package/src/patterns/Repeat.ts +95 -226
|
@@ -86,7 +86,7 @@ describe("Regex", () => {
|
|
|
86
86
|
|
|
87
87
|
test("Get Next Tokens", () => {
|
|
88
88
|
const parent = new And("parent", [new Regex("a", "A"), new Literal("b", "B")]);
|
|
89
|
-
const aClone = parent.
|
|
89
|
+
const aClone = parent.find(p => p.name === "a") as Pattern;
|
|
90
90
|
const tokens = aClone.getNextTokens();
|
|
91
91
|
|
|
92
92
|
expect(tokens).toEqual(["B"]);
|
|
@@ -99,6 +99,15 @@ describe("Regex", () => {
|
|
|
99
99
|
expect(tokens).toEqual([]);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
test("Get Patterns", () => {
|
|
103
|
+
const a = new Regex("a", "A");
|
|
104
|
+
|
|
105
|
+
const tokens = a.getPatterns();
|
|
106
|
+
const expectedTokens = [a];
|
|
107
|
+
|
|
108
|
+
expect(tokens).toEqual(expectedTokens);
|
|
109
|
+
});
|
|
110
|
+
|
|
102
111
|
test("Get Patterns After", () => {
|
|
103
112
|
const a = new Regex("a", "A")
|
|
104
113
|
const patterns = a.getPatternsAfter(new Literal("bogus", "bogus"));
|
|
@@ -108,15 +117,15 @@ describe("Regex", () => {
|
|
|
108
117
|
|
|
109
118
|
test("Find Pattern", () => {
|
|
110
119
|
const a = new Regex("a", "A")
|
|
111
|
-
const pattern = a.
|
|
120
|
+
const pattern = a.find(p => p.name === "other");
|
|
112
121
|
|
|
113
122
|
expect(pattern).toBeNull();
|
|
114
123
|
});
|
|
115
124
|
|
|
116
125
|
test("Get Next Patterns", () => {
|
|
117
126
|
const parent = new And("parent", [new Regex("a", "A"), new Literal("b", "B")]);
|
|
118
|
-
const aClone = parent.
|
|
119
|
-
const bClone = parent.
|
|
127
|
+
const aClone = parent.find(p => p.name === "a") as Pattern;
|
|
128
|
+
const bClone = parent.find(p => p.name === "b") as Pattern;
|
|
120
129
|
const patterns = aClone.getNextPatterns();
|
|
121
130
|
|
|
122
131
|
expect(patterns.length).toBe(1);
|
package/src/patterns/Regex.ts
CHANGED
|
@@ -157,6 +157,10 @@ export class Regex implements Pattern {
|
|
|
157
157
|
return this.parent.getTokensAfter(this);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
getPatterns(): Pattern[] {
|
|
161
|
+
return [this];
|
|
162
|
+
}
|
|
163
|
+
|
|
160
164
|
getPatternsAfter(_childReference: Pattern): Pattern[] {
|
|
161
165
|
return [];
|
|
162
166
|
}
|
|
@@ -169,7 +173,7 @@ export class Regex implements Pattern {
|
|
|
169
173
|
return this.parent.getPatternsAfter(this)
|
|
170
174
|
}
|
|
171
175
|
|
|
172
|
-
|
|
176
|
+
find(_predicate: (p: Pattern) => boolean): Pattern | null {
|
|
173
177
|
return null;
|
|
174
178
|
}
|
|
175
179
|
|
|
@@ -1,218 +1,222 @@
|
|
|
1
1
|
import { Node } from "../ast/Node";
|
|
2
2
|
import { And } from "./And";
|
|
3
3
|
import { Cursor } from "./Cursor";
|
|
4
|
-
import {
|
|
4
|
+
import { InfiniteRepeat } from "./InfiniteRepeat";
|
|
5
5
|
import { Literal } from "./Literal";
|
|
6
6
|
import { Pattern } from "./Pattern";
|
|
7
7
|
import { Regex } from "./Regex";
|
|
8
8
|
import { Repeat } from "./Repeat";
|
|
9
9
|
|
|
10
|
+
// To Check all behavior look at FiniteRepeat and InfiniteRepeat.
|
|
10
11
|
describe("Repeat", () => {
|
|
11
|
-
test("
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
test("Finite Repeat Without Min", () => {
|
|
13
|
+
const number = new Regex("number", "\\d");
|
|
14
|
+
const finiteRepeat = new Repeat("numbers", number, { max: 2 });
|
|
15
|
+
|
|
16
|
+
let cursor = new Cursor("f");
|
|
17
|
+
let result = finiteRepeat.parse(cursor);
|
|
18
|
+
let expected: Node | null = null;
|
|
19
|
+
|
|
20
|
+
expect(result).toBe(expected);
|
|
21
|
+
expect(cursor.hasError).toBeTruthy();
|
|
22
|
+
|
|
23
|
+
cursor = new Cursor("1");
|
|
24
|
+
result = finiteRepeat.parse(cursor);
|
|
25
|
+
expected = new Node("finite-repeat", "numbers", 0, 0, [
|
|
26
|
+
new Node("regex", "number", 0, 0, [], "1")
|
|
20
27
|
]);
|
|
21
28
|
|
|
22
|
-
expect(result).toEqual(expected)
|
|
23
|
-
expect(cursor.hasError).toBeFalsy()
|
|
24
|
-
});
|
|
29
|
+
expect(result).toEqual(expected);
|
|
30
|
+
expect(cursor.hasError).toBeFalsy();
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
cursor = new Cursor("12");
|
|
33
|
+
result = finiteRepeat.parse(cursor);
|
|
34
|
+
expected = new Node("finite-repeat", "numbers", 0, 1, [
|
|
35
|
+
new Node("regex", "number", 0, 0, [], "1"),
|
|
36
|
+
new Node("regex", "number", 1, 1, [], "2")
|
|
37
|
+
]);
|
|
31
38
|
|
|
32
|
-
expect(result).
|
|
33
|
-
expect(cursor.hasError).
|
|
34
|
-
});
|
|
39
|
+
expect(result).toEqual(expected);
|
|
40
|
+
expect(cursor.hasError).toBeFalsy();
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const result = integer.parse(cursor);
|
|
42
|
-
const expected = new Node("repeat", "number", 0, 4, [
|
|
43
|
-
new Node("regex", "digit", 0, 0, [], "3"),
|
|
44
|
-
new Node("literal", "divider", 1, 1, [], ","),
|
|
45
|
-
new Node("regex", "digit", 2, 2, [], "3"),
|
|
46
|
-
new Node("literal", "divider", 3, 3, [], ","),
|
|
47
|
-
new Node("regex", "digit", 4, 4, [], "7"),
|
|
42
|
+
cursor = new Cursor("123");
|
|
43
|
+
result = finiteRepeat.parse(cursor);
|
|
44
|
+
expected = new Node("finite-repeat", "numbers", 0, 1, [
|
|
45
|
+
new Node("regex", "number", 0, 0, [], "1"),
|
|
46
|
+
new Node("regex", "number", 1, 1, [], "2")
|
|
48
47
|
]);
|
|
49
48
|
|
|
50
|
-
expect(result).toEqual(expected)
|
|
51
|
-
expect(cursor.hasError).toBeFalsy()
|
|
49
|
+
expect(result).toEqual(expected);
|
|
50
|
+
expect(cursor.hasError).toBeFalsy();
|
|
51
|
+
expect(cursor.index).toBe(1);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
test("
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
test("Finite Repeat With Min", () => {
|
|
55
|
+
const number = new Regex("number", "\\d");
|
|
56
|
+
const finiteRepeat = new Repeat("numbers", number, { max: 2, min: 2 });
|
|
57
|
+
|
|
58
|
+
let cursor = new Cursor("f");
|
|
59
|
+
let result = finiteRepeat.parse(cursor);
|
|
60
|
+
let expected: Node | null = null;
|
|
61
|
+
|
|
62
|
+
expect(result).toBe(expected);
|
|
63
|
+
expect(cursor.hasError).toBeTruthy();
|
|
64
|
+
|
|
65
|
+
cursor = new Cursor("1");
|
|
66
|
+
result = finiteRepeat.parse(cursor);
|
|
67
|
+
expected = null;
|
|
68
|
+
|
|
69
|
+
expect(result).toEqual(expected);
|
|
70
|
+
expect(cursor.hasError).toBeTruthy();
|
|
71
|
+
|
|
72
|
+
cursor = new Cursor("12");
|
|
73
|
+
result = finiteRepeat.parse(cursor);
|
|
74
|
+
expected = new Node("finite-repeat", "numbers", 0, 1, [
|
|
75
|
+
new Node("regex", "number", 0, 0, [], "1"),
|
|
76
|
+
new Node("regex", "number", 1, 1, [], "2")
|
|
66
77
|
]);
|
|
67
78
|
|
|
68
|
-
expect(result).toEqual(expected)
|
|
69
|
-
expect(cursor.hasError).toBeFalsy()
|
|
70
|
-
});
|
|
79
|
+
expect(result).toEqual(expected);
|
|
80
|
+
expect(cursor.hasError).toBeFalsy();
|
|
71
81
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const result = integer.parse(cursor);
|
|
78
|
-
const expected = new Node("repeat", "number", 0, 4, [
|
|
79
|
-
new Node("regex", "digit", 0, 0, [], "3"),
|
|
80
|
-
new Node("literal", "divider", 1, 1, [], ","),
|
|
81
|
-
new Node("regex", "digit", 2, 2, [], "3"),
|
|
82
|
-
new Node("literal", "divider", 3, 3, [], ","),
|
|
83
|
-
new Node("regex", "digit", 4, 4, [], "7"),
|
|
82
|
+
cursor = new Cursor("123");
|
|
83
|
+
result = finiteRepeat.parse(cursor);
|
|
84
|
+
expected = new Node("finite-repeat", "numbers", 0, 1, [
|
|
85
|
+
new Node("regex", "number", 0, 0, [], "1"),
|
|
86
|
+
new Node("regex", "number", 1, 1, [], "2")
|
|
84
87
|
]);
|
|
85
88
|
|
|
86
|
-
expect(result).toEqual(expected)
|
|
87
|
-
expect(cursor.hasError).toBeFalsy()
|
|
89
|
+
expect(result).toEqual(expected);
|
|
90
|
+
expect(cursor.hasError).toBeFalsy();
|
|
91
|
+
expect(cursor.index).toBe(1);
|
|
88
92
|
});
|
|
89
93
|
|
|
90
|
-
test("
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const result = integer.parse(cursor);
|
|
94
|
+
test("Finite Repeat Get Tokens", () => {
|
|
95
|
+
const number = new Literal("number", "1");
|
|
96
|
+
const repeat = new Repeat("numbers", number);
|
|
97
|
+
const numberClone = repeat.find(p => p.name === "number") as Pattern;
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
+
let tokens = repeat.getTokens();
|
|
100
|
+
let expected = ["1"];
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
const a = new Literal("a", "A");
|
|
102
|
-
const manyA = new Repeat("number", a);
|
|
103
|
-
const tokens = manyA.getTokens();
|
|
104
|
-
const expected = ["A"];
|
|
102
|
+
expect(tokens).toEqual(expected);
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
tokens = repeat.getNextTokens();
|
|
105
|
+
expected = [];
|
|
106
|
+
|
|
107
|
+
expect(tokens).toEqual(expected);
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const manyA = new Repeat("many-a", a);
|
|
112
|
-
const tokens = manyA.getTokensAfter(new Literal("bogus", "bogus"));
|
|
113
|
-
const expected: string[] = [];
|
|
109
|
+
tokens = repeat.getTokensAfter(numberClone);
|
|
110
|
+
expected = [];
|
|
114
111
|
|
|
115
|
-
expect(tokens).toEqual(expected)
|
|
112
|
+
expect(tokens).toEqual(expected);
|
|
116
113
|
});
|
|
117
114
|
|
|
118
|
-
test("Get Tokens After
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
115
|
+
test("Get Tokens After", () => {
|
|
116
|
+
const number = new Literal("number", "1");
|
|
117
|
+
const repeat = new Repeat("numbers", number);
|
|
118
|
+
const parent = new And("parent", [repeat, new Literal("b", "B")]);
|
|
119
|
+
const numberClone = parent.find(p => p.name === "number") as Pattern;
|
|
120
|
+
const repeatClone = parent.children[0];
|
|
124
121
|
|
|
125
|
-
|
|
126
|
-
let
|
|
127
|
-
|
|
122
|
+
let tokens = repeatClone.getTokensAfter(numberClone);
|
|
123
|
+
let expected = ["B"];
|
|
124
|
+
|
|
125
|
+
expect(tokens).toEqual(expected);
|
|
126
|
+
});
|
|
128
127
|
|
|
129
|
-
|
|
128
|
+
test("Get Next Tokens", () => {
|
|
129
|
+
const number = new Literal("number", "1");
|
|
130
|
+
const repeat = new Repeat("numbers", number);
|
|
131
|
+
const parent = new And("parent", [repeat, new Literal("b", "B")]);
|
|
132
|
+
const repeatClone = parent.children[0];
|
|
130
133
|
|
|
131
|
-
tokens =
|
|
132
|
-
expected = ["
|
|
134
|
+
let tokens = repeatClone.getNextTokens();
|
|
135
|
+
let expected = ["B"];
|
|
133
136
|
|
|
134
|
-
expect(tokens).toEqual(expected)
|
|
137
|
+
expect(tokens).toEqual(expected);
|
|
135
138
|
});
|
|
136
139
|
|
|
137
|
-
test("Get
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
140
|
+
test("Get Next Patterns", () => {
|
|
141
|
+
const number = new Literal("number", "1");
|
|
142
|
+
const repeat = new Repeat("numbers", number);
|
|
143
|
+
const parent = new And("parent", [repeat, new Literal("b", "B")]);
|
|
144
|
+
const repeatClone = parent.children[0];
|
|
145
|
+
const bClone = parent.find(p => p.name === "b") as Pattern;
|
|
142
146
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const expected = ["A", "B"];
|
|
147
|
+
let patterns = repeatClone.getNextPatterns();
|
|
148
|
+
let expected = [bClone];
|
|
146
149
|
|
|
147
|
-
expect(
|
|
150
|
+
expect(patterns).toEqual(expected);
|
|
148
151
|
});
|
|
149
152
|
|
|
150
|
-
test("
|
|
151
|
-
const
|
|
153
|
+
test("Repeat Get Patterns", () => {
|
|
154
|
+
const number = new Literal("number", "1");
|
|
155
|
+
const repeat = new Repeat("numbers", number);
|
|
156
|
+
const numberClone = repeat.find(p => p.name === "number") as Pattern;
|
|
152
157
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
expect(integer.isOptional).toBeFalsy()
|
|
156
|
-
expect(integer.parent).toBeNull();
|
|
157
|
-
expect(integer.children[0].name).toBe("digit");
|
|
158
|
-
});
|
|
158
|
+
let patterns = repeat.getPatterns();
|
|
159
|
+
let expected = [numberClone];
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
const integer = new Repeat("integer", new Regex("digit", "\\d"));
|
|
162
|
-
const { ast: result } = integer.exec("B");
|
|
163
|
-
expect(result).toBeNull()
|
|
164
|
-
});
|
|
161
|
+
expect(patterns).toEqual(expected);
|
|
165
162
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const result = integer.test("1");
|
|
169
|
-
expect(result).toBeTruthy()
|
|
170
|
-
});
|
|
163
|
+
patterns = repeat.getNextPatterns();
|
|
164
|
+
expected = [];
|
|
171
165
|
|
|
172
|
-
|
|
173
|
-
const integer = new Repeat("integer", new Regex("digit", "\\d"));
|
|
174
|
-
const result = integer.test("b");
|
|
175
|
-
expect(result).toBeFalsy()
|
|
176
|
-
});
|
|
166
|
+
expect(patterns).toEqual(expected);
|
|
177
167
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const parent = new And("parent", [integer, new Literal("pow", "!")]);
|
|
181
|
-
const integerClone = parent.findPattern(p => p.name === "integer") as Pattern;
|
|
182
|
-
const tokens = integerClone.getNextTokens();
|
|
168
|
+
patterns = repeat.getPatternsAfter(numberClone);
|
|
169
|
+
expected = [];
|
|
183
170
|
|
|
184
|
-
expect(
|
|
171
|
+
expect(patterns).toEqual(expected);
|
|
185
172
|
});
|
|
186
173
|
|
|
187
|
-
test("
|
|
188
|
-
const
|
|
189
|
-
const
|
|
174
|
+
test("Repeat Properties", () => {
|
|
175
|
+
const number = new Literal("number", "1");
|
|
176
|
+
const repeat = new Repeat("numbers", number);
|
|
190
177
|
|
|
191
|
-
expect(
|
|
178
|
+
expect(repeat.type).toBe("infinite-repeat");
|
|
179
|
+
expect(repeat.name).toBe("numbers");
|
|
180
|
+
expect(repeat.parent).toBeNull();
|
|
181
|
+
expect(repeat.isOptional).toBeFalsy();
|
|
192
182
|
});
|
|
193
183
|
|
|
194
|
-
test("
|
|
195
|
-
const
|
|
196
|
-
const
|
|
184
|
+
test("test", () => {
|
|
185
|
+
const number = new Literal("number", "1");
|
|
186
|
+
const repeat = new Repeat("numbers", number);
|
|
187
|
+
let result = repeat.test("1");
|
|
188
|
+
let expected = true;
|
|
197
189
|
|
|
198
|
-
expect(
|
|
199
|
-
});
|
|
190
|
+
expect(result).toBe(expected);
|
|
200
191
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const powClone = parent.findPattern(p => p.name === "pow") as Pattern;
|
|
206
|
-
const patterns = integerClone.getNextPatterns();
|
|
207
|
-
|
|
208
|
-
expect(patterns.length).toBe(1);
|
|
209
|
-
expect(patterns[0]).toBe(powClone);
|
|
192
|
+
result = repeat.test("g");
|
|
193
|
+
expected = false;
|
|
194
|
+
|
|
195
|
+
expect(result).toBe(expected);
|
|
210
196
|
});
|
|
211
197
|
|
|
212
|
-
test("
|
|
213
|
-
const
|
|
214
|
-
const
|
|
198
|
+
test("Repeat Clone", () => {
|
|
199
|
+
const number = new Literal("number", "1");
|
|
200
|
+
const repeat = new Repeat("numbers", number);
|
|
201
|
+
|
|
202
|
+
let repeatClone = repeat.clone();
|
|
203
|
+
let expected = new Repeat("numbers", number);
|
|
204
|
+
|
|
205
|
+
expect(repeatClone).toEqual(expected);
|
|
206
|
+
|
|
207
|
+
repeatClone = repeat.clone("new-name");
|
|
208
|
+
expected = new Repeat("new-name", number);
|
|
209
|
+
|
|
210
|
+
expect(repeatClone).toEqual(expected);
|
|
211
|
+
|
|
212
|
+
repeatClone = repeat.clone("new-name", false);
|
|
213
|
+
expected = new Repeat("new-name", number);
|
|
214
|
+
|
|
215
|
+
expect(repeatClone).toEqual(expected);
|
|
216
|
+
|
|
217
|
+
repeatClone = repeat.clone("new-name", true);
|
|
218
|
+
expected = new Repeat("new-name", number, { min: 0 });
|
|
215
219
|
|
|
216
|
-
expect(
|
|
220
|
+
expect(repeatClone).toEqual(expected);
|
|
217
221
|
});
|
|
218
222
|
});
|