Comparing version 0.0.5 to 0.1.0
@@ -123,26 +123,15 @@ 'use strict'; | ||
function getIndexPos(text, index, eol) { | ||
var line = 1, col = 1, pos = 0; | ||
var lineIdx = 0, colIdx = index, pos = 0; | ||
do { | ||
pos = text.indexOf(eol, pos); | ||
if (pos == -1) { | ||
if (pos == -1 || index < pos + eol.length) { | ||
break; | ||
} | ||
lineIdx++; | ||
pos += eol.length; | ||
if (pos <= index) { | ||
line++; | ||
} | ||
colIdx = index - pos; | ||
} while (pos < index); | ||
if (index >= eol.length) { | ||
var lastIdx = text.lastIndexOf(eol, index - eol.length); | ||
if (lastIdx === -1) { | ||
col = index; | ||
} else { | ||
col = index - lastIdx - eol.length + 1; | ||
} | ||
} else { | ||
col = index + 1; | ||
} | ||
return { | ||
line: line, | ||
column: col | ||
line: lineIdx + 1, | ||
column: colIdx + 1 | ||
}; | ||
@@ -149,0 +138,0 @@ } |
{ | ||
"name": "pg-minify", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Minifies PostgreSQL scripts.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -53,3 +53,3 @@ pg-minify | ||
// error.message: | ||
// Error parsing SQL at {line:1,col:7}: Unclosed text block. | ||
// Error parsing SQL at {line:1,col:8}: Unclosed text block. | ||
} | ||
@@ -56,0 +56,0 @@ ``` |
@@ -96,3 +96,2 @@ 'use strict'; | ||
}); | ||
@@ -116,2 +115,3 @@ | ||
var errMsg = "Error parsing SQL at {line:1,col:1}: Unclosed text block."; | ||
it("must throw an error", function () { | ||
@@ -143,4 +143,19 @@ expect(function () { | ||
})); | ||
}); | ||
it("must report positions correctly", function () { | ||
expect(getErrorPos("'").column).toBe(1); | ||
expect(getErrorPos(" '").column).toBe(2); | ||
expect(getErrorPos("s'").column).toBe(2); | ||
expect(getErrorPos("s '").column).toBe(3); | ||
}); | ||
function getErrorPos(sql) { | ||
try { | ||
minify(sql); | ||
} catch (e) { | ||
return e.position; | ||
} | ||
return null; | ||
} | ||
}); | ||
@@ -194,2 +209,16 @@ | ||
it("must work from the start", function () { | ||
expect(pos("123456", 3)).toEqual({ | ||
line: 1, | ||
column: 4 | ||
}); | ||
}); | ||
it("must work from the start", function () { | ||
expect(pos("123456", 5)).toEqual({ | ||
line: 1, | ||
column: 6 | ||
}); | ||
}); | ||
it("step over lines correctly", function () { | ||
@@ -202,6 +231,6 @@ expect(pos("123\r\n456", 5)).toEqual({ | ||
it("must step back from a line break", function () { | ||
it("must step over line breaks", function () { | ||
expect(pos("123\r\n", 3)).toEqual({ | ||
line: 1, | ||
column: 3 | ||
column: 4 | ||
}); | ||
@@ -208,0 +237,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15273
355