Skip to content

Commit 9f812f9

Browse files
committed
add tests
1 parent 9985ceb commit 9f812f9

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

test/test.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,45 @@ test('character class: range [a-z]', (t) => {
9999
}
100100
});
101101

102-
test('grouping: (ab)+', (t) => {
102+
test('quantifier: {n} (fixed)', (t) => {
103103
for (let i = 0; i < 100; i++) {
104-
const val = String_random(/(ab)+/, { random });
105-
assert.match(val, /^(ab)+$/);
104+
const val = String_random(/a{5}/, { random });
105+
assert.match(val, /^a{5}$/);
106+
assert.strictEqual(val.length, 5);
106107
}
107108
});
108109

109-
test('alternation: a|b', (t) => {
110+
test('throws on invalid bracket', (t) => {
111+
assert.throws(() => {
112+
String_random('[abc', { random });
113+
});
114+
});
115+
116+
test('throws on invalid brace', (t) => {
117+
assert.throws(() => {
118+
String_random('a{2,', { random });
119+
});
120+
});
121+
122+
test('backreference: (a)(b)\\2\\1', (t) => {
110123
for (let i = 0; i < 100; i++) {
111-
const val = String_random(/a|b/, { random });
112-
assert.match(val, /^a$|^b$/);
124+
const val = String_random(/(a)(b)\2\1/, { random });
125+
assert.match(val, /^abba$/);
113126
}
114127
});
115128

129+
test('throws on unsupported regexp: positive lookahead', (t) => {
130+
assert.throws(() => {
131+
String_random(/(?=foo).../, { random });
132+
});
133+
});
134+
135+
test('throws on unsupported regexp: lookbehind', (t) => {
136+
assert.throws(() => {
137+
String_random(/(?<=foo).../, { random });
138+
});
139+
});
140+
116141

117142
const patterns = [
118143
/^$/,

0 commit comments

Comments
 (0)