expandFile-test.js (2255B)
1 var vows = require("vows"), 2 assert = require("assert"), 3 expandFile = require("../lib/smash/expand-file"); 4 5 var suite = vows.describe("smash.expandFile"); 6 7 suite.addBatch({ 8 "expandFile": { 9 "adds the specified file extension if necessary": function() { 10 assert.equal("foo.js", expandFile("foo", ".js")); 11 assert.equal("foo.coffee", expandFile("foo", ".coffee")); 12 }, 13 "adds index.extension if the file has a trailing slash": function() { 14 assert.equal("foo/index.js", expandFile("foo/", ".js")); 15 assert.equal("foo/index.coffee", expandFile("foo/", ".coffee")); 16 }, 17 "does nothing if the file already has an extension": function() { 18 assert.equal("foo.js", expandFile("foo.js")); 19 assert.equal("foo.js", expandFile("foo.js", ".coffee")); 20 }, 21 "uses the specified extension, even if it is the empty string": function() { 22 assert.equal("foo", expandFile("foo", "")); 23 assert.equal("foo/index", expandFile("foo/", "")); 24 }, 25 "coerces the specified extension to a string": function() { 26 assert.equal("foo.1", expandFile("foo", {toString: function() { return ".1"; }})); 27 assert.equal("foo/index1", expandFile("foo/", 1)); 28 }, 29 "does not require a \".\" in the file extension": function() { 30 assert.equal("foo_bar", expandFile("foo", "_bar")); 31 assert.equal("foo/index_bar", expandFile("foo/", "_bar")); 32 }, 33 "uses the specified extension, even if it is falsey": function() { 34 assert.equal("foofalse", expandFile("foo", false)); 35 assert.equal("foo/indexfalse", expandFile("foo/", false)); 36 assert.equal("foo0", expandFile("foo", 0)); 37 assert.equal("foo/index0", expandFile("foo/", 0)); 38 }, 39 "uses the default extension (.js), if not specified": function() { 40 assert.equal("foo.js", expandFile("foo")); 41 assert.equal("foo/index.js", expandFile("foo/")); 42 }, 43 "uses the default extension (.js), if null or undefined": function() { 44 assert.equal("foo.js", expandFile("foo", null)); 45 assert.equal("foo/index.js", expandFile("foo/", null)); 46 assert.equal("foo.js", expandFile("foo", undefined)); 47 assert.equal("foo/index.js", expandFile("foo/", undefined)); 48 } 49 } 50 }); 51 52 suite.export(module);