Skip to content

Commit 32ed51a

Browse files
committed
Remove @ts-expect-errors that no longer throws error with the new simplified types
1 parent 26cd700 commit 32ed51a

File tree

2 files changed

+1
-67
lines changed

2 files changed

+1
-67
lines changed

test/functions.test.ts

-52
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ describe('exactly', () => {
7474
expect(oneOrMore(exactly('foo')).toString()).toBe('(?:foo)+');
7575
});
7676
it('cannot be negated', () => {
77-
// @ts-expect-error - repeat is not negatable
7877
expect(() => not.exactly`foo`.toString()).toThrow();
79-
// @ts-expect-error - repeat is not negatable
8078
expect(() => not(exactly('foo')).toString()).toThrow();
8179
});
8280
it('throws for invalid argument', () => {
@@ -200,17 +198,14 @@ describe('not', () => {
200198
expect(not.whitespace.not(whitespace).not.whitespace.toString()).toBe('\\S\\S\\S');
201199
});
202200
it('does not allow non-negatable tokens', () => {
203-
// @ts-expect-error - not(char) is not negatable
204201
expect(() => not(char)).toThrow();
205202
});
206203
it('can be quantified', () => {
207204
expect(oneOrMore.not.word.toString()).toBe('\\W+');
208205
expect(oneOrMore(not(word)).toString()).toBe('\\W+');
209206
});
210207
it('cannot be negated', () => {
211-
// @ts-expect-error - repeat is not negatable
212208
expect(() => not.not.word.toString()).toThrow();
213-
// @ts-expect-error - repeat is not negatable
214209
expect(() => not(not(word)).toString()).toThrow();
215210
});
216211
it('throws for invalid argument', () => {
@@ -249,14 +244,11 @@ describe('repeat', () => {
249244
expect(repeat(3, 3)`foo`.toString()).toBe('(?:foo){3}');
250245
});
251246
it('cannot be quantified in dot syntax', () => {
252-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
253247
expect(oneOrMore.repeat(3, 5)`foo`.toString()).toBe('(?:(?:foo){3,5})+');
254248
expect(oneOrMore(repeat(3, 5)`foo`).toString()).toBe('(?:(?:foo){3,5})+');
255249
});
256250
it('cannot be negated', () => {
257-
// @ts-expect-error - repeat is not negatable
258251
expect(() => not.repeat(3, 5)`foo`.toString()).toThrow();
259-
// @ts-expect-error - repeat is not negatable
260252
expect(() => not(repeat(3, 5)`foo`).toString()).toThrow();
261253
});
262254
it('supports lazily', () => {
@@ -302,14 +294,11 @@ describe('atLeast', () => {
302294
expect(atLeast(3).exactly`foo`.toString()).toBe('(?:foo){3,}');
303295
});
304296
it('cannot be quantified in dot syntax', () => {
305-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
306297
expect(oneOrMore.atLeast(3)`foo`.toString()).toBe('(?:(?:foo){3,})+');
307298
expect(oneOrMore(atLeast(3)`foo`).toString()).toBe('(?:(?:foo){3,})+');
308299
});
309300
it('cannot be negated', () => {
310-
// @ts-expect-error - atLeast is not negatable
311301
expect(() => not.atLeast(3)`foo`.toString()).toThrow();
312-
// @ts-expect-error - atLeast is not negatable
313302
expect(() => not(atLeast(3)`foo`).toString()).toThrow();
314303
});
315304
it('supports lazily', () => {
@@ -351,14 +340,11 @@ describe('atMost', () => {
351340
expect(atMost(3).exactly`foo`.toString()).toBe('(?:foo){,3}');
352341
});
353342
it('cannot be quantified in dot syntax', () => {
354-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
355343
expect(oneOrMore.atMost(3)`foo`.toString()).toBe('(?:(?:foo){,3})+');
356344
expect(oneOrMore(atMost(3)`foo`).toString()).toBe('(?:(?:foo){,3})+');
357345
});
358346
it('cannot be negated', () => {
359-
// @ts-expect-error - atMost is not negatable
360347
expect(() => not.atMost(3)`foo`.toString()).toThrow();
361-
// @ts-expect-error - atMost is not negatable
362348
expect(() => not(atMost(3)`foo`).toString()).toThrow();
363349
});
364350
it('supports lazily', () => {
@@ -404,14 +390,11 @@ describe('maybe', () => {
404390
expect(exactly('foo').maybe(exactly('foo')).toString()).toBe('foo(?:foo)?');
405391
});
406392
it('cannot be quantified in dot syntax', () => {
407-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
408393
expect(oneOrMore.maybe`foo`.toString()).toBe('(?:(?:foo)?)+');
409394
expect(oneOrMore(maybe`foo`).toString()).toBe('(?:(?:foo)?)+');
410395
});
411396
it('cannot be negated', () => {
412-
// @ts-expect-error - maybe is not negatable
413397
expect(() => not.maybe`foo`.toString()).toThrow();
414-
// @ts-expect-error - maybe is not negatable
415398
expect(() => not(maybe`foo`).toString()).toThrow();
416399
});
417400
it('supports lazily', () => {
@@ -447,14 +430,11 @@ describe('zeroOrMore', () => {
447430
expect(exactly('foo').zeroOrMore(exactly('foo')).toString()).toBe('foo(?:foo)*');
448431
});
449432
it('cannot be quantified in dot syntax', () => {
450-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
451433
expect(oneOrMore.zeroOrMore`foo`.toString()).toBe('(?:(?:foo)*)+');
452434
expect(oneOrMore(zeroOrMore`foo`).toString()).toBe('(?:(?:foo)*)+');
453435
});
454436
it('cannot be negated', () => {
455-
// @ts-expect-error - zeroOrMore is not negatable
456437
expect(() => not.zeroOrMore`foo`.toString()).toThrow();
457-
// @ts-expect-error - zeroOrMore is not negatable
458438
expect(() => not(zeroOrMore`foo`).toString()).toThrow();
459439
});
460440
it('supports lazily', () => {
@@ -490,14 +470,11 @@ describe('oneOrMore', () => {
490470
expect(exactly('foo').oneOrMore(exactly('foo')).toString()).toBe('foo(?:foo)+');
491471
});
492472
it('cannot be quantified in dot syntax', () => {
493-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
494473
expect(oneOrMore.oneOrMore`foo`.toString()).toBe('(?:(?:foo)+)+');
495474
expect(oneOrMore(oneOrMore`foo`).toString()).toBe('(?:(?:foo)+)+');
496475
});
497476
it('cannot be negated', () => {
498-
// @ts-expect-error - oneOrMore is not negatable
499477
expect(() => not.oneOrMore`foo`.toString()).toThrow();
500-
// @ts-expect-error - oneOrMore is not negatable
501478
expect(() => not(oneOrMore`foo`).toString()).toThrow();
502479
});
503480
it('supports lazily', () => {
@@ -518,13 +495,10 @@ describe('oneOrMore', () => {
518495
describe('lazily', () => {
519496
it('cannot be used alone', () => {
520497
expect(maybe.lazily`bar`.toString()).toBe('(?:bar)??');
521-
// @ts-expect-error - lazily can only be used with a quantifier
522498
expect(() => exactly`foo`.lazily`bar`).toThrow();
523499
});
524500
it('cannot be repeated', () => {
525-
// @ts-expect-error - lazily should only be used once
526501
expect(repeatLazily(3, 5).lazily`foo`.toString()).toBe('(?:foo){3,5}?');
527-
// @ts-expect-error - lazily should only be used once
528502
expect(repeat(3, 5).lazily.lazily`foo`.toString()).toBe('(?:foo){3,5}?');
529503
});
530504
it('throws for invalid argument', () => {
@@ -559,9 +533,7 @@ describe('capture', () => {
559533
expect(oneOrMore(capture`foo`).toString()).toBe('(foo)+');
560534
});
561535
it('cannot be negated', () => {
562-
// @ts-expect-error - capture is not negatable
563536
expect(() => not.capture`foo`.toString()).toThrow();
564-
// @ts-expect-error - capture is not negatable
565537
expect(() => not(capture`foo`).toString()).toThrow();
566538
});
567539
it('throws for invalid argument', () => {
@@ -610,9 +582,7 @@ describe('captureAs', () => {
610582
expect(oneOrMore(captureAs`bar``foo`).toString()).toBe('(?<bar>foo)+');
611583
});
612584
it('cannot be negated', () => {
613-
// @ts-expect-error - captureAs is not negatable
614585
expect(() => not.captureAs`bar``foo`.toString()).toThrow();
615-
// @ts-expect-error - captureAs is not negatable
616586
expect(() => not(captureAs`bar``foo`).toString()).toThrow();
617587
});
618588
it('throws for invalid argument', () => {
@@ -702,9 +672,7 @@ describe('ref', () => {
702672
expect(oneOrMore(ref(12))).toHaveProperty('regExp', '\\12+');
703673
});
704674
it('cannot be negated', () => {
705-
// @ts-expect-error - ref is not negatable
706675
expect(() => not.ref`foo`).toThrow();
707-
// @ts-expect-error - ref is not negatable
708676
expect(() => not(ref`foo`)).toThrow();
709677
});
710678
it('throws for invalid argument', () => {
@@ -737,9 +705,7 @@ describe('group', () => {
737705
expect(oneOrMore(group`foo`).toString()).toBe('(?:foo)+');
738706
});
739707
it('cannot be negated', () => {
740-
// @ts-expect-error - group is not negatable
741708
expect(() => not.group`foo`.toString()).toThrow();
742-
// @ts-expect-error - group is not negatable
743709
expect(() => not(group`foo`).toString()).toThrow();
744710
});
745711
it('throws for invalid argument', () => {
@@ -769,7 +735,6 @@ describe('ahead', () => {
769735
expect(exactly('foo').ahead(exactly('foo')).toString()).toBe('foo(?=foo)');
770736
});
771737
it('can be quantified', () => {
772-
// @ts-expect-error - lookarounds are not quantifiable by themselves
773738
expect(oneOrMore.ahead`foo`.toString()).toBe('(?:(?=foo))+');
774739
expect(oneOrMore(ahead`foo`).toString()).toBe('(?:(?=foo))+');
775740
});
@@ -804,7 +769,6 @@ describe('behind', () => {
804769
expect(exactly('foo').behind(exactly('foo')).toString()).toBe('foo(?<=foo)');
805770
});
806771
it('can be quantified', () => {
807-
// @ts-expect-error - lookarounds are not quantifiable by themselves
808772
expect(oneOrMore.behind`foo`.toString()).toBe('(?:(?<=foo))+');
809773
expect(oneOrMore(behind`foo`).toString()).toBe('(?:(?<=foo))+');
810774
});
@@ -839,14 +803,11 @@ describe('notAhead', () => {
839803
expect(exactly('foo').notAhead(exactly('foo')).toString()).toBe('foo(?!foo)');
840804
});
841805
it('can be quantified', () => {
842-
// @ts-expect-error - lookarounds are not quantifiable by themselves
843806
expect(oneOrMore.notAhead`foo`.toString()).toBe('(?:(?!foo))+');
844807
expect(oneOrMore(notAhead`foo`).toString()).toBe('(?:(?!foo))+');
845808
});
846809
it('cannot be negated', () => {
847-
// @ts-expect-error - notAhead is not negatable
848810
expect(() => not.notAhead`foo`.toString()).toThrow();
849-
// @ts-expect-error - notAhead is not negatable
850811
expect(() => not(notAhead`foo`).toString()).toThrow();
851812
});
852813
it('throws for invalid argument', () => {
@@ -876,14 +837,11 @@ describe('notBehind', () => {
876837
expect(exactly('foo').notBehind(exactly('foo')).toString()).toBe('foo(?<!foo)');
877838
});
878839
it('can be quantified', () => {
879-
// @ts-expect-error - lookarounds are not quantifiable by themselves
880840
expect(oneOrMore.notBehind`foo`.toString()).toBe('(?:(?<!foo))+');
881841
expect(oneOrMore(notBehind`foo`).toString()).toBe('(?:(?<!foo))+');
882842
});
883843
it('cannot be negated', () => {
884-
// @ts-expect-error - notBehind is not negatable
885844
expect(() => not.notBehind`foo`.toString()).toThrow();
886-
// @ts-expect-error - notBehind is not negatable
887845
expect(() => not(notBehind`foo`).toString()).toThrow();
888846
});
889847
it('throws for invalid argument', () => {
@@ -914,9 +872,7 @@ describe('oneOf', () => {
914872
expect(oneOrMore(oneOf`foo``bar``baz`).toString()).toBe('(?:foo|bar|baz)+');
915873
});
916874
it('cannot be negated', () => {
917-
// @ts-expect-error - oneOf is not negatable
918875
expect(() => not.oneOf`foo``bar``baz`.toString()).toThrow();
919-
// @ts-expect-error - oneOf is not negatable
920876
expect(() => not(oneOf`foo``bar``baz`).toString()).toThrow();
921877
});
922878
it('throws for invalid argument', () => {
@@ -938,15 +894,11 @@ describe('match', () => {
938894
expect(oneOrMore.match(exactly`baz`.char).toString()).toBe('(?:baz.)+');
939895
});
940896
it('verifies quantifiers', () => {
941-
// @ts-expect-error - match content is not quantifiable
942897
expect(() => oneOrMore.match(lineStart).toString()).toThrow();
943-
// @ts-expect-error - match content is not quantifiable
944898
expect(() => oneOrMore(match(lineStart)).toString()).toThrow();
945899
});
946900
it('cannot be negated', () => {
947-
// @ts-expect-error - match is not negatable
948901
expect(() => not.match(exactly`foo`).toString()).toThrow();
949-
// @ts-expect-error - match is not negatable
950902
expect(() => not(match(exactly`foo`)).toString()).toThrow();
951903
});
952904
it('throws for invalid argument', () => {
@@ -1023,9 +975,7 @@ describe('notCharIn', () => {
1023975
expect(oneOrMore.notCharIn`abc${unicode`0123`}${unicode`fe3d`}`.toString()).toBe('[^abc\\u0123\\ufe3d]+');
1024976
});
1025977
it('cannot be negated', () => {
1026-
// @ts-expect-error - notCharIn is not negatable
1027978
expect(() => not.notCharIn`abc``A-Z``0-9`.toString()).toThrow();
1028-
// @ts-expect-error - notCharIn is not negatable
1029979
expect(() => not(notCharIn`abc``A-Z``0-9`).toString()).toThrow();
1030980
});
1031981
it('throws for invalid argument', () => {
@@ -1040,8 +990,6 @@ describe('notCharIn', () => {
1040990

1041991
describe('quantifiers', () => {
1042992
it('stacks properly', () => {
1043-
// @ts-expect-error - stacking quantifiers only cause error in dot syntax
1044-
// because the two quantifiers always have the same scope, and is thus redundant
1045993
expect(zeroOrMore.oneOrMore.exactly`foo`.toString()).toBe('(?:(?:foo)+)*');
1046994
expect(zeroOrMore(oneOrMore(exactly`foo`)).toString()).toBe('(?:(?:foo)+)*');
1047995
expect(zeroOrMore(digit.oneOrMore(exactly`foo`)).toString()).toBe('(?:\\d(?:foo)+)*');

test/tokens.test.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const testCases = [
3434
['lineEnd', lineEnd, '$'],
3535
['wordBoundary', wordBoundary, '\\b'],
3636
] as const;
37-
function runTest([name, token, expected]: typeof testCases[number]): void {
37+
function runTest([name, token, expected]: (typeof testCases)[number]): void {
3838
describe(name, () => {
3939
it('works', () => {
4040
expect(token.toString()).toBe(expected);
@@ -90,9 +90,7 @@ describe('negation', () => {
9090
expect(not(wordBoundary).toString()).toBe('\\B');
9191
});
9292
it('is not negatable', () => {
93-
// @ts-expect-error - char is not negatable
9493
expect(() => not.char).toThrow();
95-
// @ts-expect-error - char is not negatable
9694
expect(() => not(char)).toThrow();
9795
});
9896
});
@@ -133,31 +131,19 @@ describe('quantification', () => {
133131
expect(oneOrMore(nullChar).toString()).toBe('\\0+');
134132
});
135133
it('is not quantifiable', () => {
136-
// @ts-expect-error - lineStart is not quantifiable
137134
expect(() => oneOrMore.lineStart).toThrow();
138-
// @ts-expect-error - lineStart is not quantifiable
139135
expect(() => oneOrMore(lineStart)).toThrow();
140-
// @ts-expect-error - lineStart is negated with lookahead, which can technically be quantified but has no effect
141136
expect(oneOrMore.not.lineStart.toString()).toBe('(?:(?!^))+');
142-
// @ts-expect-error - lineStart is negated with lookahead, which can technically be quantified but has no effect
143137
expect(oneOrMore(not(lineStart)).toString()).toBe('(?:(?!^))+');
144138

145-
// @ts-expect-error - lineEnd is not quantifiable
146139
expect(() => oneOrMore.lineEnd).toThrow();
147-
// @ts-expect-error - lineEnd is not quantifiable
148140
expect(() => oneOrMore(lineEnd)).toThrow();
149-
// @ts-expect-error - lineEnd is negated with lookahead, which can technically be quantified but has no effect
150141
expect(oneOrMore.not.lineEnd.toString()).toBe('(?:(?!$))+');
151-
// @ts-expect-error - lineEnd is negated with lookahead, which can technically be quantified but has no effect
152142
expect(oneOrMore(not(lineEnd)).toString()).toBe('(?:(?!$))+');
153143

154-
// @ts-expect-error - wordBoundary is not quantifiable
155144
expect(() => oneOrMore.wordBoundary).toThrow();
156-
// @ts-expect-error - wordBoundary is not quantifiable
157145
expect(() => oneOrMore(wordBoundary)).toThrow();
158-
// @ts-expect-error - wordBoundary is not quantifiable
159146
expect(() => oneOrMore.not.wordBoundary).toThrow();
160-
// @ts-expect-error - wordBoundary is not quantifiable
161147
expect(() => oneOrMore(not(wordBoundary))).toThrow();
162148
});
163149
});

0 commit comments

Comments
 (0)