Skip to content

Commit

Permalink
Merge pull request #2 from io-monad/issue-1
Browse files Browse the repository at this point in the history
Fix bug toIndex({ line: 0, col: 0}) failed
  • Loading branch information
io-monad committed Mar 26, 2016
2 parents c3e10bd + 6760e9f commit 8390ef6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/line-column.js
Expand Up @@ -76,7 +76,7 @@ LineColumnFinder.prototype.toIndex = function (line, column) {
return this.toIndex(line[0], line[1]);
}
if (isObject(line) && "line" in line && ("col" in line || "column" in line)) {
return this.toIndex(line.line, line.col || line.column);
return this.toIndex(line.line, ("col" in line ? line.col : line.column));
}
return -1;
}
Expand Down
12 changes: 12 additions & 0 deletions test/line-column-test.js
Expand Up @@ -174,6 +174,9 @@ describe("LineColumnFinder", function () {
it("returns an index for the last line", function () {
assert(lineColumn.toIndex(4, 7) === 43);
});
it("returns an index for the first character", function () {
assert(lineColumn.toIndex(0, 0) === 0);
});
it("returns an index for the last character", function () {
assert(lineColumn.toIndex(4, 12) === 48);
});
Expand All @@ -190,6 +193,15 @@ describe("LineColumnFinder", function () {
it("accepts an Array of [ line, col ]", function () {
assert(lineColumn.toIndex([1, 7]) === 15);
});
it("returns an index for { line: 0, col: 0 }", function () {
assert(lineColumn.toIndex({ line: 0, col: 0 }) === 0);
});
it("returns an index for { line: 0, column: 0 }", function () {
assert(lineColumn.toIndex({ line: 0, column: 0 }) === 0);
});
it("returns an index for [ 0, 0 ]", function () {
assert(lineColumn.toIndex([0, 0]) === 0);
});

it("returns -1 for line < 0", function () {
assert(lineColumn.toIndex(-1, 3) === -1);
Expand Down

0 comments on commit 8390ef6

Please sign in to comment.