-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
65 lines (59 loc) · 1.18 KB
/
test.ts
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { lexer, parse } from "./index.ts";
import { compile, defaultConfigForNode } from "./compile/js-url-checker.ts";
const fixture = `
scheme:example1.com/foo/bar/baz {
? match /web-path=(?<path>.*)/
# match
| id-1
| id-2
| /id-3/
}
/**
* foo
*/
scheme:example2.com/path/[param1]/[param2] {
/**
* bar
*/
? form {
/**
* baz
*/
'' = ''
a
b
param1 = exact | match | value
param2 = /^[0-9]+$/
param3 [] = /^[a-z]+$/i
}
# match /id/
}
scheme:username@example3.com:4321 {
? form {
'a' = /.*/
'b' = /.*/
'c-d' = /.*/
'/' = /.*/
'?' = /.*/
'f/' = /.*/
'g' = /.*/
'h' = /.*/
}
}
`;
// lexer.reset(fixture);
// for (const token of lexer) {
// const {type, text} = token;
// console.log(`${type!.padStart(10, ' ')}: ${JSON.stringify(text)}`);
// }
const schema = parse(fixture)!;
const code = compile(schema, defaultConfigForNode);
// console.log(
// JSON.stringify(schema, null, 4)
// );
console.log(code);
const test =
"scheme://example2.com/path/param1/param2?=&a&b¶m1=exact¶m2=_123¶m3=_a¶m3=a#d";
console.log(
eval("(()=>{" + code + ';return check("' + test + '")})()'),
);