diff options
author | Freeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace> | 2013-06-25 23:26:50 +1200 |
---|---|---|
committer | Freeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace> | 2013-06-25 23:26:50 +1200 |
commit | 2cf8ba330dc60fa4c269c4fdb16716a1d9ad1e90 (patch) | |
tree | 5f0b36d1e8ebabcd989011ae98d4ed8121caf01b /test/mp/future.js | |
parent | 3953b0496e101e0ecd80672af45abbd63cf3fd1f (diff) | |
download | manaportal-2cf8ba330dc60fa4c269c4fdb16716a1d9ad1e90.tar.gz manaportal-2cf8ba330dc60fa4c269c4fdb16716a1d9ad1e90.tar.bz2 manaportal-2cf8ba330dc60fa4c269c4fdb16716a1d9ad1e90.tar.xz manaportal-2cf8ba330dc60fa4c269c4fdb16716a1d9ad1e90.zip |
Add dye API, canvas loading, future tests
The provisional API generates structured dye data from a dye string, and
dyes an image when provided dyeable image data and the associated dyeing
data.
The splitting of an image URI and the dye string should probably be
handled by a resource manager.
Tests are distinguished between stable tests and future tests.
Stable tests should pass at all times. Future tests should pass once
implemented, and be moved to stable test suites.
To run the future tests as well, run ./todo.sh.
The current logic to load and extract image data should probably be
refactored out from the test file and into some common file or resource
manager file.
Might need a custom assertion function for comparing image data to avoid
flooding the console if something doesn't fully match.
Finally, declare "use strict".
Diffstat (limited to 'test/mp/future.js')
-rw-r--r-- | test/mp/future.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/mp/future.js b/test/mp/future.js new file mode 100644 index 0000000..6f491ae --- /dev/null +++ b/test/mp/future.js @@ -0,0 +1,67 @@ +"use strict"; +var vows = require("vows"), + load = require("../load"), + assert = require("assert"), + jsdom = require("jsdom"), + Canvas = require("canvas"), + Image = Canvas.Image; + +var suite = vows.describe("mp.dye"); + +var canvas = new Canvas(32,32); +var context = canvas.getContext("2d"); + +var dyeString = "R:#ede5b2,fff7bf;G:#cccccc,ffffff"; +var dyeData = { + "R": [ + [0xed, 0xe5, 0xb2], + [0xff, 0xf7, 0xbf] + ], + "G": [ + [0xcc, 0xcc, 0xcc], + [0xff, 0xff, 0xff] + ] +}; + +function loadImage(url, tests) { + tests.topic = function() { + var image = new Image; + var tester = this; + var callback = this.callback; + var args = arguments; + image.onload = function() { + canvas.width = image.width; + canvas.height = image.height; + context.drawImage(image, 0, 0); + callback = callback.bind(tester, false, context.getImageData(0, 0, image.width, image.height)); + callback.apply(tester, args); + } + image.onerror = function(err) { + throw new Error("Error loading '" + url + "': " + err); + } + image.src = url; + }; + return tests; +} + +suite.addBatch({ + "The manaportal dye": { + topic: load("mp/dye").expression("mp.dye").document(), + "parseDyeString": { + "Extracts a the dye channel data from the dyestring": function(dye) { + assert.equal(dye.parseDyeString(dyeString), dyeData); + } + }, + "dyeImage": { + "with the big recolorable cake": loadImage("test/data/bigcake.png", { + "to the big white cake": loadImage("test/data/whitecake.png", { + "dyes correctly when given the correct dye data": function(err1, whiteCake, dyeableCake, dye) { + assert.deepEqual(dye.dyeImage(dyeableCake.data, dyeData), whiteCake.data); + } + }) + }) + } + } +}); + +suite.export(module); |