-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathregex.rs
109 lines (101 loc) · 1.68 KB
/
regex.rs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use crate::test;
test!(
test1,
r#"
test("foo")
"#,
r#"
"foo"
"#,
r#"
true
"#
);
test!(
test2,
r#"
.[] | test("a b c # spaces are ignored"; "ix")
"#,
r#"
["xabcd", "ABC"]
"#,
r#"
true
true
"#
);
test!(
match1,
r#"
match("(abc)+"; "g")
"#,
r#"
"abc abc"
"#,
r#"
{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}
{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}
"#
);
test!(
match2,
r#"
match("foo")
"#,
r#"
"foo bar foo"
"#,
r#"
{"offset": 0, "length": 3, "string": "foo", "captures": []}
"#
);
test!(
match3,
r#"
match(["foo", "ig"])
"#,
r#"
"foo bar FOO"
"#,
r#"
{"offset": 0, "length": 3, "string": "foo", "captures": []}
{"offset": 8, "length": 3, "string": "FOO", "captures": []}
"#
);
test!(
match4,
r#"
match("foo (?<bar123>bar)? foo"; "ig")
"#,
r#"
"foo bar foo foo foo"
"#,
r#"
{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}
{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}
"#
);
test!(
match5,
r#"
[ match("."; "g")] | length
"#,
r#"
"abc"
"#,
r#"
3
"#
);
test!(
capture1,
r#"
capture("(?<a>[a-z]+)-(?<n>[0-9]+)")
"#,
r#"
"xyzzy-14"
"#,
r#"
{ "a": "xyzzy", "n": "14" }
"#
);