srl_ruby 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/cucumber.yml +4 -0
- data/features/basic/anchors.feature +61 -0
- data/features/basic/characters.feature +44 -0
- data/features/basic/digits.feature +94 -0
- data/features/basic/letters.feature +86 -0
- data/features/basic/literally.feature +58 -0
- data/features/basic/quantifiers.feature +180 -0
- data/features/basic/raw.feature +22 -0
- data/features/basic/special_characters.feature +90 -0
- data/features/email_validation.feature +38 -0
- data/features/floatingpoint.feature +36 -0
- data/features/intermediate/any_of.feature +35 -0
- data/features/intermediate/capture.feature +64 -0
- data/features/intermediate/lookaround.feature +51 -0
- data/features/lib/step_definitions/srl_testing_steps.rb +59 -0
- data/features/lib/support/env..rb +3 -0
- data/features/password_validation.feature +28 -0
- data/features/url_capturing.feature +31 -0
- data/lib/srl_ruby/version.rb +1 -1
- data/srl_ruby.gemspec +4 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 192758cce667147a6b7369cf6d575aa7fb22b627
|
4
|
+
data.tar.gz: 3f851cdb8557bc8baba910ded6e4e0433851fa6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d88c26d001764e3b224e9e6f2346791300624d348d825098bf1fedd658bcb3b66234c868144d83d6a8f6a02740dc36805cd765417af16f44ed6f4e6698ac647f
|
7
|
+
data.tar.gz: ced3406cfd86aed12bb5ca64ec7917cb9f3fdcbf20b29027c993b6e1402d793b2a5d5b9907c4de75cc293e04148f037208d232b7e7ed373b11d1d958a7e4f025
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
## [0.3.
|
1
|
+
## [0.3.2] - 2018-04-13
|
2
|
+
### Added
|
3
|
+
- `Cucumber` feature files are now part of the gem.
|
4
|
+
- Added `floatingpoint.feature` as test and demo for validating flating point numbers
|
5
|
+
|
6
|
+
|
7
|
+
## [0.3.1] - 2018-04-12
|
2
8
|
### Added
|
3
9
|
- Added `Cucumber` feature files both for additional testing and demo purposes.
|
4
10
|
Almost all examples from SRL websites are "featured".
|
data/cucumber.yml
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
Feature: Defining anchors as patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use basic SRL anchors patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining a begin anchor as pattern
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
begin with uppercase letter,
|
11
|
+
digit
|
12
|
+
"""
|
13
|
+
Then I expect the generated regular expression to be "^[A-Z]\d"
|
14
|
+
Then I expect matching for:
|
15
|
+
| "R2" |
|
16
|
+
| "A10" |
|
17
|
+
|
18
|
+
And I expect no match for:
|
19
|
+
| " R2 " |
|
20
|
+
| "r2 " |
|
21
|
+
| "%[_]" |
|
22
|
+
| "?;!" |
|
23
|
+
| "SRL" |
|
24
|
+
| "123" |
|
25
|
+
|
26
|
+
|
27
|
+
Scenario: defining a begin anchor as pattern (alternative syntax)
|
28
|
+
When I define the following SRL expression:
|
29
|
+
"""
|
30
|
+
starts with uppercase letter,
|
31
|
+
digit
|
32
|
+
"""
|
33
|
+
Then I expect the generated regular expression to be "^[A-Z]\d"
|
34
|
+
Then I expect matching for:
|
35
|
+
| "R2" |
|
36
|
+
| "A10" |
|
37
|
+
|
38
|
+
And I expect no match for:
|
39
|
+
| " R2 " |
|
40
|
+
| "r2 " |
|
41
|
+
|
42
|
+
|
43
|
+
Scenario: defining an end anchor as pattern
|
44
|
+
When I define the following SRL expression:
|
45
|
+
"""
|
46
|
+
uppercase letter,
|
47
|
+
digit,
|
48
|
+
must end
|
49
|
+
"""
|
50
|
+
Then I expect the generated regular expression to be "[A-Z]\d$"
|
51
|
+
Then I expect matching for:
|
52
|
+
| "r2-D2" |
|
53
|
+
| "! B1" |
|
54
|
+
|
55
|
+
And I expect no match for:
|
56
|
+
| " R2 " |
|
57
|
+
| " r2" |
|
58
|
+
| "%[_]" |
|
59
|
+
| "?;!" |
|
60
|
+
| "SRL" |
|
61
|
+
| "123" |
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Feature: Defining basic character patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use basic SRL character patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
# Reminder: in SRL, a character is either:
|
7
|
+
# a small letter [a-z]
|
8
|
+
# a capital letter [A-Z]
|
9
|
+
# a digit [0-9]
|
10
|
+
# an underscore '_'
|
11
|
+
Scenario: defining any character as pattern
|
12
|
+
When I define the following SRL expression:
|
13
|
+
"""
|
14
|
+
any character,
|
15
|
+
any character
|
16
|
+
"""
|
17
|
+
Then I expect the generated regular expression to be "\w\w"
|
18
|
+
Then I expect matching for:
|
19
|
+
| "srl" |
|
20
|
+
| "SRL" |
|
21
|
+
| "123" |
|
22
|
+
| " (red} " |
|
23
|
+
| "r_!" |
|
24
|
+
And I expect no match for:
|
25
|
+
| "B" |
|
26
|
+
| "%[_]"|
|
27
|
+
| "?;!" |
|
28
|
+
|
29
|
+
|
30
|
+
Scenario: defining any non-character as pattern
|
31
|
+
When I define the following SRL expression:
|
32
|
+
"""
|
33
|
+
no character
|
34
|
+
"""
|
35
|
+
Then I expect the generated regular expression to be "\W"
|
36
|
+
Then I expect matching for:
|
37
|
+
| "{}" |
|
38
|
+
| " (red} " |
|
39
|
+
| "r_!" |
|
40
|
+
And I expect no match for:
|
41
|
+
| "srl" |
|
42
|
+
| "SRL" |
|
43
|
+
| "123" |
|
44
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
Feature: Defining digit letter patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use basic SRL digit patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining any single digit as pattern
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
digit
|
11
|
+
"""
|
12
|
+
Then I expect the generated regular expression to be "\d"
|
13
|
+
Then I expect matching for:
|
14
|
+
| "123" |
|
15
|
+
| "THX1138" |
|
16
|
+
| " >red7: "|
|
17
|
+
And I expect no match for:
|
18
|
+
| "one" |
|
19
|
+
| "?;!" |
|
20
|
+
|
21
|
+
|
22
|
+
Scenario: using alternative syntax for any single digit
|
23
|
+
When I define the following SRL expression:
|
24
|
+
"""
|
25
|
+
number
|
26
|
+
"""
|
27
|
+
Then I expect the generated regular expression to be "\d"
|
28
|
+
Then I expect matching for:
|
29
|
+
| "123" |
|
30
|
+
| "THX1138" |
|
31
|
+
| " >red7: "|
|
32
|
+
And I expect no match for:
|
33
|
+
| "one" |
|
34
|
+
| "?;!" |
|
35
|
+
|
36
|
+
|
37
|
+
Scenario: defining a negated digit pattern
|
38
|
+
When I define the following SRL expression:
|
39
|
+
"""
|
40
|
+
no digit
|
41
|
+
"""
|
42
|
+
Then I expect the generated regular expression to be "\D"
|
43
|
+
Then I expect matching for:
|
44
|
+
| "a" |
|
45
|
+
| "two" |
|
46
|
+
| "B1" |
|
47
|
+
| " 1" |
|
48
|
+
And I expect no match for:
|
49
|
+
| "129" |
|
50
|
+
|
51
|
+
|
52
|
+
Scenario: defining any single digit from a given range as pattern
|
53
|
+
When I define the following SRL expression:
|
54
|
+
"""
|
55
|
+
digit from 3 to 8
|
56
|
+
"""
|
57
|
+
Then I expect the generated regular expression to be "[3-8]"
|
58
|
+
Then I expect matching for:
|
59
|
+
| "4" |
|
60
|
+
| "124" |
|
61
|
+
| "B52" |
|
62
|
+
And I expect no match for:
|
63
|
+
| "129" |
|
64
|
+
| "five"|
|
65
|
+
|
66
|
+
|
67
|
+
Scenario: using alternative syntax for any single digit from a given range
|
68
|
+
When I define the following SRL expression:
|
69
|
+
"""
|
70
|
+
number from 3 to 8
|
71
|
+
"""
|
72
|
+
Then I expect the generated regular expression to be "[3-8]"
|
73
|
+
Then I expect matching for:
|
74
|
+
| "4" |
|
75
|
+
| "124" |
|
76
|
+
| "B52" |
|
77
|
+
And I expect no match for:
|
78
|
+
| "129" |
|
79
|
+
| "five"|
|
80
|
+
|
81
|
+
|
82
|
+
Scenario: defining any single digit from a given scrambled range
|
83
|
+
When I define the following SRL expression:
|
84
|
+
"""
|
85
|
+
digit from 8 to 3
|
86
|
+
"""
|
87
|
+
Then I expect the generated regular expression to be "[3-8]"
|
88
|
+
Then I expect matching for:
|
89
|
+
| "4" |
|
90
|
+
| "124" |
|
91
|
+
| "B52" |
|
92
|
+
And I expect no match for:
|
93
|
+
| "129" |
|
94
|
+
| "five"|
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Feature: Defining basic letter patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use basic SRL letter patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining any small letter as pattern
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
letter,
|
11
|
+
letter
|
12
|
+
"""
|
13
|
+
Then I expect the generated regular expression to be "[a-z][a-z]"
|
14
|
+
Then I expect matching for:
|
15
|
+
| "srl" |
|
16
|
+
| "99 km" |
|
17
|
+
| " >red: " |
|
18
|
+
And I expect no match for:
|
19
|
+
| "123" |
|
20
|
+
| "ABC" |
|
21
|
+
| "f1" |
|
22
|
+
| "?;!" |
|
23
|
+
|
24
|
+
|
25
|
+
Scenario: defining one small letter from a given range as pattern
|
26
|
+
When I define the following SRL expression:
|
27
|
+
"""
|
28
|
+
letter from a to f
|
29
|
+
"""
|
30
|
+
Then I expect the generated regular expression to be "[a-f]"
|
31
|
+
Then I expect matching for:
|
32
|
+
| "b1" |
|
33
|
+
| "red" |
|
34
|
+
|" 12 cm"|
|
35
|
+
And I expect no match for:
|
36
|
+
| "123" |
|
37
|
+
| "z" |
|
38
|
+
| "12g3"|
|
39
|
+
|
40
|
+
|
41
|
+
Scenario: defining any capital letter as pattern
|
42
|
+
When I define the following SRL expression:
|
43
|
+
"""
|
44
|
+
uppercase letter
|
45
|
+
"""
|
46
|
+
Then I expect the generated regular expression to be "[A-Z]"
|
47
|
+
Then I expect matching for:
|
48
|
+
| "Ruby" |
|
49
|
+
| "99 Km" |
|
50
|
+
| " >OFF: " |
|
51
|
+
And I expect no match for:
|
52
|
+
| "123" |
|
53
|
+
| "abc" |
|
54
|
+
| "?;!" |
|
55
|
+
|
56
|
+
|
57
|
+
Scenario: defining one capital letter from a given range as pattern
|
58
|
+
When I define the following SRL expression:
|
59
|
+
"""
|
60
|
+
uppercase letter from X to Z
|
61
|
+
"""
|
62
|
+
Then I expect the generated regular expression to be "[X-Z]"
|
63
|
+
Then I expect matching for:
|
64
|
+
| "Yes" |
|
65
|
+
| ">Zulu" |
|
66
|
+
|" 123 wHY"|
|
67
|
+
And I expect no match for:
|
68
|
+
| "yES" |
|
69
|
+
| "123" |
|
70
|
+
| "12f3"|
|
71
|
+
|
72
|
+
|
73
|
+
Scenario: defining one small letter from a scrambled range as pattern
|
74
|
+
When I define the following SRL expression:
|
75
|
+
"""
|
76
|
+
letter from d to a
|
77
|
+
"""
|
78
|
+
Then I expect the generated regular expression to be "[a-d]"
|
79
|
+
Then I expect matching for:
|
80
|
+
| "b1" |
|
81
|
+
And I expect no match for:
|
82
|
+
| "123" |
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Feature: Defining literal strings as patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use basic SRL literal strings patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining a literal string as pattern
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
literally "aba"
|
11
|
+
"""
|
12
|
+
Then I expect the generated regular expression to be "aba"
|
13
|
+
Then I expect matching for:
|
14
|
+
| "nabab " |
|
15
|
+
| "alibaba" |
|
16
|
+
| "<abakka>" |
|
17
|
+
|
18
|
+
And I expect no match for:
|
19
|
+
| "a ba"|
|
20
|
+
| "%[_]"|
|
21
|
+
| "?;!" |
|
22
|
+
| "srl" |
|
23
|
+
| "SRL" |
|
24
|
+
| "123" |
|
25
|
+
|
26
|
+
|
27
|
+
Scenario: defining a character from a set as pattern
|
28
|
+
When I define the following SRL expression:
|
29
|
+
"""
|
30
|
+
one of "13579"
|
31
|
+
"""
|
32
|
+
Then I expect the generated regular expression to be "[13579]"
|
33
|
+
Then I expect matching for:
|
34
|
+
| "NCC-1701-A" |
|
35
|
+
| "even24685" |
|
36
|
+
|
37
|
+
And I expect no match for:
|
38
|
+
| "a ba"|
|
39
|
+
| "%[_]"|
|
40
|
+
| "?;!" |
|
41
|
+
| "srl" |
|
42
|
+
| "SRL" |
|
43
|
+
| "246" |
|
44
|
+
|
45
|
+
|
46
|
+
Scenario: defining a character not from a given set
|
47
|
+
When I define the following SRL expression:
|
48
|
+
"""
|
49
|
+
none of "13579"
|
50
|
+
"""
|
51
|
+
Then I expect the generated regular expression to be "[^13579]"
|
52
|
+
Then I expect matching for:
|
53
|
+
| "42" |
|
54
|
+
| "text" |
|
55
|
+
| "%[_]?" |
|
56
|
+
|
57
|
+
And I expect no match for:
|
58
|
+
| "13" |
|
@@ -0,0 +1,180 @@
|
|
1
|
+
Feature: Defining quntifiers for patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use quantifiers for patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: Repeat a pattern an exact number of times
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
(uppercase letter,
|
11
|
+
digit) exactly 2 times
|
12
|
+
"""
|
13
|
+
Then I expect the generated regular expression to be "(?:[A-Z]\d){2}"
|
14
|
+
Then I expect matching for:
|
15
|
+
| "R2D2" |
|
16
|
+
|
17
|
+
And I expect no match for:
|
18
|
+
| "r2D2"|
|
19
|
+
| "%[_]"|
|
20
|
+
| "?;!" |
|
21
|
+
| "SRL" |
|
22
|
+
| "123" |
|
23
|
+
|
24
|
+
|
25
|
+
Scenario: Repeat a pattern a number from range
|
26
|
+
When I define the following SRL expression:
|
27
|
+
"""
|
28
|
+
begin with
|
29
|
+
(uppercase letter,
|
30
|
+
digit) between 2 and 4 times
|
31
|
+
must end
|
32
|
+
"""
|
33
|
+
Then I expect the generated regular expression to be "^(?:[A-Z]\d){2,4}$"
|
34
|
+
Then I expect matching for:
|
35
|
+
| "R2D2" |
|
36
|
+
| "A1B2C3" |
|
37
|
+
| "A1B2C3D4" |
|
38
|
+
|
39
|
+
And I expect no match for:
|
40
|
+
| "R2" |
|
41
|
+
| "R2d2" |
|
42
|
+
| "A1B2C3D4E5" |
|
43
|
+
| "%[_]" |
|
44
|
+
| "?;!" |
|
45
|
+
| "SRL" |
|
46
|
+
| "123" |
|
47
|
+
|
48
|
+
|
49
|
+
Scenario: Repeat a pattern a number from range (without 'times' keyword)
|
50
|
+
When I define the following SRL expression:
|
51
|
+
"""
|
52
|
+
begin with
|
53
|
+
(uppercase letter,
|
54
|
+
digit) between 2 and 4
|
55
|
+
must end
|
56
|
+
"""
|
57
|
+
Then I expect the generated regular expression to be "^(?:[A-Z]\d){2,4}$"
|
58
|
+
Then I expect matching for:
|
59
|
+
| "R2D2" |
|
60
|
+
| "A1B2C3" |
|
61
|
+
| "A1B2C3D4" |
|
62
|
+
|
63
|
+
And I expect no match for:
|
64
|
+
| "R2" |
|
65
|
+
| "R2d2" |
|
66
|
+
| "A1B2C3D4E5" |
|
67
|
+
| "%[_]" |
|
68
|
+
| "?;!" |
|
69
|
+
| "SRL" |
|
70
|
+
| "123" |
|
71
|
+
|
72
|
+
|
73
|
+
Scenario: Repeat a pattern zero or one times
|
74
|
+
When I define the following SRL expression:
|
75
|
+
"""
|
76
|
+
begin with one of "+-" optional,
|
77
|
+
digit
|
78
|
+
"""
|
79
|
+
Then I expect the generated regular expression to be "^[+\-]?\d"
|
80
|
+
Then I expect matching for:
|
81
|
+
| "42 " |
|
82
|
+
| "+42 " |
|
83
|
+
| "-42 " |
|
84
|
+
| "99 bottles" |
|
85
|
+
|
86
|
+
And I expect no match for:
|
87
|
+
| "R2" |
|
88
|
+
| "++42" |
|
89
|
+
|
90
|
+
|
91
|
+
Scenario: Repeat a pattern zero or more times
|
92
|
+
When I define the following SRL expression:
|
93
|
+
"""
|
94
|
+
begin with one of "+-" optional,
|
95
|
+
digit never or more,
|
96
|
+
letter
|
97
|
+
"""
|
98
|
+
Then I expect the generated regular expression to be "^[+\-]?\d*[a-z]"
|
99
|
+
Then I expect matching for:
|
100
|
+
| "42cm " |
|
101
|
+
| "+42cm " |
|
102
|
+
| "-42cm " |
|
103
|
+
| "50cents" |
|
104
|
+
| "cents" |
|
105
|
+
| "-cents" |
|
106
|
+
|
107
|
+
And I expect no match for:
|
108
|
+
| "++42" |
|
109
|
+
| "+42Km" |
|
110
|
+
|
111
|
+
|
112
|
+
Scenario: Repeat a pattern one or more times
|
113
|
+
When I define the following SRL expression:
|
114
|
+
"""
|
115
|
+
begin with one of "+-" optional,
|
116
|
+
digit once or more,
|
117
|
+
letter
|
118
|
+
"""
|
119
|
+
Then I expect the generated regular expression to be "^[+\-]?\d+[a-z]"
|
120
|
+
Then I expect matching for:
|
121
|
+
| "42cm " |
|
122
|
+
| "+42cm " |
|
123
|
+
| "-42cm " |
|
124
|
+
| "50cents" |
|
125
|
+
|
126
|
+
And I expect no match for:
|
127
|
+
| "++42" |
|
128
|
+
| "+42Km" |
|
129
|
+
| "cents" |
|
130
|
+
| "-cents" |
|
131
|
+
|
132
|
+
|
133
|
+
Scenario: Repeat a pattern n times or more
|
134
|
+
When I define the following SRL expression:
|
135
|
+
"""
|
136
|
+
begin with letter at least 2 times,
|
137
|
+
must end
|
138
|
+
"""
|
139
|
+
Then I expect the generated regular expression to be "^[a-z]{2,}$"
|
140
|
+
Then I expect matching for:
|
141
|
+
| "ab" |
|
142
|
+
| "abcdef" |
|
143
|
+
|
144
|
+
And I expect no match for:
|
145
|
+
| "a" |
|
146
|
+
|
147
|
+
|
148
|
+
# This one won't very much in use
|
149
|
+
Scenario: Repeat a pattern exactly once
|
150
|
+
When I define the following SRL expression:
|
151
|
+
"""
|
152
|
+
begin with (uppercase letter, digit) once,
|
153
|
+
must end
|
154
|
+
"""
|
155
|
+
Then I expect the generated regular expression to be "^(?:[A-Z]\d){1}$"
|
156
|
+
Then I expect matching for:
|
157
|
+
| "R2" |
|
158
|
+
|
159
|
+
And I expect no match for:
|
160
|
+
| "r2" |
|
161
|
+
| "R2D2" |
|
162
|
+
|
163
|
+
|
164
|
+
Scenario: Repeat a pattern twice
|
165
|
+
When I define the following SRL expression:
|
166
|
+
"""
|
167
|
+
begin with (uppercase letter, digit,
|
168
|
+
literally "-" optional) twice,
|
169
|
+
must end
|
170
|
+
"""
|
171
|
+
Then I expect the generated regular expression to be "^(?:[A-Z]\d-?){2}$"
|
172
|
+
Then I expect matching for:
|
173
|
+
| "R2D2" |
|
174
|
+
| "R2-D2" |
|
175
|
+
| "R2-D2-" |
|
176
|
+
|
177
|
+
And I expect no match for:
|
178
|
+
| "r2d2" |
|
179
|
+
| "R2D2E3" |
|
180
|
+
| "R2--D2" |
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: Defining regular expression as pattern
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to embed regex expression in SRL
|
4
|
+
So that I can use them when crafting complex regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining a literal string as pattern
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
letter,
|
11
|
+
raw "[^1-4]"
|
12
|
+
"""
|
13
|
+
Then I expect the generated regular expression to be "[a-z][^1-4]"
|
14
|
+
Then I expect matching for:
|
15
|
+
| " b52 " |
|
16
|
+
| "road66" |
|
17
|
+
| "a " |
|
18
|
+
|
19
|
+
And I expect no match for:
|
20
|
+
| "%[_]"|
|
21
|
+
| "?;!" |
|
22
|
+
| "12b" |
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Feature: Defining basic special character patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use basic SRL special character patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining any whitespace as pattern
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
whitespace,
|
11
|
+
whitespace
|
12
|
+
"""
|
13
|
+
Then I expect the generated regular expression to be "\s\s"
|
14
|
+
Then I expect matching for:
|
15
|
+
| "two spaces> " |
|
16
|
+
| " <two spaces" |
|
17
|
+
| " two> spaces" |
|
18
|
+
|
19
|
+
And I expect no match for:
|
20
|
+
| "B" |
|
21
|
+
| "%[_]"|
|
22
|
+
| "?;!" |
|
23
|
+
| "srl" |
|
24
|
+
| "SRL" |
|
25
|
+
| "123" |
|
26
|
+
|
27
|
+
|
28
|
+
Scenario: defining any non-whitespace as pattern
|
29
|
+
When I define the following SRL expression:
|
30
|
+
"""
|
31
|
+
no whitespace
|
32
|
+
"""
|
33
|
+
Then I expect the generated regular expression to be "\S"
|
34
|
+
Then I expect matching for:
|
35
|
+
| "{}" |
|
36
|
+
| " (red} " |
|
37
|
+
| "r_!" |
|
38
|
+
And I expect no match for:
|
39
|
+
| " " |
|
40
|
+
|
41
|
+
|
42
|
+
Scenario: defining a backslash as pattern
|
43
|
+
When I define the following SRL expression:
|
44
|
+
"""
|
45
|
+
backslash
|
46
|
+
"""
|
47
|
+
Then I expect the generated regular expression to be "\\"
|
48
|
+
Then I expect matching for:
|
49
|
+
| " \ " |
|
50
|
+
| "{}\ " |
|
51
|
+
And I expect no match for:
|
52
|
+
| " " |
|
53
|
+
| "B" |
|
54
|
+
| "%[_]"|
|
55
|
+
| "?;!" |
|
56
|
+
| "srl" |
|
57
|
+
| "SRL" |
|
58
|
+
| "123" |
|
59
|
+
|
60
|
+
Scenario: defining a tab as pattern
|
61
|
+
When I define the following SRL expression:
|
62
|
+
"""
|
63
|
+
tab
|
64
|
+
"""
|
65
|
+
Then I expect the generated regular expression to be "\t"
|
66
|
+
|
67
|
+
|
68
|
+
Scenario: defining a vertical tab as pattern
|
69
|
+
When I define the following SRL expression:
|
70
|
+
"""
|
71
|
+
vertical tab
|
72
|
+
"""
|
73
|
+
Then I expect the generated regular expression to be "\v"
|
74
|
+
|
75
|
+
|
76
|
+
Scenario: defining a newline as pattern
|
77
|
+
When I define the following SRL expression:
|
78
|
+
"""
|
79
|
+
new line
|
80
|
+
"""
|
81
|
+
Then I expect the generated regular expression to be "\n"
|
82
|
+
|
83
|
+
|
84
|
+
Scenario: defining a carriage return as pattern
|
85
|
+
When I define the following SRL expression:
|
86
|
+
"""
|
87
|
+
carriage return
|
88
|
+
"""
|
89
|
+
Then I expect the generated regular expression to be "\r"
|
90
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
Feature: Defining an email validation pattern
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use SRL to specify valid email address pattern
|
4
|
+
So that I can use its regex representation in my code
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining email validating expression
|
8
|
+
# The expression isn't 100 reliable but suffice in a vast majority of cases
|
9
|
+
When I define the following SRL expression:
|
10
|
+
"""
|
11
|
+
begin with any of (digit, letter, one of "._%+-") once or more,
|
12
|
+
literally "@",
|
13
|
+
any of (digit, letter, one of ".-") once or more,
|
14
|
+
( literally ".",
|
15
|
+
letter at least 2 times ) optional,
|
16
|
+
must end,
|
17
|
+
case insensitive
|
18
|
+
"""
|
19
|
+
Then I expect the generated regular expression to be "^(?:\d|[a-z]|[._%+\-])+@(?:\d|[a-z]|[.\-])+(?:\.[a-z]{2,})?$"
|
20
|
+
Then I expect matching for:
|
21
|
+
| s@example.com |
|
22
|
+
| simple@example.com |
|
23
|
+
| john.doe@example.com |
|
24
|
+
| disposable.style.email.with+symbol@example.com |
|
25
|
+
| other.email-with-dash@example.com |
|
26
|
+
| fully-qualified-domain@example.com |
|
27
|
+
| user.name+tag+sorting@example.com |
|
28
|
+
| example-indeed@strange-example.com |
|
29
|
+
| example@s.solutions |
|
30
|
+
| user@localserver |
|
31
|
+
|
32
|
+
And I expect no match for:
|
33
|
+
| admin.example.com |
|
34
|
+
| @office.info.com |
|
35
|
+
| method()*@example.com |
|
36
|
+
| a@b@c@example.com |
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Feature: Defining a floating-point number pattern
|
2
|
+
As a Rubyist,
|
3
|
+
I want to use SRL to specify a pattern for floating points
|
4
|
+
So that I can use its regex representation in my code
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining a floating-point number expression
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
begin with one of "-+" optional,
|
11
|
+
digit once or more,
|
12
|
+
literally "." optional,
|
13
|
+
digit never or more,
|
14
|
+
(
|
15
|
+
one of "eE",
|
16
|
+
one of "-+" optional,
|
17
|
+
digit once or more
|
18
|
+
) optional,
|
19
|
+
must end
|
20
|
+
"""
|
21
|
+
Then I expect the generated regular expression to be "^[\-+]?\d+\.?\d*(?:[eE][\-+]?\d+)?$"
|
22
|
+
Then I expect matching for:
|
23
|
+
| 1 |
|
24
|
+
| +2 |
|
25
|
+
| -3 |
|
26
|
+
| +5. |
|
27
|
+
| -6. |
|
28
|
+
| 7.123 |
|
29
|
+
| 8.123E3 |
|
30
|
+
| 9.123e-4 |
|
31
|
+
|
32
|
+
And I expect no match for:
|
33
|
+
| text |
|
34
|
+
| 1c |
|
35
|
+
| 1,5 |
|
36
|
+
| 3E3+5 |
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Feature: Defining alternation as patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use alternation combine patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
capture (any of (literally "sample", (digit once or more)))
|
11
|
+
"""
|
12
|
+
|
13
|
+
|
14
|
+
Scenario: defining an alternation as pattern
|
15
|
+
Then I expect the generated regular expression to be "((?:sample|(?:\d+)))"
|
16
|
+
Then I expect matching for:
|
17
|
+
| "two samples " |
|
18
|
+
| " 1234" |
|
19
|
+
| " sample 42" |
|
20
|
+
|
21
|
+
And I expect no match for:
|
22
|
+
| "a ba"|
|
23
|
+
| "%[_]"|
|
24
|
+
| "?;!" |
|
25
|
+
| "srl" |
|
26
|
+
|
27
|
+
|
28
|
+
Scenario: capturing an alternation
|
29
|
+
When I use the text "sample 42"
|
30
|
+
Then I expect the first capture to be:
|
31
|
+
| 0 | sample |
|
32
|
+
And I expect the second capture to be:
|
33
|
+
| 0 | 42 |
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
Feature: Defining capture patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use intermediate SRL capture patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: using named captures
|
8
|
+
Given I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
capture (anything once or more) as "first",
|
11
|
+
literally " - ",
|
12
|
+
capture (literally "second part") as "second"
|
13
|
+
"""
|
14
|
+
When I use the text "first part - second part"
|
15
|
+
Then I expect the first captures to be:
|
16
|
+
|first | first part |
|
17
|
+
|second| second part |
|
18
|
+
|
19
|
+
|
20
|
+
Scenario: using anonymous captures
|
21
|
+
Given I define the following SRL expression:
|
22
|
+
"""
|
23
|
+
capture (anything once or more),
|
24
|
+
literally " - ",
|
25
|
+
capture (literally "second part")
|
26
|
+
"""
|
27
|
+
When I use the text "first part - second part"
|
28
|
+
Then I expect the first captures to be:
|
29
|
+
| 0 | first part |
|
30
|
+
| 1 | second part |
|
31
|
+
|
32
|
+
|
33
|
+
Scenario: using capture ... until
|
34
|
+
Given I define the following SRL expression:
|
35
|
+
"""
|
36
|
+
begin with capture (
|
37
|
+
anything once or more
|
38
|
+
) until literally "m"
|
39
|
+
"""
|
40
|
+
When I use the text "this is an example"
|
41
|
+
Then I expect the first capture to be:
|
42
|
+
| 0 | this is an exa |
|
43
|
+
|
44
|
+
|
45
|
+
Scenario: using any of
|
46
|
+
Given I define the following SRL expression:
|
47
|
+
"""
|
48
|
+
capture (any of (literally "sample", (digit once or more)))
|
49
|
+
"""
|
50
|
+
When I use the text "sample && 1234"
|
51
|
+
Then I expect the first captures to be:
|
52
|
+
| 0 | sample |
|
53
|
+
| 1 | 1234 |
|
54
|
+
|
55
|
+
|
56
|
+
Scenario: using either of (synonym of any of)
|
57
|
+
Given I define the following SRL expression:
|
58
|
+
"""
|
59
|
+
capture (either of (literally "sample", (digit once or more)))
|
60
|
+
"""
|
61
|
+
When I use the text "sample && 1234"
|
62
|
+
Then I expect the first captures to be:
|
63
|
+
| 0 | sample |
|
64
|
+
| 1 | 1234 |
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: Defining lookaround patterns
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use intermediate SRL lookaround patterns
|
4
|
+
So that I can use them when crafting my regular expressions
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: using if not followed lookforward
|
8
|
+
Given I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
capture (digit) if followed by (anything once or more, digit)
|
11
|
+
"""
|
12
|
+
When I use the text "This example contains 3 numbers. 2 should not match. Only 1 should."
|
13
|
+
Then I expect the first capture to be:
|
14
|
+
| 0 | 3 |
|
15
|
+
And I expect the second capture to be:
|
16
|
+
| 0 | 2 |
|
17
|
+
|
18
|
+
|
19
|
+
Scenario: using if not followed lookforward
|
20
|
+
Given I define the following SRL expression:
|
21
|
+
"""
|
22
|
+
capture (digit) if not followed by (anything once or more, digit)
|
23
|
+
"""
|
24
|
+
When I use the text "This example contains 3 numbers. 2 should not match. Only 1 should."
|
25
|
+
Then I expect the first capture to be:
|
26
|
+
| 0 | 1 |
|
27
|
+
|
28
|
+
|
29
|
+
Scenario: using if already had
|
30
|
+
Given I define the following SRL expression:
|
31
|
+
"""
|
32
|
+
capture (literally "bar") if already had literally "foo"
|
33
|
+
"""
|
34
|
+
Then I expect no match for:
|
35
|
+
| "fobar"|
|
36
|
+
When I use the text "foobar"
|
37
|
+
Then I expect the first capture to be:
|
38
|
+
| 0 | bar |
|
39
|
+
|
40
|
+
|
41
|
+
Scenario: using if already had
|
42
|
+
Given I define the following SRL expression:
|
43
|
+
"""
|
44
|
+
capture (literally "bar") if not already had literally "foo"
|
45
|
+
"""
|
46
|
+
Then I expect no match for:
|
47
|
+
| "foobar"|
|
48
|
+
When I use the text "fobar"
|
49
|
+
Then I expect the first capture to be:
|
50
|
+
| 0 | bar |
|
51
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
When("I define the following SRL expression:") do |srl_source|
|
2
|
+
@regex = SrlRuby::parse(srl_source)
|
3
|
+
end
|
4
|
+
|
5
|
+
When("I use the text {string}") do |test_string|
|
6
|
+
@subject = test_string
|
7
|
+
end
|
8
|
+
|
9
|
+
Then("I expect the generated regular expression to be {string}") do |regex_source|
|
10
|
+
expect(@regex.source).to eq(regex_source)
|
11
|
+
end
|
12
|
+
|
13
|
+
Then("I expect matching for:") do |table|
|
14
|
+
# table is a Cucumber::MultilineArgument::DataTable
|
15
|
+
values = table.raw.flatten.map { |raw_val| raw_val.gsub(/^"|"$/, '') }
|
16
|
+
values.each do |val|
|
17
|
+
expect(val).to match(@regex)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Then("I expect no match for:") do |table|
|
22
|
+
# table is a Cucumber::MultilineArgument::DataTable
|
23
|
+
values = table.raw.flatten.map { |raw_val| raw_val.gsub(/^"|"$/, '') }
|
24
|
+
values.each do |val|
|
25
|
+
expect(val).not_to match(@regex)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
Then(/I expect the (first|second|third|fourth|fifth) captures? to be:/) do |rank_literal, table|
|
31
|
+
ordinal2indices = { 'first' => 0,
|
32
|
+
'second' => 1,
|
33
|
+
'third' => 2,
|
34
|
+
'fourth' => 3,
|
35
|
+
'fifth' => 4
|
36
|
+
}
|
37
|
+
rank = ordinal2indices[rank_literal]
|
38
|
+
# table is a Cucumber::MultilineArgument::DataTable
|
39
|
+
expectations = table.rows_hash
|
40
|
+
|
41
|
+
scan_results = @subject.scan(@regex)
|
42
|
+
actuals = scan_results[rank]
|
43
|
+
if actuals.nil?
|
44
|
+
puts "Big issue"
|
45
|
+
puts @regex.source
|
46
|
+
end
|
47
|
+
|
48
|
+
if @regex.names.empty?
|
49
|
+
capture_names = (0..actuals.size-1).to_a.map(&:to_s)
|
50
|
+
else
|
51
|
+
capture_names = @regex.names
|
52
|
+
end
|
53
|
+
|
54
|
+
capture_names.each_with_index do |var_name, index|
|
55
|
+
if expectations.include?(var_name)
|
56
|
+
expect(expectations[var_name]).to eq(actuals[index])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Feature: Defining a password validation pattern
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use SRL to specify password pattern
|
4
|
+
So that I can use its regex representation in my code
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining a password validation expression
|
8
|
+
When I define the following SRL expression:
|
9
|
+
"""
|
10
|
+
if followed by (anything never or more, letter),
|
11
|
+
if followed by (anything never or more, uppercase letter),
|
12
|
+
if followed by (anything never or more, digit),
|
13
|
+
if followed by (anything never or more, one of "!@#$%^&*[]\"';:_-<>., =+/\\"),
|
14
|
+
anything at least 8 times
|
15
|
+
"""
|
16
|
+
Then I expect matching for:
|
17
|
+
| Sup3r $ecure! |
|
18
|
+
| P@sSword1 |
|
19
|
+
| Pass-w0rd |
|
20
|
+
|
21
|
+
And I expect no match for:
|
22
|
+
| Password |
|
23
|
+
| P@sS1 |
|
24
|
+
| justalongpassword |
|
25
|
+
| m1ss1ng upper |
|
26
|
+
| missing Number |
|
27
|
+
| M1SS1NG LOWER |
|
28
|
+
| m1ss1ngSpec1al |
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Feature: Defining an email validation pattern
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use SRL to specify valid email address pattern
|
4
|
+
So that I can use its regex representation in my code
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I define the following SRL expression:
|
8
|
+
"""
|
9
|
+
begin with capture (letter once or more) as "protocol",
|
10
|
+
literally "://",
|
11
|
+
capture (
|
12
|
+
letter once or more,
|
13
|
+
any of (letter, literally ".") once or more,
|
14
|
+
letter at least 2 times
|
15
|
+
) as "domain",
|
16
|
+
(literally ":", capture (digit once or more) as "port") optional,
|
17
|
+
capture (literally "/", anything never or more) as "path" until (any of (literally "?", must end)),
|
18
|
+
literally "?" optional,
|
19
|
+
capture (anything never or more) as "parameters" optional,
|
20
|
+
must end,
|
21
|
+
case insensitive
|
22
|
+
"""
|
23
|
+
|
24
|
+
Scenario: defining url capturing expression
|
25
|
+
When I use the text "https://example.domain.com:1234/a/path?query=param"
|
26
|
+
Then I expect the first capture to be:
|
27
|
+
| protocol | https |
|
28
|
+
| domain | example.domain.com |
|
29
|
+
| port | 1234 |
|
30
|
+
| path | /a/path |
|
31
|
+
| parameters | query=param |
|
data/lib/srl_ruby/version.rb
CHANGED
data/srl_ruby.gemspec
CHANGED
@@ -10,6 +10,7 @@ module PkgExtending
|
|
10
10
|
'.rspec',
|
11
11
|
'.yardopts',
|
12
12
|
'appveyor.yml',
|
13
|
+
'cucumber.yml',
|
13
14
|
'Gemfile',
|
14
15
|
'Rakefile',
|
15
16
|
'CHANGELOG.md',
|
@@ -19,6 +20,9 @@ module PkgExtending
|
|
19
20
|
'lib/*.*',
|
20
21
|
'lib/**/*.rb',
|
21
22
|
'spec/**/*.rb',
|
23
|
+
'features/*.*',
|
24
|
+
'features/**/*.*',
|
25
|
+
'features/**/**/*.features',
|
22
26
|
'srl_test/**/*.*'
|
23
27
|
]
|
24
28
|
aPackage.files = file_list
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srl_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|
@@ -99,6 +99,24 @@ files:
|
|
99
99
|
- Rakefile
|
100
100
|
- appveyor.yml
|
101
101
|
- bin/srl_ruby
|
102
|
+
- cucumber.yml
|
103
|
+
- features/basic/anchors.feature
|
104
|
+
- features/basic/characters.feature
|
105
|
+
- features/basic/digits.feature
|
106
|
+
- features/basic/letters.feature
|
107
|
+
- features/basic/literally.feature
|
108
|
+
- features/basic/quantifiers.feature
|
109
|
+
- features/basic/raw.feature
|
110
|
+
- features/basic/special_characters.feature
|
111
|
+
- features/email_validation.feature
|
112
|
+
- features/floatingpoint.feature
|
113
|
+
- features/intermediate/any_of.feature
|
114
|
+
- features/intermediate/capture.feature
|
115
|
+
- features/intermediate/lookaround.feature
|
116
|
+
- features/lib/step_definitions/srl_testing_steps.rb
|
117
|
+
- features/lib/support/env..rb
|
118
|
+
- features/password_validation.feature
|
119
|
+
- features/url_capturing.feature
|
102
120
|
- lib/regex/abstract_method.rb
|
103
121
|
- lib/regex/alternation.rb
|
104
122
|
- lib/regex/anchor.rb
|