unicoderegexp
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -25,2 +25,29 @@ (function (root, factory) { | ||
var unicodePackageNamesMapping = { | ||
L: unicodeRegExp.letter, | ||
M: unicodeRegExp.mark, | ||
N: unicodeRegExp.number, | ||
P: unicodeRegExp.punctuation, | ||
S: unicodeRegExp.symbol, | ||
Z: unicodeRegExp.separator, | ||
C: unicodeRegExp.other, | ||
letter: unicodeRegExp.letter, | ||
mark: unicodeRegExp.mark, | ||
number: unicodeRegExp.number, | ||
digit: unicodeRegExp.number, | ||
punctuation: unicodeRegExp.punctuation, | ||
symbol: unicodeRegExp.symbol, | ||
separator: unicodeRegExp.separator, | ||
other: unicodeRegExp.other | ||
}; | ||
unicodeRegExp.unicodePackageNameRegExp = new RegExp('^\\[\\:(\\^)?(' + Object.keys(unicodePackageNamesMapping).join('|') + ')\\:\\]$'); | ||
unicodeRegExp.expandCldrUnicodeSetIdToCharacterClass = function (unicodeSetId) { | ||
return new RegExp(unicodeSetId.replace(unicodeRegExp.unicodePackageNameRegExp, function ($0, negated, packageName) { | ||
var characters = unicodePackageNamesMapping[packageName].source; | ||
return '[' + (negated ? '^' + characters : characters) + ']'; | ||
})); | ||
}; | ||
unicodeRegExp.spliceCharacterClassRegExps = function () { // ... | ||
@@ -27,0 +54,0 @@ var args = Array.prototype.slice.call(arguments); |
@@ -16,7 +16,7 @@ { | ||
}, | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "=1.18.0", | ||
"unexpected": "2.1.8", | ||
"mocha": "2.2.5", | ||
"unexpected": "9.6.0", | ||
"xregexp": "=2.0.0" | ||
@@ -23,0 +23,0 @@ }, |
@@ -9,5 +9,5 @@ /*global describe,it*/ | ||
expect.addAssertion('[not] to match all characters in', function (value) { | ||
expect.addAssertion('[not] to match all characters in', function (expect, subject, value) { | ||
for (var i = 0 ; i < value.length ; i += 1) { | ||
this.assert(this.obj.test(value.charAt(i))); | ||
expect(value.charAt(i), '[not] to match', subject); | ||
} | ||
@@ -37,4 +37,4 @@ }); | ||
describe('#removeCharacterFromCharacterClassRegExp()', function () { | ||
expect.addAssertion('[not] to be rewritten to', function (value) { | ||
this.assert(unicodeRegExp.removeCharacterFromCharacterClassRegExp(this.obj[0], this.obj[1]), 'to equal', value); | ||
expect.addAssertion('[not] to be rewritten to', function (expect, subject, value) { | ||
expect(unicodeRegExp.removeCharacterFromCharacterClassRegExp(subject[0], subject[1]), 'to equal', value); | ||
}); | ||
@@ -158,2 +158,24 @@ | ||
}); | ||
describe('expandCldrUnicodeSetIdToCharacterClass', function () { | ||
expect.addAssertion('[not] to be expanded to character class satisfying', function (expect, subject, value) { | ||
expect(unicodeRegExp.expandCldrUnicodeSetIdToCharacterClass(subject).source, 'to equal', '[' + (value[1] ? '^' : '') + value[0].source + ']'); | ||
}); | ||
it('to expand [:S:] to the "symbol" character class, negated', function () { | ||
expect('[:S:]', 'to be expanded to character class satisfying', [unicodeRegExp.symbol]); | ||
}); | ||
it('to expand [:^S:] to the "symbol" character class, negated', function () { | ||
expect('[:^S:]', 'to be expanded to character class satisfying', [unicodeRegExp.symbol, true]); | ||
}); | ||
it('to expand [:digit:] to the "symbol" character class, negated', function () { | ||
expect('[:digit:]', 'to be expanded to character class satisfying', [unicodeRegExp.number]); | ||
}); | ||
it('to expand [:^digit:] to the "symbol" character class, negated', function () { | ||
expect('[:^digit:]', 'to be expanded to character class satisfying', [unicodeRegExp.number, true]); | ||
}); | ||
}); | ||
}); |
26874
320