Permalink
Browse files

Set up tests and add them for Path.

  • Loading branch information...
1 parent e70110f commit e1e97d7e93d197206dd1848b2633d4f35b06c88d @moll moll committed Mar 24, 2014
Showing with 117 additions and 1 deletion.
  1. +1 −1 .npmignore
  2. +20 −0 Makefile
  3. +7 −0 package.json
  4. +2 −0 {tests → test}/dates.js
  5. +2 −0 {tests → test}/fields.js
  6. +81 −0 test/lib/path_test.js
  7. +2 −0 test/mocha.opts
  8. +2 −0 {tests → test}/utils.js
View
@@ -1,3 +1,3 @@
docs
examples
-tests
+/test/
View
@@ -0,0 +1,20 @@
+NODE_OPTS :=
+TEST_OPTS :=
+
+love:
+ @echo "What would you like to do today?"
+
+test:
+ @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R dot $(TEST_OPTS)
+
+spec:
+ @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R spec $(TEST_OPTS)
+
+autotest:
+ @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R dot --watch $(TEST_OPTS)
+
+autospec:
+ @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R spec --watch $(TEST_OPTS)
+
+.PHONY: love
+.PHONY: test spec autotest autospec
View
@@ -29,6 +29,10 @@
"azure": "~0.8.1",
"range_check": "~0.0.4"
},
+ "devDependencies": {
+ "mocha": ">= 1.12 < 2",
+ "must": ">= 0.11 < 1"
+ },
"author": "Jed Watson",
"license": "MIT",
"keywords": [
@@ -47,6 +51,9 @@
"bugs": {
"url": "https://github.com/JedWatson/keystone/issues"
},
+ "scripts": {
+ "test": "make test"
+ },
"engines": {
"node": "0.10.x",
"npm": "1.3.x"
@@ -1,3 +1,5 @@
+if (module.parent) return;
+
/**
These tests are currently designed to be run from the command line like
`/keystone/tests node dates`
@@ -1,3 +1,5 @@
+if (module.parent) return;
+
/**
These tests are currently designed to be run from the command line like
`/keystone/tests node fields`
View
@@ -0,0 +1,81 @@
+var Path = require("../../lib/path")
+
+describe("Path", function() {
+ describe("new", function() {
+ it("must be an instance of Path", function() {
+ new Path("").must.be.an.instanceof(Path)
+ })
+ })
+
+ describe(".prototype.append", function() {
+ it("must return the path appended to the given part", function() {
+ var path = new Path("foo.example.dir")
+ path.append(".com").must.equal("foo.example.dir.com")
+ })
+ })
+
+ describe(".prototype.addTo", function() {
+ it("must return an hierarchical object from path", function() {
+ var path = new Path("foo.example.dir.file")
+ var obj = path.addTo({}, 42)
+ obj.must.eql({foo: {example: {dir: {file: 42}}}})
+ })
+
+ it("must merge given an existing hierarchy", function() {
+ var path = new Path("foo.example.dir.file")
+ var obj = path.addTo({foo: {example: {link: 69}}}, 42)
+ obj.must.eql({foo: {example: {link: 69, dir: {file: 42}}}})
+ })
+ })
+
+ describe(".prototype.get", function() {
+ it("must walk hierarchy and return value", function() {
+ var path = new Path("foo.example.dir")
+ path.get({foo: {example: {dir: 42}}}).must.equal(42)
+ })
+ })
+
+ describe(".prototype.prependToLast", function() {
+ it("must return path with preprended last part", function() {
+ var path = new Path("foo.example.dir")
+ path.prependToLast("cool").must.equal("foo.example.cooldir")
+ })
+
+ it("must return path with last part in titlecase given true", function() {
+ var path = new Path("foo.example.dir")
+ path.prependToLast("cool", true).must.equal("foo.example.coolDir")
+ })
+
+ it("must return path with last part as-is given false", function() {
+ var path = new Path("foo.example.dir")
+ path.prependToLast("cool", false).must.equal("foo.example.cooldir")
+ })
+ })
+
+ describe(".prototype.flatten", function() {
+ it("must return path camel cased given false", function() {
+ var path = new Path("foo.example.dir")
+ path.flatten(false).must.equal("FooExampleDir")
+ })
+
+ it("must return path camel cased with lowercase first letter given true",
+ function() {
+ var path = new Path("foo.example.dir")
+ path.flatten(true).must.equal("fooExampleDir")
+ })
+ })
+
+ describe("last", function() {
+ it("must equal to the last part of path", function() {
+ var path = new Path("foo.example.dir")
+ path.last.must.equal("dir")
+ })
+ })
+
+ describe("exceptLast", function() {
+ it("must equal to the path without last part", function() {
+ var path = new Path("foo.example.dir")
+ path.exceptLast.must.equal("foo.example")
+ })
+ })
+})
View
@@ -0,0 +1,2 @@
+--recursive
+--require must
@@ -1,3 +1,5 @@
+if (module.parent) return;
+
/**
These tests are currently designed to be run from the command line like
`/keystone/tests node utils`

0 comments on commit e1e97d7

Please sign in to comment.