Skip to content

Commit

Permalink
Add loose mode for repeatable delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed May 21, 2024
1 parent 9085eda commit 55fbd02
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 129 deletions.
159 changes: 77 additions & 82 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, it, expect } from "vitest";
import * as util from "util";
import * as pathToRegexp from "./index";
import semver from "semver";

type Test = [
pathToRegexp.Path,
Expand Down Expand Up @@ -2703,96 +2702,92 @@ const TESTS: Test[] = [
[["foobar", ["foobar", "foobar"]]],
[[{ name: "foobar" }, "foobar"]],
],
];

/**
* Named capturing groups (available from 1812 version 10)
*/
if (semver.gte(process.version, "10.0.0")) {
TESTS.push(
/**
* Named capturing groups (available from 1812 version 10)
*/
[
/\/(?<groupname>.+)/,
undefined,
[
/\/(?<groupname>.+)/,
undefined,
[
{
name: "groupname",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
],
[
["/", null],
["/foo", ["/foo", "foo"]],
],
[],
{
name: "groupname",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
],
[
/\/(?<test>.*).(?<format>html|json)/,
undefined,
[
{
name: "test",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
{
name: "format",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
],
[
["/route", null],
["/route.txt", null],
["/route.html", ["/route.html", "route", "html"]],
["/route.json", ["/route.json", "route", "json"]],
],
[],
["/", null],
["/foo", ["/foo", "foo"]],
],
[],
],
[
/\/(?<test>.*).(?<format>html|json)/,
undefined,
[
/\/(.+)\/(?<groupname>.+)\/(.+)/,
undefined,
[
{
name: 0,
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
{
name: "groupname",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
{
name: 1,
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
],
{
name: "test",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
{
name: "format",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
],
[
["/route", null],
["/route.txt", null],
["/route.html", ["/route.html", "route", "html"]],
["/route.json", ["/route.json", "route", "json"]],
],
[],
],
[
/\/(.+)\/(?<groupname>.+)\/(.+)/,
undefined,
[
{
name: 0,
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
{
name: "groupname",
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
{
name: 1,
prefix: "",
suffix: "",
modifier: "",
pattern: "",
},
],
[
["/test", null],
["/test/testData", null],
[
["/test", null],
["/test/testData", null],
[
"/test/testData/extraStuff",
["/test/testData/extraStuff", "test", "testData", "extraStuff"],
],
"/test/testData/extraStuff",
["/test/testData/extraStuff", "test", "testData", "extraStuff"],
],
[],
],
);
}
[],
],
];

/**
* Dynamically generate the entire test suite.
Expand Down
Loading

0 comments on commit 55fbd02

Please sign in to comment.