-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor params to match up to next token
- Loading branch information
1 parent
cbf2c73
commit 208cc83
Showing
5 changed files
with
584 additions
and
1,424 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
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,36 +1,28 @@ | ||
import { checkSync } from "recheck"; | ||
import { pathToRegexp } from "../src/index.js"; | ||
import { match } from "../src/index.js"; | ||
import { MATCH_TESTS } from "../src/cases.spec.js"; | ||
|
||
const TESTS = [ | ||
"/abc{abc:foo}?", | ||
"/:foo{abc:foo}?", | ||
"{:attr1}?{:attr2/}?", | ||
"{:attr1/}?{:attr2/}?", | ||
"{:foo.}?{:bar.}?", | ||
"{:foo([^\\.]+).}?{:bar.}?", | ||
":foo(a+):bar(b+)", | ||
]; | ||
let safe = 0; | ||
let fail = 0; | ||
|
||
const TESTS = new Set(MATCH_TESTS.map((test) => test.path)); | ||
// const TESTS = [ | ||
// ":path([^\\.]+).:ext", | ||
// ":path.:ext(\\w+)", | ||
// ":path{.:ext([^\\.]+)}", | ||
// "/:path.:ext(\\\\w+)", | ||
// ]; | ||
|
||
for (const path of TESTS) { | ||
try { | ||
const re = pathToRegexp(path, { strict: true }); | ||
const result = checkSync(re.source, re.flags); | ||
if (result.status === "safe") { | ||
console.log("Safe:", path, String(re)); | ||
} else { | ||
console.log("Fail:", path, String(re)); | ||
} | ||
} catch (err) { | ||
try { | ||
const re = pathToRegexp(path); | ||
const result = checkSync(re.source, re.flags); | ||
if (result.status === "safe") { | ||
console.log("Invalid:", path, String(re)); | ||
} else { | ||
console.log("Pass:", path, String(re)); | ||
} | ||
} catch (err) { | ||
console.log("Error:", path, err.message); | ||
} | ||
const { re } = match(path); | ||
const result = checkSync(re.source, re.flags); | ||
if (result.status === "safe") { | ||
safe++; | ||
console.log("Safe:", path, String(re)); | ||
} else { | ||
fail++; | ||
console.log("Fail:", path, String(re)); | ||
} | ||
} | ||
|
||
console.log("Safe:", safe, "Fail:", fail); |
Oops, something went wrong.