-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from larshisken/feat-improve-errors
feat: improve parse errors
- Loading branch information
Showing
6 changed files
with
95 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.PHONY: clean | ||
|
||
unit_test_files := $(shell find test/unit/ -name '*.ts') | ||
|
||
coverage: $(unit_test_files) | ||
deno test --coverage=coverage --unstable test/unit | ||
|
||
coverage.lcov: coverage | ||
deno coverage --unstable test/unit coverage --lcov > coverage.lcov | ||
|
||
coverage/html: coverage.lcov | ||
genhtml --output-directory=coverage/html coverage.lcov | ||
|
||
clean: | ||
rm --recursive --force coverage coverage.lcov |
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,5 @@ | ||
export { | ||
assert, | ||
assertEquals, | ||
assertThrows | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; |
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { | ||
assert, | ||
assertEquals, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
import { doTest, Example } from "./helper.ts"; | ||
import { assert, assertEquals } from "../../deps.ts"; | ||
import { expand } from "../../mod.ts"; | ||
import { doTest, Example } from "./helper.ts"; | ||
|
||
const [x, y] = await Promise.all([ | ||
Deno.readTextFile("./uritemplate-test/spec-examples.json"), | ||
|
@@ -19,7 +15,9 @@ const examples: Record<string, Example> = { | |
doTest( | ||
examples, | ||
({ testcase: [x, y], variables }) => | ||
typeof y === "string" | ||
? assertEquals(expand(x, variables), y) | ||
: assert(y.includes(expand(x, variables))), | ||
typeof y === "string" ? assertEquals(expand(x, variables), y) : assert( | ||
y.includes( | ||
expand(x, variables), | ||
), | ||
), | ||
); |
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { | ||
assertEquals, | ||
assertThrows, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
import { Expression, ExpressionType, parse } from "../../mod.ts"; | ||
import { assertEquals, assertThrows } from "../../deps.ts"; | ||
|
||
Deno.test("Should parse '{foo}' to a list of expressions", () => { | ||
const expected: Expression[] = [ | ||
|
@@ -79,21 +75,57 @@ Deno.test("Should parse 'foo/{bar}/baz' to a list of expressions", () => { | |
}); | ||
|
||
Deno.test("Should throw when a closing brace is found without an opening brace", () => { | ||
assertThrows(() => parse("}"), Error, "ParseError"); | ||
assertThrows(() => parse("foo}bar"), Error, "ParseError"); | ||
assertThrows( | ||
() => parse("}"), | ||
Error, | ||
"Unexpected char '}' at position 1 in '}', expected an opening brace before a closing brace.", | ||
); | ||
|
||
assertThrows( | ||
() => parse("foo}bar"), | ||
Error, | ||
"Unexpected char '}' at position 4 in 'foo}bar', expected an opening brace before a closing brace.", | ||
); | ||
}); | ||
|
||
Deno.test("Should throw when an opening brace is found at the end", () => { | ||
assertThrows(() => parse("{"), Error, "ParseError"); | ||
assertThrows(() => parse("foo{"), Error, "ParseError"); | ||
assertThrows( | ||
() => parse("{"), | ||
Error, | ||
"Unexpected char '{' at position 1 in '{', expected a closing brace.", | ||
); | ||
|
||
assertThrows( | ||
() => parse("foo{"), | ||
Error, | ||
"Unexpected char '{' at position 4 in 'foo{', expected a closing brace.", | ||
); | ||
}); | ||
|
||
Deno.test("Should throw when an opening brace is not closed", () => { | ||
assertThrows(() => parse("foo{bar"), Error, "ParseError"); | ||
assertThrows(() => parse("foo{bar{baz}"), Error, "ParseError"); | ||
assertThrows( | ||
() => parse("foo{bar"), | ||
Error, | ||
"Unexpected char 'r' at position 7 in 'foo{bar', expected a closing brace.", | ||
); | ||
|
||
assertThrows( | ||
() => parse("foo{bar{baz}"), | ||
Error, | ||
"Unexpected char '{' at position 8 in 'foo{bar{baz}', expected a closing brace.", | ||
); | ||
}); | ||
|
||
Deno.test("Should throw when empty braces are found", () => { | ||
assertThrows(() => parse("{}"), Error, "ParseError"); | ||
assertThrows(() => parse("foo/{}"), Error, "ParseError"); | ||
assertThrows( | ||
() => parse("{}"), | ||
Error, | ||
"Unexpected char '}' at position 2 in '{}', expected a pair of braces to have content.", | ||
); | ||
|
||
assertThrows( | ||
() => parse("foo/{}"), | ||
Error, | ||
"Unexpected char '}' at position 6 in 'foo/{}', expected a pair of braces to have content.", | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
import { assertEquals } from "../../deps.ts"; | ||
import { pctEncode, pctEncodeChar } from "../../pct.ts"; | ||
|
||
Deno.test("Should encode individual characters", () => { | ||
|