Skip to content

Commit

Permalink
1.7.1: Simplified dependencies and made the module slightly easier to…
Browse files Browse the repository at this point in the history
… work with.
  • Loading branch information
Jason LaPorte committed Jul 29, 2014
1 parent dad9bbd commit 8d04af0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,20 @@ distribution. The above command will create the directory `node_modules` which
will contain the two libraries used for development. After this, you can
verify that everything is working by running the tests:

$ ./node_modules/.bin/mocha
$ npm test

> [email protected] test /Users/jason/src/forecast-io-translations
> mocha --reporter dot --check-leaks

․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․

278 passing (80ms)
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․

386 passing (196ms)

[5]: http://visionmedia.github.io/mocha/
[6]: http://chaijs.com/
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "forecast-io-translations",
"version": "1.7.0",
"version": "1.7.1",
"description": "translate the Forecast API into any language",
"author": {
"name": "The Dark Sky Company",
Expand Down Expand Up @@ -47,8 +47,10 @@
"type": "git",
"url": "git://github.com/darkskyapp/forecast-api-translations"
},
"scripts": {
"test": "./node_modules/.bin/mocha --reporter dot --check-leaks"
},
"devDependencies": {
"mocha": "1.20.x",
"chai": "1.9.x"
"mocha": "1.21.x"
}
}
48 changes: 24 additions & 24 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var expect = require("chai").expect,
var assert = require("assert"),
fs = require("fs"),
path = require("path"),
template = require("./lib/template"),
Expand All @@ -15,95 +15,95 @@ describe("translation", function() {
});

it("should return a number in string form", function() {
expect(convert(42)).to.equal("42");
assert.strictEqual(convert(42), "42");
});

it("should throw an error given an unrecognized string", function() {
expect(function() { convert("42"); }).to.throw();
assert.throws(function() { convert("42"); });
});

it("should apply an expected value conversion", function() {
expect(convert("foo")).to.equal("bar");
assert.strictEqual(convert("foo"), "bar");
});

it("should throw an error given a value that's expected to be a string template", function() {
expect(function() { convert("bar"); }).to.throw();
assert.throws(function() { convert("bar"); });
});

it("should throw an error given a value that's expected to be a function template", function() {
expect(function() { convert("baz"); }).to.throw();
assert.throws(function() { convert("baz"); });
});

it("should throw an error given an empty array", function() {
expect(function() { convert([]); }).to.throw();
assert.throws(function() { convert([]); });
});

it("should apply a string template", function() {
expect(convert(["bar", 10, 20])).to.equal("meeple 20");
assert.strictEqual(convert(["bar", 10, 20]), "meeple 20");
});

it("should fail to apply a function template given the wrong number of arguments", function() {
expect(function() { convert(["baz", 10, 20, 30]); }).to.throw();
assert.throws(function() { convert(["baz", 10, 20, 30]); });
});

it("should apply a function template", function() {
expect(convert(["baz", 10, 20])).to.equal("meeple 20");
assert.strictEqual(convert(["baz", 10, 20]), "meeple 20");
});

it("should recursively apply function templates", function() {
/* Actually, a "meeple meeple bar" sounds like it'd be a pretty tasty
* candy treat. */
expect(convert(["bar", 10, ["baz", 20, "foo"]])).to.equal("meeple meeple bar");
assert.strictEqual(convert(["bar", 10, ["baz", 20, "foo"]]), "meeple meeple bar");
});

it("should throw an error given undefined", function() {
expect(function() { convert(undefined); }).to.throw();
assert.throws(function() { convert(undefined); });
});

it("should throw an error given null", function() {
expect(function() { convert(null); }).to.throw();
assert.throws(function() { convert(null); });
});

it("should throw an error given an object", function() {
expect(function() { convert({}); }).to.throw();
assert.throws(function() { convert({}); });
});

it("should apply an expected value conversion given a zero-argument function", function() {
expect(convert("quux")).to.equal("glorple");
assert.strictEqual(convert("quux"), "glorple");
});

it("should fail to apply a zero-argument function given arguments", function() {
expect(function() { convert(["quux"]); }).to.throw();
assert.throws(function() { convert(["quux"]); });
});

it("should fail to apply a function template given a value", function() {
expect(function() { convert("baz"); }).to.throw();
assert.throws(function() { convert("baz"); });
});

it("should provide context to functions", function() {
var convert = template({
"foo": function(a, b, c) {
expect(this).to.deep.equal(["foo"]);
assert.deepEqual(this, ["foo"]);
return "Moop.";
},
"bar": function() {
expect(this).to.deep.equal(["foo", "bar"]);
assert.deepEqual(this, ["foo", "bar"]);
return "Boop.";
},
"baz": function(a) {
expect(this).to.deep.equal(["foo", "baz"]);
assert.deepEqual(this, ["foo", "baz"]);
return "Soup.";
},
"quux": function() {
expect(this).to.deep.equal(["foo", "baz", "quux"]);
assert.deepEqual(this, ["foo", "baz", "quux"]);
return "Floop.";
},
"neem": function(a) {
expect(this).to.deep.equal(["foo", "neem"]);
assert.deepEqual(this, ["foo", "neem"]);
return "Bloop.";
},
"glorp": function(a) {
expect(this).to.deep.equal(["foo", "neem", "glorp"]);
assert.deepEqual(this, ["foo", "neem", "glorp"]);
return "Rope?";
}
});
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("translation", function() {
it(
util.format("should translate %j to \"%s\"", source, summary),
function() {
expect(translate(source)).to.equal(summary);
assert.strictEqual(translate(source), summary);
}
);
});
Expand Down

0 comments on commit 8d04af0

Please sign in to comment.