Skip to content

Commit bd764da

Browse files
committed
chore: add tests
1 parent 8406c49 commit bd764da

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { hexColorFinder, hexColorValidator } from '..';
2+
3+
test('hexColorValidator', () => {
4+
expect(hexColorValidator).toMatchString('#ffffff');
5+
expect(hexColorValidator).toMatchString('#000');
6+
7+
expect(hexColorValidator).not.toMatchString('#000 ');
8+
expect(hexColorValidator).not.toMatchString(' #000');
9+
expect(hexColorValidator).not.toMatchString('#0');
10+
expect(hexColorValidator).not.toMatchString('#11');
11+
expect(hexColorValidator).not.toMatchString('#4444');
12+
expect(hexColorValidator).not.toMatchString('#55555');
13+
expect(hexColorValidator).not.toMatchString('#7777777');
14+
});
15+
16+
test('hexColorFinder', () => {
17+
expect(hexColorFinder).toMatchAllGroups('The color is #ffffff', [['#ffffff']]);
18+
expect(hexColorFinder).toMatchAllGroups('The colors are #1, #22, #333, #4444, #55555, #666666', [
19+
['#333'],
20+
['#666666'],
21+
]);
22+
});

src/patterns/hex-color.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { buildRegExp } from '../builders';
2-
import { endOfString, startOfString } from '../constructs/anchors';
2+
import { endOfString, startOfString, wordBoundary } from '../constructs/anchors';
33
import { charClass, charRange, digit } from '../constructs/character-class';
44
import { choiceOf } from '../constructs/choice-of';
55
import { repeat } from '../constructs/repeat';
@@ -14,8 +14,9 @@ export const hexColorFinder = buildRegExp(
1414
repeat(hexDigit, 6), // #rrggbb
1515
repeat(hexDigit, 3), // #rgb
1616
),
17+
wordBoundary,
1718
],
18-
{ ignoreCase: true },
19+
{ ignoreCase: true, global: true },
1920
);
2021

2122
/**

0 commit comments

Comments
 (0)