Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from martialblog/update-regex
Browse files Browse the repository at this point in the history
Add accented characters to regex
  • Loading branch information
martialblog committed Feb 20, 2018
2 parents 115b61a + 4c4b9e8 commit 5d00875
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ module.exports = function (input) {
// TODO: We could reuse one RegExp
if (str.startsWith('{')) {
// Lemma
valid = /{[a-z0-9]+}/.test(str);
valid = /{[a-z0-9À-ÿ]+}/.test(str);
} else if (/_{/.test(str)) {
// Wildcard or Literal with simple POS
valid = /(^[A-Za-z0-9,\(\)\[\]\?\+\*\\]+(:d)?)?_{[A-Z$]+}$/.test(str);
valid = /(^[A-Za-z0-9À-ÿ,\(\)\[\]\?\+\*\\]+(:d)?)?_{[A-Z$]+}$/.test(str);
} else if (/_[A-Z]/.test(str)) {
// Wildcard or Literal with POS
valid = /(^[A-Za-z0-9,\(\)\[\]\?\+\*\\]+(:d)?)?_[A-Z0-9,\[\]\+\*]+$/.test(str);
valid = /(^[A-Za-z0-9À-ÿ,\(\)\[\]\?\+\*\\]+(:d)?)?_[A-Z0-9,\[\]\+\*]+$/.test(str);
} else {
// Wildcard or Literal
valid = /^[A-Za-z0-9,\(\)\[\]\?\+\*\\]+(:d)?/.test(str);
valid = /^[A-Za-z0-9À-ÿ,\(\)\[\]\?\+\*\\]+(:d)?/.test(str);
}

return valid;
Expand Down
13 changes: 13 additions & 0 deletions test/validate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ test('Testing parentheses mismatch', () => {
expect(validate(')')).toBe(false);
});

test('Testing :d modifier', () => {
expect(validate('foo:d')).toBe(true);
expect(validate('fóó:d')).toBe(true);
expect(validate('foo:d_BAR')).toBe(true);
expect(validate('foobar:d_{BARFOO}')).toBe(true);
});

test('Testing validate lemma', () => {
expect(validate('{lemma}')).toBe(true);
expect(validate('{123}')).toBe(true);
expect(validate('{áéú}')).toBe(true);

expect(validate('{}')).toBe(false);
expect(validate('{lemma_}')).toBe(false);
Expand All @@ -35,6 +43,8 @@ test('Testing validate POS', () => {
expect(validate('great_RESP_')).toBe(false);
expect(validate('_onsability')).toBe(false);
expect(validate('_')).toBe(false);

expect(validate('áéú_BLA')).toBe(true);
});

test('Testing validate simple POS', () => {
Expand All @@ -47,6 +57,8 @@ test('Testing validate simple POS', () => {
expect(validate('_{}')).toBe(false);
expect(validate('_{P?S}')).toBe(false);
expect(validate('_{P*S}')).toBe(false);

expect(validate('áéú_{SIMPLE}')).toBe(true);
});

test('Testing validate literal-wildcards', () => {
Expand All @@ -55,6 +67,7 @@ test('Testing validate literal-wildcards', () => {
expect(validate('[alan,rickman]')).toBe(true);
expect(validate('john:d')).toBe(true);
expect(validate('McCl4n3')).toBe(true);
expect(validate('áéú')).toBe(true);

expect(validate('')).toBe(false);
});

0 comments on commit 5d00875

Please sign in to comment.