-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils.clean extracts a test method content re-indenting the function for whitespaces. This commit fixes to issues with indentation * windows line feed `\r\n` * tab indentation `\t`
- Loading branch information
fcrisci
committed
Mar 5, 2013
1 parent
4d95a87
commit 2bbc1bb
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var utils = require('../../lib/utils'); | ||
|
||
describe('lib/utils', function () { | ||
describe('clean', function () { | ||
it("should format a single line test function", function () { | ||
var fn = [ | ||
"function () {" | ||
, " var a = 1;" | ||
, "}" | ||
].join("\n"); | ||
utils.clean(fn).should.equal("var a = 1;"); | ||
}); | ||
|
||
it("should format a multi line test indented with spaces", function () { | ||
// and no new lines after curly braces, shouldn't matter | ||
var fn = [ | ||
"function(){ var a = 1;" | ||
, " var b = 2;" // this one has more spaces | ||
, " var c = 3; }" | ||
].join("\n"); | ||
utils.clean(fn).should.equal("var a = 1;\n var b = 2;\nvar c = 3;"); | ||
}); | ||
|
||
it("should format a multi line test indented with tabs", function () { | ||
var fn = [ | ||
"function (arg1, arg2) {" | ||
, "\tif (true) {" | ||
, "\t\tvar a = 1;" | ||
, "\t}" | ||
, "}" | ||
].join("\n"); | ||
utils.clean(fn).should.equal("if (true) {\n\tvar a = 1;\n}"); | ||
}); | ||
|
||
it("should format functions saved in windows style - spaces", function () { | ||
var fn = [ | ||
"function (one) {" | ||
, " do {", | ||
, ' "nothing";', | ||
, " } while (false);" | ||
, ' }' | ||
].join("\r\n"); | ||
utils.clean(fn).should.equal('do {\n "nothing";\n} while (false);'); | ||
}); | ||
|
||
it("should format functions saved in windows style - tabs", function () { | ||
var fn = [ | ||
"function ( ) {" | ||
, "\tif (false) {" | ||
, "\t\tvar json = {" | ||
, '\t\t\tone : 1' | ||
, '\t\t};' | ||
, "\t}" | ||
, "}" | ||
].join("\r\n"); | ||
utils.clean(fn).should.equal("if (false) {\n\tvar json = {\n\t\tone : 1\n\t};\n}"); | ||
}); | ||
}); | ||
}); |