summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2016-05-05 15:38:21 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2016-05-05 15:38:21 +0200
commit9e14ae8476f0d363cc064ddbb3fa1a954aa309b8 (patch)
treeedd029a7886d3ee9dbecbd88839d6e0f2d3efd63 /spec
parent30df220d96e813e0dab08a08ebb00ba9cfa25352 (diff)
downloadsvg.js-9e14ae8476f0d363cc064ddbb3fa1a954aa309b8.tar.gz
svg.js-9e14ae8476f0d363cc064ddbb3fa1a954aa309b8.zip
fixed bug in `parse()` from `SVG.PathArray` which does not correctly handled `S` and `T` (#485)
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/array.js122
-rw-r--r--spec/spec/element.js2
2 files changed, 64 insertions, 60 deletions
diff --git a/spec/spec/array.js b/spec/spec/array.js
index 05ea837..d027e03 100644
--- a/spec/spec/array.js
+++ b/spec/spec/array.js
@@ -1,77 +1,81 @@
describe('Array', function () {
- var array
+ var array
- it('parses a matrix array correctly to string', function() {
- array = new SVG.Array([ .343, .669, .119, 0, 0
- , .249, -.626, .130, 0, 0
- , .172, .334, .111, 0, 0
- , .000, .000, .000, 1, -0 ])
+ it('parses a matrix array correctly to string', function() {
+ array = new SVG.Array([ .343, .669, .119, 0, 0
+ , .249, -.626, .130, 0, 0
+ , .172, .334, .111, 0, 0
+ , .000, .000, .000, 1, -0 ])
- expect(array + '').toBe('0.343 0.669 0.119 0 0 0.249 -0.626 0.13 0 0 0.172 0.334 0.111 0 0 0 0 0 1 0')
- })
- describe('reverse()', function() {
- it('reverses the array', function() {
- array = new SVG.Array([1 ,2 ,3, 4, 5]).reverse()
- expect(array.value).toEqual([5, 4, 3, 2, 1])
- })
- it('returns itself', function() {
- array = new SVG.Array()
- expect(array.reverse()).toBe(array)
- })
- })
+ expect(array + '').toBe('0.343 0.669 0.119 0 0 0.249 -0.626 0.13 0 0 0.172 0.334 0.111 0 0 0 0 0 1 0')
+ })
+ describe('reverse()', function() {
+ it('reverses the array', function() {
+ array = new SVG.Array([1 ,2 ,3, 4, 5]).reverse()
+ expect(array.value).toEqual([5, 4, 3, 2, 1])
+ })
+ it('returns itself', function() {
+ array = new SVG.Array()
+ expect(array.reverse()).toBe(array)
+ })
+ })
})
describe('PointArray', function () {
- it('parses a string to a point array', function() {
- var array = new SVG.PointArray('0,1 -.05,7.95 1000.0001,-200.222')
+ it('parses a string to a point array', function() {
+ var array = new SVG.PointArray('0,1 -.05,7.95 1000.0001,-200.222')
- expect(array.valueOf()).toEqual([[0, 1], [-0.05, 7.95], [1000.0001, -200.222]])
- })
- it('parses a points array correctly to string', function() {
- var array = new SVG.PointArray([[0,.15], [-100,-3.141592654], [50,100]])
+ expect(array.valueOf()).toEqual([[0, 1], [-0.05, 7.95], [1000.0001, -200.222]])
+ })
+ it('parses a points array correctly to string', function() {
+ var array = new SVG.PointArray([[0,.15], [-100,-3.141592654], [50,100]])
- expect(array + '').toBe('0,0.15 -100,-3.141592654 50,100')
- })
+ expect(array + '').toBe('0,0.15 -100,-3.141592654 50,100')
+ })
})
describe('PathArray', function () {
- var p1, p2, p3
+ var p1, p2, p3
- beforeEach(function() {
- p1 = new SVG.PathArray('m10 10 h 80 v 80 h -80 l 300 400 z')
- p2 = new SVG.PathArray('m10 80 c 40 10 65 10 95 80 s 150 150 180 80 t 300 300 q 52 10 95 80 z')
- p3 = new SVG.PathArray('m80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 z')
- })
+ beforeEach(function() {
+ p1 = new SVG.PathArray('m10 10 h 80 v 80 h -80 l 300 400 z')
+ p2 = new SVG.PathArray('m10 80 c 40 10 65 10 95 80 s 150 150 180 80 t 300 300 q 52 10 95 80 z')
+ p3 = new SVG.PathArray('m80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 z')
+ p4 = new SVG.PathArray('M215.458,245.23c0,0,77.403,0,94.274,0S405,216.451,405,138.054S329.581,15,287.9,15c-41.68,0-139.924,0-170.688,0C86.45,15,15,60.65,15,134.084c0,73.434,96.259,112.137,114.122,112.137C146.984,246.221,215.458,245.23,215.458,245.23z')
- it('converts to absolute values', function() {
- expect(p1.toString()).toBe('M10 10H90V90H10L310 490Z ')
- expect(p2.toString()).toBe('M10 80C50 90 75 90 105 160S255 310 285 240T585 540Q637 550 680 620Z ')
- expect(p3.toString()).toBe('M80 80A45 45 0 0 0 125 125L125 80Z ')
- })
+ })
- describe('move()', function() {
- it('moves all points in a straight path', function() {
- expect(p1.move(100,200).toString()).toBe('M100 200H180V280H100L400 680Z ')
- })
- it('moves all points in a curved path', function() {
- expect(p2.move(100,200).toString()).toBe('M100 200C140 210 165 210 195 280S345 430 375 360T675 660Q727 670 770 740Z ')
- })
- it('moves all points in a arc path', function() {
- expect(p3.move(100,200).toString()).toBe('M100 200A45 45 0 0 0 145 245L145 200Z ')
- })
- })
+ it('converts to absolute values', function() {
+ expect(p1.toString()).toBe('M10 10H90V90H10L310 490Z ')
+ expect(p2.toString()).toBe('M10 80C50 90 75 90 105 160S255 310 285 240T585 540Q637 550 680 620Z ')
+ expect(p3.toString()).toBe('M80 80A45 45 0 0 0 125 125L125 80Z ')
+ expect(p4.toString()).toBe('M215.458 245.23C215.458 245.23 292.861 245.23 309.73199999999997 245.23S405 216.451 405 138.054S329.581 15 287.9 15C246.21999999999997 15 147.97599999999997 15 117.21199999999999 15C86.45 15 15 60.65 15 134.084C15 207.518 111.259 246.221 129.122 246.221C146.984 246.221 215.458 245.23 215.458 245.23Z ')
- describe('size()', function() {
- it('resizes all points in a straight path', function() {
- expect(p1.size(600,200).toString()).toBe('M10 10H170V43.333333333333336H10L610 210Z ')
- })
- it('resizes all points in a curved path', function() {
- expect(p2.size(600,200).toString()).toBe('M10 80C45.82089552238806 83.70370370370371 68.2089552238806 83.70370370370371 95.07462686567165 109.62962962962963S229.40298507462686 165.1851851851852 256.2686567164179 139.25925925925927T524.9253731343283 250.37037037037038Q571.4925373134329 254.07407407407408 610 280Z ')
- })
- it('resizes all points in a arc path', function() {
- expect(p3.size(600,200).toString()).toBe('M80 80A599.9998982747568 199.9999660915856 0 0 0 679.9998982747568 279.99996609158563L679.9998982747568 80Z ')
- })
- })
+ })
+
+ describe('move()', function() {
+ it('moves all points in a straight path', function() {
+ expect(p1.move(100,200).toString()).toBe('M100 200H180V280H100L400 680Z ')
+ })
+ it('moves all points in a curved path', function() {
+ expect(p2.move(100,200).toString()).toBe('M100 200C140 210 165 210 195 280S345 430 375 360T675 660Q727 670 770 740Z ')
+ })
+ it('moves all points in a arc path', function() {
+ expect(p3.move(100,200).toString()).toBe('M100 200A45 45 0 0 0 145 245L145 200Z ')
+ })
+ })
+
+ describe('size()', function() {
+ it('resizes all points in a straight path', function() {
+ expect(p1.size(600,200).toString()).toBe('M10 10H170V43.333333333333336H10L610 210Z ')
+ })
+ it('resizes all points in a curved path', function() {
+ expect(p2.size(600,200).toString()).toBe('M10 80C45.82089552238806 83.70370370370371 68.2089552238806 83.70370370370371 95.07462686567165 109.62962962962963S229.40298507462686 165.1851851851852 256.2686567164179 139.25925925925927T524.9253731343283 250.37037037037038Q571.4925373134329 254.07407407407408 610 280Z ')
+ })
+ it('resizes all points in a arc path', function() {
+ expect(p3.size(600,200).toString()).toBe('M80 80A599.9998982747568 199.9999660915856 0 0 0 679.9998982747568 279.99996609158563L679.9998982747568 80Z ')
+ })
+ })
}) \ No newline at end of file
diff --git a/spec/spec/element.js b/spec/spec/element.js
index 1f96120..fffeed1 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -578,7 +578,7 @@ describe('Element', function() {
it('returns full raw svg when called on the main svg doc', function() {
draw.size(100,100).rect(100,100).id(null)
draw.circle(100).fill('#f06').id(null)
- expect(draw.svg()).toBe('<svg id="SvgjsSvg1000" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="100" height="100"><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></svg>')
+ expect(draw.svg()).toBe('<svg id="SvgjsSvg1001" width="100" height="100" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs"><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></svg>')
})
it('returns partial raw svg when called on a sub group', function() {
var group = draw.group().id(null)