Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 91a988c

Browse files
committed
Initial commit
1 parent 457ab90 commit 91a988c

10 files changed

+158
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Test Rules
2+
3+
Test rules are made to verify that your implementation of SRL is valid.
4+
These files contain simple tests to validate the SRL and the
5+
corresponding results. The structure is easy to understand and implement.
6+
7+
## Structure of a .rule File
8+
9+
These rules are required to build valid test rules:
10+
11+
* All files used for testing must end with the extension `.rule` and at
12+
least contain one valid assertion along with the SRL query.
13+
* The query is defined through `srl: ` on the beginning of a line.
14+
* All strings that should match are defined through `match: ` on the
15+
beginning of a line.
16+
* There can be unlimited `match: ` lines per rule.
17+
* Each match must be surrounded by `"`.
18+
* All strings that should **not** match are defined through `no match: `
19+
on the beginning of a line.
20+
* There can be unlimited `no match: ` lines per rule.
21+
* Each match must be surrounded by `"`.
22+
* If a capture group is defined, its result can be defined as follows:
23+
* The line must begin with `capture for `.
24+
* Surrounded by `"`, the test string to match must be provided, followed by a `: `.
25+
* If a named group is desired, use the following syntax: `name: "result"`
26+
* If a anonymous group is desired, just supply `"result"`.
27+
* Separate multiple captures using `, `.
28+
* If one expression returns multiple matches, supply the same test string in the second line.
29+
* The query as well as the expectations must not exceed one line.
30+
If required, new lines can be forced using `\n`. Tabs using `\t`.
31+
* Comments must be on a separate line and start with a `#`.
32+
33+
## Example .rule Files
34+
35+
```
36+
# This is a sample rule with a named capture group
37+
srl: capture (letter twice) as "foo"
38+
capture for "aa1":
39+
- 0: foo: "aa"
40+
match: "example"
41+
match: "aa2"
42+
no match: "a"
43+
```
44+
45+
```
46+
# This is a sample rule with an anonymous capture group and multiple results
47+
srl: capture (digit)
48+
capture for "123":
49+
- 0: 0: "1"
50+
- 1: 0: "2"
51+
- 2: 0: "3"
52+
53+
capture for "01":
54+
- 0: 0: "0"
55+
- 1: 0: "1"
56+
```

basename_capture_group.rule

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Make sure php internal functions aren't executed while using capture groups
2+
srl: begin with capture (letter twice) as "basename", must end
3+
capture for "aa":
4+
- 0: basename: "aa"
5+
no match: "a1"
6+
no match: "aaa"
7+
match: "bb"

issue_17_uppercase_letter.rule

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
srl: begin with (digit once), any of (letter, digit, uppercase letter) once or more, must end
2+
match: "1a"
3+
match: "56"
4+
match: "8B"
5+
no match: "abc"
6+
no match: "1"

literally_spaces.rule

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Make sure literal strings are not trimmed.
2+
srl: literally " foo "
3+
match: " foo "
4+
no match: "foo"

sample_capture.rule

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This is a sample rule with an anonymous capture group and multiple results
2+
srl: capture (digit)
3+
capture for "123":
4+
- 0: 0: "1"
5+
- 1: 0: "2"
6+
- 2: 0: "3"
7+
8+
capture for "01":
9+
- 0: 0: "0"
10+
- 1: 0: "1"

website_example_email.rule

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
srl: begin with any of (digit, letter, one of "._%+-") once or more, literally "@", any of (digit, letter, one of ".-") once or more, literally ".", letter at least 2 times, must end, case insensitive
2+
3+
4+
5+
no match: "[email protected]"
6+
no match: "you@example"
7+
no match: "[email protected]"
8+
no match: "@example.com"
9+
no match: "example.com"

website_example_email_capture.rule

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
srl: capture (any of (digit, letter, one of "._%+-") once or more) as "local", literally "@", capture (any of (digit, letter, one of ".-") once or more, literally ".", letter at least 2 times ) as "domain", case insensitive
2+
3+
no match: "[email protected]"
4+
no match: "just some text"
5+
no match: "example.com"
6+
7+
capture for "Message me at [email protected]. Business email: [email protected]":
8+
- 0: local: "you"
9+
- 0: domain: "example.com"
10+
- 1: local: "business"
11+
- 1: domain: "awesome.email"

website_example_lookahead.rule

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
srl: capture (digit) if not followed by (anything once or more, digit)
2+
match: "This example contains 3 numbers. 2 should not match. Only 1 should."
3+
no match: "some string without numbers"
4+
5+
capture for "This example contains 3 numbers. 2 should not match. Only 1 should.":
6+
- 0: 0: "1"

website_example_password.rule

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
srl: if followed by (anything never or more, letter), if followed by (anything never or more, uppercase letter), if followed by (anything never or more, digit), if followed by (anything never or more, one of "!@#$%^&*[]\"';:_-<>., =+/\\"), anything at least 8 time
2+
match: "P@sSword1"
3+
match: "Pass-w0rd"
4+
match: "Th1s is Secure"
5+
no match: "Password"
6+
no match: "P@sS1"
7+
no match: "justalongpassword"
8+
no match: "m1ss1ng upper"
9+
no match: "missing Number"
10+
no match: "M1SS1NG LOWER"
11+
no match: "m1ss1ngSpec1al"

website_example_url.rule

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
srl: begin with capture (letter once or more) as "protocol", literally "://", capture ( letter once or more, any of (letter, literally ".") once or more, letter at least 2 times ) as "domain", literally ":" optional, capture (digit once or more) as "port" optional, capture (anything never or more) as "path" until (any of (literally "?", must end)), literally "?" optional, capture (anything never or more) as "parameters" optional, must end, case insensitive
2+
match: "https://example.domain.com:1234/a/path?query=param"
3+
match: "http://domain.com?query=param"
4+
match: "http://domain.com/"
5+
match: "http://domain.com"
6+
match: "http://domain/foo/?bar=baz"
7+
no match: "[email protected]"
8+
no match: "domain.com"
9+
no match: "://domain.com"
10+
no match: "http://"
11+
12+
capture for "https://example.domain.com:1234/a/path?query=param":
13+
- 0: protocol: "https"
14+
- 0: domain: "example.domain.com"
15+
- 0: port: "1234"
16+
- 0: path: "/a/path"
17+
- 0: parameters: "query=param"
18+
19+
capture for "https://example.domain.com:1234/a/path":
20+
- 0: protocol: "https"
21+
- 0: domain: "example.domain.com"
22+
- 0: port: "1234"
23+
- 0: path: "/a/path"
24+
- 0: parameters: ""
25+
26+
capture for "protocol://domain/a/path":
27+
- 0: protocol: "protocol"
28+
- 0: domain: "domain"
29+
- 0: port: ""
30+
- 0: path: "/a/path"
31+
- 0: parameters: ""
32+
33+
capture for "http://domain.com":
34+
- 0: protocol: "http"
35+
- 0: domain: "domain.com"
36+
- 0: port: ""
37+
- 0: path: ""
38+
- 0: parameters: ""

0 commit comments

Comments
 (0)