Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed May 5, 2024
1 parent 5dda108 commit cc3f86f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/constructs/__tests__/unicode.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
buildRegExp,
charClass,
endOfString,
type RegexSequence,
startOfString,
unicodeChar,
unicodeProp,
endOfString,
startOfString,
} from '../../index';

function u(sequence: RegexSequence) {
Expand Down Expand Up @@ -68,6 +69,18 @@ test('`unicodeChar` matching', () => {
expect(u(unicodeChar('😎'.codePointAt(0)!))).toMatchString('\u{1f60e}');
});

test('`unicodeChar` nesting matching', () => {
expect(
u(charClass(unicodeChar('a'.codePointAt(0)!), unicodeChar('ą'.codePointAt(0)!))),
).toMatchString('a');
expect(
u(charClass(unicodeChar('a'.codePointAt(0)!), unicodeChar('ą'.codePointAt(0)!))),
).toMatchString('ą');
expect(
u(charClass(unicodeChar('a'.codePointAt(0)!), unicodeChar('ą'.codePointAt(0)!))),
).not.toMatchString('b');
});

test('`unicodeProp` pattern', () => {
expect(unicodeProp('General_Category', 'Letter')).toEqualRegex(/\p{General_Category=Letter}/);
expect(unicodeProp('Letter')).toEqualRegex(/\p{Letter}/);
Expand Down Expand Up @@ -115,3 +128,9 @@ test('`unicodeProp` matching', () => {
expect(u(unicodeProp('Emoji'))).toMatchString('☝🏼');
expect(u([startOfString, unicodeProp('Emoji'), endOfString])).not.toMatchString('☝🏼');
});

test('`unicodeProp` nesting matching', () => {
expect(u(charClass(unicodeProp('Lowercase'), unicodeProp('White_Space')))).toMatchString('a');
expect(u(charClass(unicodeProp('Lowercase'), unicodeProp('White_Space')))).toMatchString(' ');
expect(u(charClass(unicodeProp('Lowercase'), unicodeProp('White_Space')))).not.toMatchString('A');
});
6 changes: 3 additions & 3 deletions src/constructs/unicode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type CharacterClass, encodeCharacterClass } from './character-class';

/**
* Add a unicode character escape.
* Unicode character escape.
*
* Regex pattern:
* - `\uXXXX`: 4-digit hex escape for code points below 0x10000.
Expand All @@ -26,9 +26,9 @@ export function unicodeChar(codePoint: number): CharacterClass {
}

/**
* Add a unicode character class escape that matches a set of characters specified by a Unicode property.
* Unicode character class escape matching a set of characters specified by a Unicode property.
*
* Regex pattern: `\p{property}` or `\p{Property=Value}`
* Regex pattern: `\p{Property}` or `\p{Property=Value}`
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape
*
* @param prop Unicode property name.
Expand Down

0 comments on commit cc3f86f

Please sign in to comment.