From 8e58084d935166de6c0a63d520b7920218664cfb Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Sun, 17 Mar 2013 14:50:51 +0100 Subject: [PATCH] Add initial set of JSON tests. --- test/tests/JSON.js | 195 +++++++++++++++++++++++++++++++++++++++++++++ test/tests/load.js | 1 + 2 files changed, 196 insertions(+) create mode 100644 test/tests/JSON.js diff --git a/test/tests/JSON.js b/test/tests/JSON.js new file mode 100644 index 00000000..f17d2968 --- /dev/null +++ b/test/tests/JSON.js @@ -0,0 +1,195 @@ +/* + * Paper.js - The Swiss Army Knife of Vector Graphics Scripting. + * http://paperjs.org/ + * + * Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey + * http://lehni.org/ & http://jonathanpuckey.com/ + * + * Distributed under the MIT license. See LICENSE file for details. + * + * All rights reserved. + */ + +module('JSON'); + +test('Circles', function() { + var topLeft = new Point(200, 200); + var size = new Size(150, 100); + var rectangle = new Rectangle(topLeft, size); + var path = new Path.Ellipse(rectangle); + path.fillColor = 'black'; + + var topLeft = new Point(5, 400); + var size = new Size(100, 50); + var rectangle = new Rectangle(topLeft, size); + var path = new Path.Ellipse(rectangle); + path.fillColor = 'yellow'; + + var path = new Path.Circle(new Point(50, 50), 25); + path.fillColor = 'red'; + + testExportImportJson(paper.project); +}); + +test('CompoundPath', function() { + paper.project.currentStyle.fillColor = 'black'; + var path1 = new Path.Rectangle([200, 200], [100, 100]); + var path2 = new Path.Rectangle([50, 50], [200, 200]); + var path3 = new Path.Rectangle([0, 0], [400, 400]); + new CompoundPath(path1, path2, path3); + + testExportImportJson(paper.project); +}); + +test('Empty Path', function() { + new Path(); + testExportImportJson(paper.project); +}); + +test('gradients', function() { + var path = new Path.Circle([100, 100], 40); + var gradient = new RadialGradient('yellow', 'red', 'black'); + var from = path.position; + var to = path.bounds.rightCenter; + var gradientColor = new GradientColor(gradient, from, to); + path.fillColor = gradientColor; + path.strokeColor = 'black'; + testExportImportJson(paper.project); +}); + +test('group transform', function() { + var circle1 = new Path.Circle([100, 100], 50); + circle1.fillColor = 'red'; + var circle2 = new Path.Circle([200, 100], 50); + circle2.fillColor = 'blue'; + var group = new Group(circle1, circle2); + group.translate([100, 100]); + group.scale(0.5); + group.rotate(10); + testExportImportJson(paper.project); +}); + +test('rectangle testing', function() { + var point1 = new Point(10, 10); + var size1 = new Size(50, 50); + var rectangle1 = new Rectangle(point1, size1); + var path1 = new Path.Rectangle(rectangle1); + path1.strokeColor = 'black'; + path1.fillColor = 'red'; + path1.name = 'square1'; + path1.strokeCap = 'square'; + path1.opacity = .1; + path1.dashArray = [5, 2]; + path1.dashOffset = 0; + + var point2 = new Point(75, 75); + var point22 = new Point(100, 100); + var path2 = new Path.Rectangle(point2, point22); + path2.strokeColor = 'red'; + path2.strokeWidth = 4; + path2.fillColor = 'blue'; + path2.name = 'square2'; + path2.strokeCap = 'butt'; + + var point3 = new Point(150, 150); + var size3 = new Size(50, 50); + var rectangle3 = new Rectangle(point3, size3); + var path3 = new Path.Rectangle(rectangle3); + path3.strokeColor = 'blue'; + + var point4 = new Point(200, 200); + var size4 = new Size(100, 100); + var rectangle4 = new Rectangle(point4, size4); + var cornerSize4 = new Size(30, 30); + var path4 = new Path.RoundRectangle(rectangle4, cornerSize4); + path4.strokeColor= 'yellow'; + path4.fillColor='purple'; + testExportImportJson(paper.project); +}); + +test('symbols', function() { + var ellipse = new Path.Ellipse({ + from: [0, 0], + to: [200, 100], + fillColor: 'red' + }); + var symbol = new Symbol(ellipse); + var p1 = symbol.place([100, 100]); + p1.rotate(45); + var p2 = symbol.place([300, 200]); + p2.rotate(-30); + + testExportImportJson(paper.project); +}); + +test('text testing', function() { + var text = new PointText(new Point(50, 100)); + text.fillColor = 'black'; + text.content = 'This is a test'; + + var text = new PointText(new Point(100, 150)); + text.fillColor = 'red'; + text.strokeWidth = '4'; + text.content = 'This is also a test'; + + text.rotate(45); + text.shear(.85, .15); + text.scale(.85, 2); + testExportImportJson(paper.project); +}); + +test('transform test 1', function() { + var circlePath = new Path.Circle(new Point(280, 100), 25); + circlePath.strokeColor = 'black'; + circlePath.fillColor = 'white'; + + var clones = 30; + var angle = 360 / clones; + + for(var i = 0; i < clones; i++) { + var clonedPath = circlePath.clone(); + clonedPath.rotate(angle * i, circlePath.bounds.topLeft); + }; + testExportImportJson(paper.project); +}); + +test('transform test 2', function() { + var path = new Path.Rectangle(new Point(50, 50), new Size(100, 50)); + path.style = { + fillColor: 'white', + strokeColor: 'black' + }; + var copy = path.clone(); + copy.strokeColor = 'red'; + copy.rotate(-45); + copy.scale(0.5); + testExportImportJson(paper.project); +}); + +test('Item#name', function() { + var path = new Path({ + name: 'dave' + }); + testExportImportJson(paper.project); +}); + +test('Item#data', function() { + var path = new Path(); + path.data = { + string: '----', + number: 1234, + array: ['a ray', 'some rays'], + bool: true, + nully: null, + point: new Point(12, 34), + size: new Size(12, 34), + rectangle: new Rectangle([12, 34], [56, 78]), + deep: { + deeper: { + deepest: true + } + } + }; + testExportImportJson(paper.project); +}); + diff --git a/test/tests/load.js b/test/tests/load.js index c0b27c97..a87b4b51 100644 --- a/test/tests/load.js +++ b/test/tests/load.js @@ -43,3 +43,4 @@ /*#*/ include('SvgImport.js'); /*#*/ include('SvgExport.js'); +/*#*/ include('JSON.js'); \ No newline at end of file