Skip to content

Commit

Permalink
add unit tests for function character locations
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrbrandt committed Jun 23, 2012
1 parent 1ac8c63 commit 4b16206
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/unit/fixtures/nestedFunctions-locations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests/unit/fixtures/nestedFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// non-nested function with non-standard ending curly placement
function a(x, y) {
return x+y;
}

// regular nested function
function b() {
function c() {
return 1+1;
}
return c();
}

// anonymous nested function with params
function d() {
var e = function (x, y) {
return x+y;
};
return e;
}

// anonymous nested function in parens
function f() {
(function () {
return 1+1;
})();
}

// all on one line with non-standard parenthesis placement
function g() { return function h () { return 1+1; };}

// function in object
var i = {
j : function () { return 1+1; }
};
18 changes: 18 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

var JSHINT = require('../../jshint.js').JSHINT,
fs = require('fs'),
assert = require('assert'),
TestRun = require("../helpers/testhelper").setup.testRun;

exports.unsafe = function () {
Expand Down Expand Up @@ -359,3 +360,20 @@ exports.withStatement = function () {
.addError(13, "Unexpected space after '2'.")
.test(src, {white: true, withstmt: true});
};

exports.functionCharaterLocation = function () {
var i;
var src = fs.readFileSync(__dirname + "/fixtures/nestedFunctions.js", "utf8");
var locations = JSON.parse(fs.readFileSync(__dirname + "/fixtures/nestedFunctions-locations.js", "utf8"));
JSHINT(src);
var report = JSHINT.data().functions;

assert.equal(locations.length, report.length);
for (i = 0; i < locations.length; i++) {
assert.equal(locations[i].name, report[i].name);
assert.equal(locations[i].line, report[i].line);
assert.equal(locations[i].character, report[i].character);
assert.equal(locations[i].last, report[i].last);
assert.equal(locations[i].lastcharacter, report[i].lastcharacter);
}
};

0 comments on commit 4b16206

Please sign in to comment.