Skip to content

Commit 85d46d5

Browse files
authored
C++: Add coverage for lazy quantifiers and \f/\v escapes
1 parent e631b08 commit 85d46d5

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

cpp/ql/test/library-tests/regex/parse.expected

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626

2727
#-----| [RegExpConstant, RegExpNormalChar] b
2828

29+
#-----| [RegExpConstant, RegExpEscape] \f
30+
31+
#-----| [RegExpConstant, RegExpEscape] \v
32+
33+
#-----| [RegExpConstant, RegExpNormalChar] d
34+
35+
#-----| [RegExpConstant, RegExpNormalChar] c
36+
37+
#-----| [RegExpConstant, RegExpNormalChar] b
38+
39+
#-----| [RegExpConstant, RegExpNormalChar] a
40+
2941
#-----| [RegExpConstant, RegExpEscape] \0
3042

3143
#-----| [RegExpConstant, RegExpEscape] \0
@@ -187,6 +199,10 @@
187199
#-----| 1 -> [RegExpConstant, RegExpEscape] \n
188200
#-----| 2 -> [RegExpConstant, RegExpNormalChar] b
189201

202+
#-----| [RegExpSequence] \f\v
203+
#-----| 0 -> [RegExpConstant, RegExpEscape] \f
204+
#-----| 1 -> [RegExpConstant, RegExpEscape] \v
205+
190206
#-----| [RegExpSequence] [A-F[[=b=]]a-f]
191207
#-----| 0 -> [RegExpCharacterClass] [A-F[[=b=]]
192208
#-----| 1 -> [RegExpConstant, RegExpNormalChar] a-f]
@@ -409,6 +425,18 @@
409425
#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo
410426
#-----| 1 -> [RegExpConstant, RegExpNormalChar] bar
411427

428+
#-----| [RegExpQuantifier] d{2,3}?
429+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] d
430+
431+
#-----| [RegExpOpt] c??
432+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] c
433+
434+
#-----| [RegExpPlus] b+?
435+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] b
436+
437+
#-----| [RegExpStar] a*?
438+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] a
439+
412440
#-----| [RegExpPlus] a+
413441
#-----| 0 -> [RegExpConstant, RegExpNormalChar] a
414442

cpp/ql/test/library-tests/regex/regexp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ std::regex r_ctrl2("[\\cZ]");
9292
std::regex r_nul1("\\0");
9393
std::regex r_nul2("[\\0]");
9494

95+
// Lazy quantifiers and additional supported escapes
96+
std::regex r_lazy1("a*?");
97+
std::regex r_lazy2("b+?");
98+
std::regex r_lazy3("c??");
99+
std::regex r_lazy4("d{2,3}?");
100+
std::regex r_fv("\\f\\v");
101+
95102
// String literal spellings for location tests
96103
std::regex r_loc_plain("a\\nb");
97104
std::basic_regex<wchar_t> r_loc_L(L"abc");

cpp/ql/test/library-tests/regex/regexp.expected

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ term
9393
| file://:0:0:0:0 | \\cZ | RegExpConstant,RegExpEscape |
9494
| file://:0:0:0:0 | \\d | RegExpCharacterClassEscape |
9595
| file://:0:0:0:0 | \\d\\D | RegExpSequence |
96+
| file://:0:0:0:0 | \\f | RegExpConstant,RegExpEscape |
97+
| file://:0:0:0:0 | \\f\\v | RegExpSequence |
9698
| file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape |
9799
| file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape |
98100
| file://:0:0:0:0 | \\n\\r\\t | RegExpSequence |
@@ -101,6 +103,7 @@ term
101103
| file://:0:0:0:0 | \\s\\S | RegExpSequence |
102104
| file://:0:0:0:0 | \\t | RegExpConstant,RegExpEscape |
103105
| file://:0:0:0:0 | \\u0061 | RegExpConstant,RegExpEscape |
106+
| file://:0:0:0:0 | \\v | RegExpConstant,RegExpEscape |
104107
| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape |
105108
| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape |
106109
| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape |
@@ -122,7 +125,9 @@ term
122125
| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar |
123126
| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar |
124127
| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar |
128+
| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar |
125129
| file://:0:0:0:0 | a* | RegExpStar |
130+
| file://:0:0:0:0 | a*? | RegExpStar |
126131
| file://:0:0:0:0 | a*b+c?d | RegExpSequence |
127132
| file://:0:0:0:0 | a+ | RegExpPlus |
128133
| file://:0:0:0:0 | a-f | RegExpCharacterRange |
@@ -155,15 +160,21 @@ term
155160
| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar |
156161
| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar |
157162
| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar |
163+
| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar |
158164
| file://:0:0:0:0 | b+ | RegExpPlus |
159165
| file://:0:0:0:0 | b+ | RegExpPlus |
166+
| file://:0:0:0:0 | b+? | RegExpPlus |
160167
| file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar |
161168
| file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar |
162169
| file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar |
163170
| file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar |
171+
| file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar |
164172
| file://:0:0:0:0 | c? | RegExpOpt |
173+
| file://:0:0:0:0 | c?? | RegExpOpt |
165174
| file://:0:0:0:0 | cd | RegExpConstant,RegExpNormalChar |
166175
| file://:0:0:0:0 | d | RegExpConstant,RegExpNormalChar |
176+
| file://:0:0:0:0 | d | RegExpConstant,RegExpNormalChar |
177+
| file://:0:0:0:0 | d{2,3}? | RegExpQuantifier |
167178
| file://:0:0:0:0 | e | RegExpConstant,RegExpNormalChar |
168179
| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar |
169180
| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar |
@@ -208,12 +219,14 @@ regExpNormalCharValue
208219
| file://:0:0:0:0 | \\cA | cA |
209220
| file://:0:0:0:0 | \\cZ | cZ |
210221
| file://:0:0:0:0 | \\d | d |
222+
| file://:0:0:0:0 | \\f | \u000c |
211223
| file://:0:0:0:0 | \\n | \n |
212224
| file://:0:0:0:0 | \\n | \n |
213225
| file://:0:0:0:0 | \\r | \r |
214226
| file://:0:0:0:0 | \\s | s |
215227
| file://:0:0:0:0 | \\t | \t |
216228
| file://:0:0:0:0 | \\u0061 | a |
229+
| file://:0:0:0:0 | \\v | \u000b |
217230
| file://:0:0:0:0 | \\w | w |
218231
| file://:0:0:0:0 | \\w | w |
219232
| file://:0:0:0:0 | \\w | w |
@@ -233,6 +246,7 @@ regExpNormalCharValue
233246
| file://:0:0:0:0 | a | a |
234247
| file://:0:0:0:0 | a | a |
235248
| file://:0:0:0:0 | a | a |
249+
| file://:0:0:0:0 | a | a |
236250
| file://:0:0:0:0 | a-f] | a-f] |
237251
| file://:0:0:0:0 | a-f] | a-f] |
238252
| file://:0:0:0:0 | abc | abc |
@@ -254,12 +268,15 @@ regExpNormalCharValue
254268
| file://:0:0:0:0 | b | b |
255269
| file://:0:0:0:0 | b | b |
256270
| file://:0:0:0:0 | b | b |
271+
| file://:0:0:0:0 | b | b |
257272
| file://:0:0:0:0 | bar | bar |
258273
| file://:0:0:0:0 | bar | bar |
259274
| file://:0:0:0:0 | c | c |
260275
| file://:0:0:0:0 | c | c |
276+
| file://:0:0:0:0 | c | c |
261277
| file://:0:0:0:0 | cd | cd |
262278
| file://:0:0:0:0 | d | d |
279+
| file://:0:0:0:0 | d | d |
263280
| file://:0:0:0:0 | e | e |
264281
| file://:0:0:0:0 | f | f |
265282
| file://:0:0:0:0 | f | f |

0 commit comments

Comments
 (0)