forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurlpattern-test.js
More file actions
30 lines (26 loc) · 833 Bytes
/
urlpattern-test.js
File metadata and controls
30 lines (26 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
const common = require('../common.js');
const { URLPattern } = require('url');
const { notStrictEqual } = require('assert');
const tests = [
'https://(sub.)?example(.com/)foo',
{ 'hostname': 'xn--caf-dma.com' },
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz',
'baseURL': 'https://example.com:8080' },
{ 'pathname': '/([[a-z]--a])' },
];
const bench = common.createBenchmark(main, {
pattern: tests.map(JSON.stringify),
n: [1e5],
});
function main({ pattern, n }) {
const inputPattern = JSON.parse(pattern);
const urlpattern = new URLPattern(inputPattern);
let deadcode;
bench.start();
for (let i = 0; i < n; i += 1) {
deadcode = urlpattern.test('https://sub.example.com/foo');
}
bench.end(n);
notStrictEqual(deadcode, undefined); // We don't care if it is true or false.
}