diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2016-01-23 00:24:57 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2016-01-23 00:24:57 +0100 |
commit | 0858bca9eb30a7544bd1f381d940ade494f43e13 (patch) | |
tree | fb675904974e9ac2b3285b0980d0b86bd20c7dd9 /spec | |
parent | d17bab6bcccc8319b8b4c96db0def8926e93152d (diff) | |
download | svg.js-0858bca9eb30a7544bd1f381d940ade494f43e13.tar.gz svg.js-0858bca9eb30a7544bd1f381d940ade494f43e13.zip |
fixed unit unit regex and renamed it to numberAndUnit, added specs (fix #443)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/regex.js | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/spec/spec/regex.js b/spec/spec/regex.js index 67b03ef..9a14bec 100644 --- a/spec/spec/regex.js +++ b/spec/spec/regex.js @@ -1,23 +1,46 @@ describe('Regex', function() { describe('matchers', function() { - describe('unit', function() { + + describe('numberAndUnit', function() { var match it('is true with a positive unit value', function() { - match = ('10%').match(SVG.regex.unit) + match = ('10%').match(SVG.regex.numberAndUnit) expect(match[1]).toBe('10') - expect(match[2]).toBe('%') + expect(match[5]).toBe('%') }) it('is true with a negative unit value', function() { - match = ('-11%').match(SVG.regex.unit) + match = ('-11%').match(SVG.regex.numberAndUnit) expect(match[1]).toBe('-11') - expect(match[2]).toBe('%') + expect(match[5]).toBe('%') }) it('is false with a positive unit value', function() { - match = ('NotAUnit').match(SVG.regex.unit) + match = ('NotAUnit').match(SVG.regex.numberAndUnit) expect(match).toBeNull() }) + + it('is true with a number', function() { + ["1", "-1", "+15", "1.55", ".5", "5.", "1.3e2", "1E-4", "1e+12"].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeTruthy() + }) + }) + it('is false with a faulty number', function() { + ["+-1", "1.2.3", "1+1", "1e4.5", ".5.", "1f5", "."].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeFalsy() + }) + }) + it('is true with a number with unit', function() { + ["1px", "-1em", "+15%", "1.55s", ".5pt", "5.deg", "1.3e2rad", "1E-4grad", "1e+12cm"].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeTruthy() + }) + }) + it('is false with a faulty number or wrong unit', function() { + ["1em1", "-1eq,5"].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeFalsy() + }) + }) + }) }) @@ -45,7 +68,7 @@ describe('Regex', function() { expect(SVG.regex.isRgb.test('hsb(255, 100, 100)')).toBeFalsy() }) }) - + describe('isNumber', function() { it('is true with a number', function() { @@ -53,15 +76,17 @@ describe('Regex', function() { expect(SVG.regex.isNumber.test(s)).toBeTruthy() }) }) - + it('is false with a faulty number', function() { ["1a", "+-1", "1.2.3", "1+1", "1e4.5", ".5.", "1f5", "."].forEach(function(s) { expect(SVG.regex.isNumber.test(s)).toBeFalsy() }) }) - + }) + + }) })
\ No newline at end of file |