summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace>2013-06-25 16:42:25 +1200
committerFreeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace>2013-06-25 16:42:25 +1200
commit3953b0496e101e0ecd80672af45abbd63cf3fd1f (patch)
treea63e9531c0c0964e300e775fa43bf545f6175c10 /test
parentb12ce0d15654fbb73d531dc862121f77f9858217 (diff)
downloadmanaportal-3953b0496e101e0ecd80672af45abbd63cf3fd1f.tar.gz
manaportal-3953b0496e101e0ecd80672af45abbd63cf3fd1f.tar.bz2
manaportal-3953b0496e101e0ecd80672af45abbd63cf3fd1f.tar.xz
manaportal-3953b0496e101e0ecd80672af45abbd63cf3fd1f.zip
Add Jaxad's dye channel detection
Set up tests
Diffstat (limited to 'test')
-rw-r--r--test/load.js44
-rw-r--r--test/mp/dye.js52
2 files changed, 96 insertions, 0 deletions
diff --git a/test/load.js b/test/load.js
new file mode 100644
index 0000000..d04c647
--- /dev/null
+++ b/test/load.js
@@ -0,0 +1,44 @@
+process.env.TZ = "UTC";
+
+var smash = require("smash"),
+ jsdom = require("jsdom");
+
+module.exports = function() {
+ var files = [].slice.call(arguments).map(function(d) { return "public/js/" + d; }),
+ expression = "mp",
+ sandbox = {};
+
+ function topic() {
+ smash.load(files, expression, sandbox, this.callback);
+ }
+
+ topic.expression = function(_) {
+ expression = _;
+ return topic;
+ };
+
+ topic.document = function(_) {
+ var document = jsdom.jsdom("<html><head></head><body></body></html>");
+
+ document.createRange = function() {
+ return {
+ selectNode: function() {},
+ createContextualFragment: jsdom.jsdom
+ };
+ };
+
+ sandbox = {
+ console: console,
+ document: document,
+ window: document.createWindow(),
+ };
+
+ return topic;
+ };
+
+ return topic;
+};
+
+process.on("uncaughtException", function(e) {
+ console.trace(e.stack);
+});
diff --git a/test/mp/dye.js b/test/mp/dye.js
new file mode 100644
index 0000000..a4819ae
--- /dev/null
+++ b/test/mp/dye.js
@@ -0,0 +1,52 @@
+var vows = require("vows"),
+ load = require("../load"),
+ assert = require("assert");
+
+var suite = vows.describe("mp.dye");
+
+suite.addBatch({
+ "The manaportal dye": {
+ topic: load("mp/dye").expression("mp.dye"),
+ "getChannel": {
+ topic: function(dye) { return dye.getChannel; },
+ "returns null given pure black": function(f) {
+ assert.equal(f([0,0,0]).channel, null);
+ },
+ "returns R given a pure red": function(f) {
+ assert.equal(f([255,0,0]).channel, "R");
+ assert.equal(f([12,0,0]).channel, "R");
+ },
+ "returns G given a pure green": function(f) {
+ assert.equal(f([0,255,0]).channel, "G");
+ assert.equal(f([0,50,0]).channel, "G");
+ },
+ "returns B given a pure blue": function (f) {
+ assert.equal(f([0,0,255]).channel, "B");
+ assert.equal(f([0,0,23]).channel, "B");
+ },
+ "returns C given a pure cyan": function (f) {
+ assert.equal(f([0,255,255]).channel, "C");
+ assert.equal(f([0,90,90]).channel, "C");
+ },
+ "returns M given a pure magenta": function (f) {
+ assert.equal(f([255,0,255]).channel, "M");
+ assert.equal(f([62,0,62]).channel, "M");
+ },
+ "returns Y given a pure yellow": function (f) {
+ assert.equal(f([255,255,0]).channel, "Y");
+ assert.equal(f([70,70,0]).channel, "Y");
+ },
+ "returns W given a pure white": function (f) {
+ assert.equal(f([255,255,255]).channel, "W");
+ assert.equal(f([100,100,100]).channel, "W");
+ },
+ "returns null given an impure color": function(f) {
+ assert.equal(f([12,34,56]).channel, null);
+ assert.equal(f([55,53,55]).channel, null);
+ assert.equal(f([0,128,254]).channel, null);
+ }
+ }
+ }
+});
+
+suite.export(module);