Add regex matcher tests.

This commit is contained in:
Bauke 2022-10-21 00:14:58 +02:00
parent f7d292932f
commit 696dd8fde8
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 14 additions and 1 deletions

View File

@ -88,14 +88,27 @@ test('Redirect.isMatch', (t) => {
test: 'invalid', test: 'invalid',
} as unknown as HostnameRedirect['parameters']); } as unknown as HostnameRedirect['parameters']);
const regexMatch = new HostnameRedirect({
matcherType: 'regex',
matcherValue: String.raw`^https://(www\.)?example.org/$`,
redirectType: 'simple',
redirectValue: '',
});
const regexSamples: UrlSamples = [
['https://example.org', true],
['https://www.example.org', true],
['https://example.org/path', false],
];
const samples: Array<[Redirects, UrlSamples]> = [ const samples: Array<[Redirects, UrlSamples]> = [
[invalidRedirect, [['https://example.org', false]]], [invalidRedirect, [['https://example.org', false]]],
[hostnameRedirect, hostnameSamples], [hostnameRedirect, hostnameSamples],
[regexMatch, regexSamples],
]; ];
for (const [redirect, urlSamples] of samples) { for (const [redirect, urlSamples] of samples) {
for (const [sample, expected] of urlSamples) { for (const [sample, expected] of urlSamples) {
t.is(redirect.isMatch(new URL(sample)), expected); t.is(redirect.isMatch(new URL(sample)), expected, `Sample ${sample}`);
} }
} }
}); });