diff --git a/test/api.js b/test/api.js index 941b813..5841427 100644 --- a/test/api.js +++ b/test/api.js @@ -9,14 +9,14 @@ describe('API', function () { describe('from', function () { it('string', function () { - assert.equal( + assert.strictEqual( svgpath.from('M0 0 L 10 10').scale(2, 2).toString(), 'M0 0L20 20' ); }); it('SvgPath instance', function () { - assert.equal( + assert.strictEqual( svgpath.from(svgpath.from('M0 0 L 10 10').scale(2, 2)).toString(), 'M0 0L20 20' ); @@ -29,14 +29,14 @@ describe('API', function () { describe('toString', function () { it('should not collapse multiple M', function () { - assert.equal( + assert.strictEqual( svgpath('M 10 10 M 10 100 M 100 100 M 100 10 Z').toString(), 'M10 10M10 100M100 100M100 10Z' ); }); it('should not collapse multiple m', function () { - assert.equal( + assert.strictEqual( svgpath('m 10 10 m 10 100 m 100 100 m 100 10 z').toString(), 'M10 10m10 100m100 100m100 10z' ); @@ -45,28 +45,28 @@ describe('API', function () { describe('unshort - cubic', function () { it("shouldn't change full arc", function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 C 20 20, 40 20, 50 10').unshort().toString(), 'M10 10C20 20 40 20 50 10' ); }); it('should reflect control point after full path', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 C 20 20, 40 20, 50 10 S 80 0, 90 10').unshort().toString(), 'M10 10C20 20 40 20 50 10 60 0 80 0 90 10' ); }); it('should copy starting point if not followed by a path', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 S 50 50, 90 10').unshort().toString(), 'M10 10C10 10 50 50 90 10' ); }); it('should handle relative paths', function () { - assert.equal( + assert.strictEqual( svgpath('M30 50 c 10 30, 30 30, 40 0 s 30 -30, 40 0').unshort().toString(), 'M30 50c10 30 30 30 40 0 10-30 30-30 40 0' ); @@ -76,28 +76,28 @@ describe('API', function () { describe('unshort - quadratic', function () { it("shouldn't change full arc", function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 Q 50 50, 90 10').unshort().toString(), 'M10 10Q50 50 90 10' ); }); it('should reflect control point after full path', function () { - assert.equal( + assert.strictEqual( svgpath('M30 50 Q 50 90, 90 50 T 150 50').unshort().toString(), 'M30 50Q50 90 90 50 130 10 150 50' ); }); it('should copy starting point if not followed by a path', function () { - assert.equal( + assert.strictEqual( svgpath('M10 30 T150 50').unshort().toString(), 'M10 30Q10 30 150 50' ); }); it('should handle relative paths', function () { - assert.equal( + assert.strictEqual( svgpath('M30 50 q 20 20, 40 0 t 40 0').unshort().toString(), 'M30 50q20 20 40 0 20-20 40 0' ); @@ -107,49 +107,49 @@ describe('API', function () { describe('abs', function () { it('should convert line', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 l 30 30').abs().toString(), 'M10 10L40 40' ); }); it("shouldn't process existing line", function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 L30 30').abs().toString(), 'M10 10L30 30' ); }); it('should convert multi-segment curve', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 c 10 30 30 30 40, 0 10 -30 20 -30 40 0').abs().toString(), 'M10 10C20 40 40 40 50 10 60-20 70-20 90 10' ); }); it('should handle horizontal lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10H40h50').abs().toString(), 'M10 10H40 90' ); }); it('should handle vertical lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10V40v50').abs().toString(), 'M10 10V40 90' ); }); it('should handle arcs', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').abs().toString(), 'M40 30A20 40-45 0 1 60 80' ); }); it('should track position after z', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 l10 0 l0 10 Z l 0 10 l 10 0 z l-1-1').abs().toString(), 'M10 10L20 10 20 20ZL10 20 20 20ZL9 9' ); @@ -159,49 +159,49 @@ describe('API', function () { describe('rel', function () { it('should convert line', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 L30 30').rel().toString(), 'M10 10l20 20' ); }); it("shouldn't process existing line", function () { - assert.equal( + assert.strictEqual( svgpath('m10 10 l30 30').rel().toString(), 'M10 10l30 30' ); }); it('should convert multi-segment curve', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 C 20 40 40 40 50 10 60 -20 70 -20 90 10').rel().toString(), 'M10 10c10 30 30 30 40 0 10-30 20-30 40 0' ); }); it('should handle horizontal lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10H40h50').rel().toString(), 'M10 10h30 50' ); }); it('should handle vertical lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10V40v50').rel().toString(), 'M10 10v30 50' ); }); it('should handle arcs', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30A20 40 -45 0 1 60 80').rel().toString(), 'M40 30a20 40-45 0 1 20 50' ); }); it('should track position after z', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 L20 10 L20 20 Z L10 20 L20 20 z L9 9').rel().toString(), 'M10 10l10 0 0 10zl0 10 10 0zl-1-1' ); @@ -211,47 +211,47 @@ describe('API', function () { describe('scale', function () { it('should scale abs curve', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 C 20 40 40 40 50 10').scale(2, 1.5).toString(), 'M20 15C40 60 80 60 100 15' ); }); it('should scale rel curve', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 c 10 30 30 30 40 0').scale(2, 1.5).toString(), 'M20 15c20 45 60 45 80 0' ); }); it('second argument defaults to the first', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10l20 30').scale(2).toString(), 'M20 20l40 60' ); }); it('should handle horizontal lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10H40h50').scale(2, 1.5).toString(), 'M20 15H80h100' ); }); it('should handle vertical lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10V40v50').scale(2, 1.5).toString(), 'M20 15V60v75' ); }); it('should handle arcs', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').scale(2, 1.5).round(0).toString(), 'M80 45a72 34 32.04 0 1 40 75' ); - assert.equal( + assert.strictEqual( svgpath('M40 30A20 40 -45 0 1 20 50').scale(2, 1.5).round(0).toString(), 'M80 45A72 34 32.04 0 1 40 75' ); @@ -261,28 +261,28 @@ describe('API', function () { describe('rotate', function () { it('rotate by 90 degrees about point(10, 10)', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10L15 10').rotate(90, 10, 10).round(0).toString(), 'M10 10L10 15' ); }); it('rotate by -90 degrees about point (0,0)', function () { - assert.equal( + assert.strictEqual( svgpath('M0 10L0 20').rotate(-90).round(0).toString(), 'M10 0L20 0' ); }); it('rotate abs arc', function () { - assert.equal( + assert.strictEqual( svgpath('M 100 100 A 90 30 0 1 1 200 200').rotate(45).round(0).toString(), 'M0 141A90 30 45 1 1 0 283' ); }); it('rotate rel arc', function () { - assert.equal( + assert.strictEqual( svgpath('M 100 100 a 90 30 15 1 1 200 200').rotate(20).round(0).toString(), 'M60 128a90 30 35 1 1 119 257' ); @@ -294,7 +294,7 @@ describe('API', function () { // x = x*1 + y*4 + 0 = x + y*4 // y = x*0 + y*1 + 0 = y it('skewX', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5L15 20').skewX(75.96).round(0).toString(), 'M25 5L95 20' ); @@ -304,7 +304,7 @@ describe('API', function () { // x = x*1 + y*0 + 0 = x // y = x*4 + y*1 + 0 = y + x*4 it('skewY', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5L15 20').skewY(75.96).round(0).toString(), 'M5 25L15 80' ); @@ -316,33 +316,33 @@ describe('API', function () { // x = x*1.5 + y/2 + ( absolute ? 10 : 0) // y = x/2 + y*1.5 + ( absolute ? 15 : 0) it('path with absolute segments', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5 C20 30 10 15 30 15').matrix([ 1.5, 0.5, 0.5, 1.5, 10, 15 ]).toString(), 'M20 25C55 70 32.5 42.5 62.5 52.5' ); }); it('path with relative segments', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5 c10 12 10 15 20 30').matrix([ 1.5, 0.5, 0.5, 1.5, 10, 15 ]).toString(), 'M20 25c21 23 22.5 27.5 45 55' ); }); it('no change', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5 C20 30 10 15 30 15').matrix([ 1, 0, 0, 1, 0, 0 ]).toString(), 'M5 5C20 30 10 15 30 15' ); }); it('should handle arcs', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').matrix([ 1.5, 0.5, 0.5, 1.5, 10, 15 ]).round(0).toString(), 'M85 80a80 20 45 0 1 55 85' ); - assert.equal( + assert.strictEqual( svgpath('M40 30A20 40 -45 0 1 20 50').matrix([ 1.5, 0.5, 0.5, 1.5, 10, 15 ]).round(0).toString(), 'M85 80A80 20 45 0 1 65 100' ); @@ -352,21 +352,21 @@ describe('API', function () { describe('combinations', function () { it('scale + translate', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10').scale(2, 3).translate(100, 100).toString(), 'M100 100L120 130 140 130' ); }); it('scale + rotate', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10').scale(2, 3).rotate(90).round(0).toString(), 'M0 0L-30 20-30 40' ); }); it('empty', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10').translate(0).scale(1).rotate(0, 10, 10).round(0).toString(), 'M0 0L10 10 20 10' ); @@ -376,47 +376,47 @@ describe('API', function () { describe('translate', function () { it('should translate abs curve', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 C 20 40 40 40 50 10').translate(5, 15).toString(), 'M15 25C25 55 45 55 55 25' ); }); it('should translate rel curve', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 c 10 30 30 30 40 0').translate(5, 15).toString(), 'M15 25c10 30 30 30 40 0' ); }); it('second argument defaults to zero', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10L20 30').translate(10).toString(), 'M20 10L30 30' ); }); it('should handle horizontal lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10H40h50').translate(10, 15).toString(), 'M20 25H50h50' ); }); it('should handle vertical lines', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10V40v50').translate(10, 15).toString(), 'M20 25V55v50' ); }); it('should handle arcs', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').translate(10, 15).round(0).toString(), 'M50 45a40 20 45 0 1 20 50' ); - assert.equal( + assert.strictEqual( svgpath('M40 30A20 40 -45 0 1 20 50').translate(10, 15).round(0).toString(), 'M50 45A40 20 45 0 1 30 65' ); @@ -426,49 +426,49 @@ describe('API', function () { describe('round', function () { it('should round arcs', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 A12.5 17.5 45.5 0 0 15.5 19.5').round(0).toString(), 'M10 10A13 18 45.5 0 0 16 20' ); }); it('should round curves', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 c 10.12 30.34 30.56 30 40.00 0.12').round(0).toString(), 'M10 10c10 30 31 30 40 0' ); }); it('set precision', function () { - assert.equal( + assert.strictEqual( svgpath('M10.123 10.456L20.4351 30.0000').round(2).toString(), 'M10.12 10.46L20.44 30' ); }); it('should track errors', function () { - assert.equal( + assert.strictEqual( svgpath('M1.2 1.4l1.2 1.4 l1.2 1.4').round(0).toString(), 'M1 1l1 2 2 1' ); }); it('should track errors #2', function () { - assert.equal( + assert.strictEqual( svgpath('M1.2 1.4 H2.4 h1.2 v2.4 h-2.4 V2.4 v-1.2').round(0).toString(), 'M1 1H2h2v3h-3V2v-1' ); }); it('should track errors for contour start', function () { - assert.equal( + assert.strictEqual( svgpath('m0.4 0.2zm0.4 0.2m0.4 0.2m0.4 0.2zm0.4 0.2').round(0).abs().toString(), 'M0 0ZM1 0M1 1M2 1ZM2 1' ); }); it('reset delta error on contour end', function () { - assert.equal( + assert.strictEqual( svgpath('m.1 .1l.3 .3zm.1 .1l.3 .3zm0 0z').round(0).abs().toString(), 'M0 0L0 0ZM0 0L1 1ZM0 0Z' ); @@ -478,21 +478,21 @@ describe('API', function () { describe('unarc', function () { it('almost complete arc gets expanded to 4 curves', function () { - assert.equal( + assert.strictEqual( svgpath('M100 100 A30 50 0 1 1 110 110').unarc().round(0).toString(), 'M100 100C89 83 87 54 96 33 105 12 122 7 136 20 149 33 154 61 147 84 141 108 125 119 110 110' ); }); it('small arc gets expanded to one curve', function () { - assert.equal( + assert.strictEqual( svgpath('M100 100 a30 50 0 0 1 30 30').unarc().round(0).toString(), 'M100 100C113 98 125 110 130 130' ); }); it('unarc a circle', function () { - assert.equal( + assert.strictEqual( svgpath('M 100, 100 m -75, 0 a 75,75 0 1,0 150,0 a 75,75 0 1,0 -150,0').unarc().round(0).toString(), 'M100 100m-75 0C25 141 59 175 100 175 141 175 175 141 175 100 175 59 141 25 100 25 59 25 25 59 25 100' ); @@ -504,7 +504,7 @@ describe('API', function () { // Due to rounding errors, with these exact arguments radicant // will be -9.974659986866641e-17, causing Math.sqrt() of that to be NaN // - assert.equal( + assert.strictEqual( svgpath('M-0.5 0 A 0.09188163040671497 0.011583783896639943 0 0 1 0 0.5').unarc().round(5).toString(), 'M-0.5 0C0.59517-0.01741 1.59491 0.08041 1.73298 0.21848 1.87105 0.35655 1.09517 0.48259 0 0.5' ); @@ -516,7 +516,7 @@ describe('API', function () { // Due to rounding errors this will compute Math.acos(-1.0000000000000002) // and fail when calculating vector between angles // - assert.equal( + assert.strictEqual( svgpath('M-0.07467194809578359 -0.3862391309812665' + 'A1.2618792965076864 0.2013618852943182 90 0 1 -0.7558937461581081 -0.8010219619609416') .unarc().round(5).toString(), @@ -530,12 +530,12 @@ describe('API', function () { // Asked to draw a curve between a point and itself. According to spec, // nothing shall be drawn in this case. // - assert.equal( + assert.strictEqual( svgpath('M100 100A123 456 90 0 1 100 100').unarc().round(0).toString(), 'M100 100L100 100' ); - assert.equal( + assert.strictEqual( svgpath('M100 100a123 456 90 0 1 0 0').unarc().round(0).toString(), 'M100 100l0 0' ); @@ -543,13 +543,13 @@ describe('API', function () { it('radii are zero', function () { // both rx and ry are zero - assert.equal( + assert.strictEqual( svgpath('M100 100A0 0 0 0 1 110 110').unarc().round(0).toString(), 'M100 100L110 110' ); // rx is zero - assert.equal( + assert.strictEqual( svgpath('M100 100A0 100 0 0 1 110 110').unarc().round(0).toString(), 'M100 100L110 110' ); @@ -559,79 +559,79 @@ describe('API', function () { describe('arc transform edge cases', function () { it('replace arcs rx/ry = 0 with lines', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a0 40 -45 0 1 20 50Z M40 30A20 0 -45 0 1 20 50Z').scale(2, 2).toString(), 'M80 60l40 100ZM80 60L40 100Z' ); }); it('drop arcs with end point === start point', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 0 0').scale(2, 2).toString(), 'M80 60l0 0' ); - assert.equal( + assert.strictEqual( svgpath('M40 30A20 40 -45 0 1 40 30').scale(2, 2).toString(), 'M80 60L80 60' ); }); it('to line at scale x|y = 0 ', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').scale(0, 1).toString(), 'M0 30l0 50' ); - assert.equal( + assert.strictEqual( svgpath('M40 30A20 40 -45 0 1 20 50').scale(1, 0).toString(), 'M40 0L20 0' ); }); it('rotate to +/- 90 degree', function () { - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').rotate(90).round(0).toString(), 'M-30 40a20 40 45 0 1-50 20' ); - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').matrix([ 0, 1, -1, 0, 0, 0 ]).round(0).toString(), 'M-30 40a20 40 45 0 1-50 20' ); - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').rotate(-90).round(0).toString(), 'M30-40a20 40 45 0 1 50-20' ); - assert.equal( + assert.strictEqual( svgpath('M40 30a20 40 -45 0 1 20 50').matrix([ 0, -1, 1, 0, 0, 0 ]).round(0).toString(), 'M30-40a20 40 45 0 1 50-20' ); }); it('process circle-like segments', function () { - assert.equal( + assert.strictEqual( svgpath('M50 50A30 30 -45 0 1 100 100').scale(0.5).round(0).toString(), 'M25 25A15 15 0 0 1 50 50' ); }); it('almost zero eigen values', function () { - assert.equal( + assert.strictEqual( svgpath('M148.7 277.9A228.7 113.2 90 1 0 159.3 734.8').translate(10).round(1).toString(), 'M158.7 277.9A228.7 113.2 90 1 0 169.3 734.8' ); }); it('should flip sweep flag if image is flipped', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10A20 15 90 0 1 30 10').scale(1, -1).translate(0, 40).toString(), 'M10 30A20 15 90 0 0 30 30' ); - assert.equal( + assert.strictEqual( svgpath('M10 10A20 15 90 0 1 30 10').scale(-1, -1).translate(40, 40).toString(), 'M30 30A20 15 90 0 1 10 30' ); diff --git a/test/matrix.js b/test/matrix.js index 634f5ba..058c310 100644 --- a/test/matrix.js +++ b/test/matrix.js @@ -12,22 +12,22 @@ describe('Matrix', function () { m = matrix(); m.matrix([ 1, 0, 0, 1, 0, 0 ]); - assert.equal(m.queue.length, 0); + assert.strictEqual(m.queue.length, 0); m.translate(0, 0); - assert.equal(m.queue.length, 0); + assert.strictEqual(m.queue.length, 0); m.scale(1, 1); - assert.equal(m.queue.length, 0); + assert.strictEqual(m.queue.length, 0); m.rotate(0); - assert.equal(m.queue.length, 0); + assert.strictEqual(m.queue.length, 0); m.skewX(0); - assert.equal(m.queue.length, 0); + assert.strictEqual(m.queue.length, 0); m.skewY(0); - assert.equal(m.queue.length, 0); + assert.strictEqual(m.queue.length, 0); }); it('do nothing on empty queue', function () { @@ -44,12 +44,12 @@ describe('Matrix', function () { .toArray(); // Need to round errors prior to compare - assert.equal(+m[0].toFixed(2), 1); - assert.equal(+m[1].toFixed(2), 0); - assert.equal(+m[2].toFixed(2), 0); - assert.equal(+m[3].toFixed(2), 1); - assert.equal(+m[4].toFixed(2), 0); - assert.equal(+m[5].toFixed(2), 0); + assert.strictEqual(+m[0].toFixed(2), 1); + assert.strictEqual(+m[1].toFixed(2), -0); + assert.strictEqual(+m[2].toFixed(2), 0); + assert.strictEqual(+m[3].toFixed(2), 1); + assert.strictEqual(+m[4].toFixed(2), -0); + assert.strictEqual(+m[5].toFixed(2), 0); }); it('cache', function () { diff --git a/test/path_parse.js b/test/path_parse.js index a4f0acd..250d82b 100644 --- a/test/path_parse.js +++ b/test/path_parse.js @@ -15,56 +15,56 @@ describe('Path parse', function () { for (var i = 0; i < batch.length; i++) { if (!batch[i]) { continue; } - assert.equal(batch[i], svgpath(batch[i]).toString()); + assert.strictEqual(batch[i], svgpath(batch[i]).toString()); } }); it('empty string', function () { - assert.equal(svgpath('').toString(), ''); + assert.strictEqual(svgpath('').toString(), ''); }); it('line terminators', function () { - assert.equal(svgpath('M0\r 0\n\u1680l2-3\nz').toString(), 'M0 0l2-3z'); + assert.strictEqual(svgpath('M0\r 0\n\u1680l2-3\nz').toString(), 'M0 0l2-3z'); }); it('params formats', function () { - assert.equal(svgpath('M 0.0 0.0').toString(), 'M0 0'); - assert.equal(svgpath('M 1e2 0').toString(), 'M100 0'); - assert.equal(svgpath('M 1e+2 0').toString(), 'M100 0'); - assert.equal(svgpath('M +1e+2 0').toString(), 'M100 0'); - assert.equal(svgpath('M 1e-2 0').toString(), 'M0.01 0'); - assert.equal(svgpath('M 0.1e-2 0').toString(), 'M0.001 0'); - assert.equal(svgpath('M .1e-2 0').toString(), 'M0.001 0'); + assert.strictEqual(svgpath('M 0.0 0.0').toString(), 'M0 0'); + assert.strictEqual(svgpath('M 1e2 0').toString(), 'M100 0'); + assert.strictEqual(svgpath('M 1e+2 0').toString(), 'M100 0'); + assert.strictEqual(svgpath('M +1e+2 0').toString(), 'M100 0'); + assert.strictEqual(svgpath('M 1e-2 0').toString(), 'M0.01 0'); + assert.strictEqual(svgpath('M 0.1e-2 0').toString(), 'M0.001 0'); + assert.strictEqual(svgpath('M .1e-2 0').toString(), 'M0.001 0'); }); it('repeated', function () { - assert.equal(svgpath('M 0 0 100 100').toString(), 'M0 0L100 100'); - assert.equal(svgpath('m 0 0 100 100').toString(), 'M0 0l100 100'); - assert.equal(svgpath('M 0 0 R 1 1 2 2').toString(), 'M0 0R1 1 2 2'); - assert.equal(svgpath('M 0 0 r 1 1 2 2').toString(), 'M0 0r1 1 2 2'); + assert.strictEqual(svgpath('M 0 0 100 100').toString(), 'M0 0L100 100'); + assert.strictEqual(svgpath('m 0 0 100 100').toString(), 'M0 0l100 100'); + assert.strictEqual(svgpath('M 0 0 R 1 1 2 2').toString(), 'M0 0R1 1 2 2'); + assert.strictEqual(svgpath('M 0 0 r 1 1 2 2').toString(), 'M0 0r1 1 2 2'); }); it('arc flags', function () { - assert.equal( + assert.strictEqual( svgpath('M 0 0 a.625.625 0 01.84-.925').toString(), 'M0 0a0.625 0.625 0 0 1 0.84-0.925' ); }); it('errors', function () { - assert.equal(svgpath('0').err, 'SvgPath: bad command 0 (at pos 0)'); - assert.equal(svgpath('U').err, 'SvgPath: bad command U (at pos 0)'); - assert.equal(svgpath('M0 0G 1').err, 'SvgPath: bad command G (at pos 4)'); - assert.equal(svgpath('z').err, 'SvgPath: string should start with `M` or `m`'); - assert.equal(svgpath('M+').err, 'SvgPath: param should start with 0..9 or `.` (at pos 2)'); - assert.equal(svgpath('M00').err, 'SvgPath: numbers started with `0` such as `09` are illegal (at pos 1)'); - assert.equal(svgpath('M0e').err, 'SvgPath: invalid float exponent (at pos 3)'); - assert.equal(svgpath('M0').err, 'SvgPath: missed param (at pos 2)'); - assert.equal(svgpath('M0,0,').err, 'SvgPath: missed param (at pos 5)'); - assert.equal(svgpath('M0 .e3').err, 'SvgPath: invalid float exponent (at pos 4)'); - assert.equal(svgpath('M0 0a2 2 2 2 2 2 2').err, 'SvgPath: arc flag can be 0 or 1 only (at pos 11)'); + assert.strictEqual(svgpath('0').err, 'SvgPath: bad command 0 (at pos 0)'); + assert.strictEqual(svgpath('U').err, 'SvgPath: bad command U (at pos 0)'); + assert.strictEqual(svgpath('M0 0G 1').err, 'SvgPath: bad command G (at pos 4)'); + assert.strictEqual(svgpath('z').err, 'SvgPath: string should start with `M` or `m`'); + assert.strictEqual(svgpath('M+').err, 'SvgPath: param should start with 0..9 or `.` (at pos 2)'); + assert.strictEqual(svgpath('M00').err, 'SvgPath: numbers started with `0` such as `09` are illegal (at pos 1)'); + assert.strictEqual(svgpath('M0e').err, 'SvgPath: invalid float exponent (at pos 3)'); + assert.strictEqual(svgpath('M0').err, 'SvgPath: missed param (at pos 2)'); + assert.strictEqual(svgpath('M0,0,').err, 'SvgPath: missed param (at pos 5)'); + assert.strictEqual(svgpath('M0 .e3').err, 'SvgPath: invalid float exponent (at pos 4)'); + assert.strictEqual(svgpath('M0 0a2 2 2 2 2 2 2').err, 'SvgPath: arc flag can be 0 or 1 only (at pos 11)'); }); }); diff --git a/test/transform.js b/test/transform.js index 904dd12..b5a1542 100644 --- a/test/transform.js +++ b/test/transform.js @@ -9,27 +9,27 @@ describe('Transform', function () { describe('translate', function () { it('x only', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 L15 15').transform('translate(20)').toString(), 'M30 10L35 15' ); }); it('x and y', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 L15 15').transform('translate(20,10)').toString(), 'M30 20L35 25'); }); it('x and y with relatives curves', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 c15 15, 20 10, 15 15').transform('translate(20,10)').toString(), 'M30 20c15 15 20 10 15 15' ); }); it('x and y with absolute curves', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10 C15 15, 20 10, 15 15').transform('translate(20,10)').toString(), 'M30 20C35 25 40 20 35 25' ); @@ -38,12 +38,12 @@ describe('Transform', function () { it('rel after translate sequence should not break translate if first m (#10)', function () { var p = 'm70 70 l20 20 l-20 0 l0 -20'; - assert.equal( + assert.strictEqual( svgpath(p).translate(100, 100).toString(), 'M170 170l20 20-20 0 0-20' ); - assert.equal( + assert.strictEqual( svgpath(p).translate(100, 100).rel().toString(), 'M170 170l20 20-20 0 0-20' ); @@ -53,14 +53,14 @@ describe('Transform', function () { describe('rotate', function () { it('rotate by 90 degrees about point(10, 10)', function () { - assert.equal( + assert.strictEqual( svgpath('M10 10L15 10').transform('rotate(90, 10, 10)').round(0).toString(), 'M10 10L10 15' ); }); it('rotate by -90 degrees about point (0,0)', function () { - assert.equal( + assert.strictEqual( svgpath('M0 10L0 20').transform('rotate(-90)').round(0).toString(), 'M10 0L20 0' ); @@ -70,21 +70,21 @@ describe('Transform', function () { describe('scale', function () { it('scale picture by 2', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5L15 20').transform('scale(2)').toString(), 'M10 10L30 40' ); }); it('scale picture with x*0.5 and y*1.5', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5L30 20').transform('scale(.5, 1.5)').toString(), 'M2.5 7.5L15 30' ); }); it('scale picture with x*0.5 and y*1.5 with relative elements', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5c15 15, 20 10, 15 15').transform('scale(.5, 1.5)').toString(), 'M2.5 7.5c7.5 22.5 10 15 7.5 22.5' ); @@ -97,7 +97,7 @@ describe('Transform', function () { // x = x*1 + y*4 + 0 = x + y*4 // y = x*0 + y*1 + 0 = y it('skewX', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5L15 20').transform('skewX(75.96)').round(0).toString(), 'M25 5L95 20' ); @@ -107,7 +107,7 @@ describe('Transform', function () { // x = x*1 + y*0 + 0 = x // y = x*4 + y*1 + 0 = y + x*4 it('skewY', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5L15 20').transform('skewY(75.96)').round(0).toString(), 'M5 25L15 80' ); @@ -119,14 +119,14 @@ describe('Transform', function () { // x = x*1.5 + y/2 + ( absolute ? 10 : 0) // y = x/2 + y*1.5 + ( absolute ? 15 : 0) it('path with absolute segments', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5 C20 30 10 15 30 15').transform('matrix(1.5, 0.5, 0.5, 1.5 10, 15)').toString(), 'M20 25C55 70 32.5 42.5 62.5 52.5' ); }); it('path with relative segments', function () { - assert.equal( + assert.strictEqual( svgpath('M5 5 c10 12 10 15 20 30').transform('matrix(1.5, 0.5, 0.5, 1.5 10, 15)').toString(), 'M20 25c21 23 22.5 27.5 45 55' ); @@ -136,21 +136,21 @@ describe('Transform', function () { describe('combinations', function () { it('scale + translate', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10').transform('translate(100,100) scale(2,3)').toString(), 'M100 100L120 130 140 130' ); }); it('scale + rotate', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10').transform('rotate(90) scale(2,3)').round(0).toString(), 'M0 0L-30 20-30 40' ); }); it('rotate + skewX', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10').transform('skewX(75.96) scale(2,3)').round(0).toString(), 'M0 0L140 30 160 30' ); @@ -160,7 +160,7 @@ describe('Transform', function () { describe('misc', function () { it('empty transforms', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10') .transform('rotate(0) scale(1,1) translate(0,0) skewX(0) skewY(0)') .round(0) @@ -170,7 +170,7 @@ describe('Transform', function () { }); it('wrong params count in transforms', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 L 10 10 20 10') .transform('rotate(10,0) scale(10,10,1) translate(10,10,0) skewX(10,0) skewY(10,0) matrix(0)') .round(0) @@ -180,7 +180,7 @@ describe('Transform', function () { }); it('segment replacement [H,V] => L', function () { - assert.equal( + assert.strictEqual( svgpath('M0 0 H 10 V 10 Z M 100 100 h 15 v -10').transform('rotate(45)').round(0).toString(), 'M0 0L7 7 0 14ZM0 141l11 11 7-7' ); @@ -188,7 +188,7 @@ describe('Transform', function () { it('nothing to transform', function () { // coverage - assert.equal( + assert.strictEqual( svgpath('M10 10 L15 15').transform(' ').toString(), 'M10 10L15 15' ); @@ -199,7 +199,7 @@ describe('Transform', function () { // By default parser force first 'm' to upper case // and we don't fall into troubles. - assert.equal( + assert.strictEqual( p.translate(100, 100).toString(), 'M170 170l70 70' ); @@ -208,7 +208,7 @@ describe('Transform', function () { p = svgpath('m70 70 70 70'); p.segments[0][0] = 'm'; - assert.equal( + assert.strictEqual( p.translate(100, 100).toString(), 'm170 170l70 70' );