Skip to content

Commit cd1e73b

Browse files
committed
Swift: Add some more test cases.
1 parent dc5f964 commit cd1e73b

File tree

2 files changed

+79
-65
lines changed

2 files changed

+79
-65
lines changed

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

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6492,112 +6492,117 @@ regex.swift:
64926492

64936493
# 206| [RegExpNamedCharacterProperty] [:aaaaa:]
64946494

6495-
# 210| [RegExpGroup] (?i)
6495+
# 211| [RegExpGroup] (?i)
64966496
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i
64976497

6498-
# 210| [RegExpSequence] (?i)abc
6498+
# 211| [RegExpSequence] (?i)abc
64996499
#-----| 0 -> [RegExpGroup] (?i)
65006500
#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc
65016501

6502-
# 210| [RegExpConstant, RegExpNormalChar] i
6502+
# 211| [RegExpConstant, RegExpNormalChar] i
65036503

6504-
# 210| [RegExpConstant, RegExpNormalChar] abc
6504+
# 211| [RegExpConstant, RegExpNormalChar] abc
65056505

6506-
# 211| [RegExpGroup] (?s)
6506+
# 212| [RegExpGroup] (?s)
65076507
#-----| 0 -> [RegExpConstant, RegExpNormalChar] s
65086508

6509-
# 211| [RegExpSequence] (?s)abc
6509+
# 212| [RegExpSequence] (?s)abc
65106510
#-----| 0 -> [RegExpGroup] (?s)
65116511
#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc
65126512

6513-
# 211| [RegExpConstant, RegExpNormalChar] s
6513+
# 212| [RegExpConstant, RegExpNormalChar] s
65146514

6515-
# 211| [RegExpConstant, RegExpNormalChar] abc
6515+
# 212| [RegExpConstant, RegExpNormalChar] abc
65166516

6517-
# 212| [RegExpGroup] (?is)
6517+
# 213| [RegExpGroup] (?is)
65186518
#-----| 0 -> [RegExpConstant, RegExpNormalChar] is
65196519

6520-
# 212| [RegExpSequence] (?is)abc
6520+
# 213| [RegExpSequence] (?is)abc
65216521
#-----| 0 -> [RegExpGroup] (?is)
65226522
#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc
65236523

6524-
# 212| [RegExpConstant, RegExpNormalChar] is
6524+
# 213| [RegExpConstant, RegExpNormalChar] is
65256525

6526-
# 212| [RegExpConstant, RegExpNormalChar] abc
6526+
# 213| [RegExpConstant, RegExpNormalChar] abc
65276527

6528-
# 214| [RegExpConstant, RegExpNormalChar] abc
6528+
# 214| [RegExpGroup] (?i-s)
6529+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i-s
65296530

6530-
# 215| [RegExpConstant, RegExpNormalChar] abc
6531+
# 214| [RegExpSequence] (?i-s)abc
6532+
#-----| 0 -> [RegExpGroup] (?i-s)
6533+
#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc
65316534

6532-
# 216| [RegExpConstant, RegExpNormalChar] abc
6535+
# 214| [RegExpConstant, RegExpNormalChar] i-s
6536+
6537+
# 214| [RegExpConstant, RegExpNormalChar] abc
65336538

65346539
# 217| [RegExpConstant, RegExpNormalChar] abc
65356540

6536-
# 218| [RegExpConstant, RegExpNormalChar] abc
6541+
# 217| [RegExpSequence] abc(?i)def
6542+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] abc
6543+
#-----| 1 -> [RegExpGroup] (?i)
6544+
#-----| 2 -> [RegExpConstant, RegExpNormalChar] def
65376545

6538-
# 219| [RegExpConstant, RegExpNormalChar] abc
6546+
# 217| [RegExpGroup] (?i)
6547+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i
65396548

6540-
# 221| [RegExpDot] .
6549+
# 217| [RegExpConstant, RegExpNormalChar] i
65416550

6542-
# 221| [RegExpStar] .*
6543-
#-----| 0 -> [RegExpDot] .
6551+
# 217| [RegExpConstant, RegExpNormalChar] def
65446552

6545-
# 222| [RegExpDot] .
6553+
# 218| [RegExpConstant, RegExpNormalChar] abc
65466554

6547-
# 222| [RegExpStar] .*
6548-
#-----| 0 -> [RegExpDot] .
6555+
# 218| [RegExpSequence] abc(?i:def)ghi
6556+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] abc
6557+
#-----| 1 -> [RegExpGroup] (?i:def)
6558+
#-----| 2 -> [RegExpConstant, RegExpNormalChar] ghi
65496559

6550-
# 223| [RegExpDot] .
6560+
# 218| [RegExpGroup] (?i:def)
6561+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i:def
65516562

6552-
# 223| [RegExpStar] .*
6553-
#-----| 0 -> [RegExpDot] .
6563+
# 218| [RegExpConstant, RegExpNormalChar] i:def
65546564

6555-
# 229| [RegExpGroup] (?i-s)
6556-
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i-s
6565+
# 218| [RegExpConstant, RegExpNormalChar] ghi
65576566

6558-
# 229| [RegExpSequence] (?i-s)abc
6559-
#-----| 0 -> [RegExpGroup] (?i-s)
6560-
#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc
6567+
# 219| [RegExpGroup] (?i)
6568+
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i
65616569

6562-
# 229| [RegExpConstant, RegExpNormalChar] i-s
6570+
# 219| [RegExpConstant, RegExpNormalChar] i
65636571

6564-
# 229| [RegExpConstant, RegExpNormalChar] abc
6572+
# 219| [RegExpConstant, RegExpNormalChar] abc
65656573

6566-
# 232| [RegExpConstant, RegExpNormalChar] abc
6574+
# 219| [RegExpConstant, RegExpNormalChar] -i
65676575

6568-
# 232| [RegExpSequence] abc(?i)def
6569-
#-----| 0 -> [RegExpConstant, RegExpNormalChar] abc
6570-
#-----| 1 -> [RegExpGroup] (?i)
6571-
#-----| 2 -> [RegExpConstant, RegExpNormalChar] def
6576+
# 219| [RegExpConstant, RegExpNormalChar] def
65726577

6573-
# 232| [RegExpGroup] (?i)
6574-
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i
6578+
# 222| [RegExpConstant, RegExpNormalChar] abc
65756579

6576-
# 232| [RegExpConstant, RegExpNormalChar] i
6580+
# 223| [RegExpConstant, RegExpNormalChar] abc
65776581

6578-
# 232| [RegExpConstant, RegExpNormalChar] def
6582+
# 224| [RegExpConstant, RegExpNormalChar] abc
65796583

6580-
# 233| [RegExpConstant, RegExpNormalChar] abc
6584+
# 225| [RegExpConstant, RegExpNormalChar] abc
65816585

6582-
# 233| [RegExpSequence] abc(?i:def)ghi
6583-
#-----| 0 -> [RegExpConstant, RegExpNormalChar] abc
6584-
#-----| 1 -> [RegExpGroup] (?i:def)
6585-
#-----| 2 -> [RegExpConstant, RegExpNormalChar] ghi
6586+
# 226| [RegExpConstant, RegExpNormalChar] abc
65866587

6587-
# 233| [RegExpGroup] (?i:def)
6588-
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i:def
6588+
# 227| [RegExpConstant, RegExpNormalChar] abc
6589+
6590+
# 230| [RegExpDot] .
65896591

6590-
# 233| [RegExpConstant, RegExpNormalChar] i:def
6592+
# 230| [RegExpStar] .*
6593+
#-----| 0 -> [RegExpDot] .
65916594

6592-
# 233| [RegExpConstant, RegExpNormalChar] ghi
6595+
# 231| [RegExpDot] .
65936596

6594-
# 234| [RegExpGroup] (?i)
6595-
#-----| 0 -> [RegExpConstant, RegExpNormalChar] i
6597+
# 231| [RegExpStar] .*
6598+
#-----| 0 -> [RegExpDot] .
65966599

6597-
# 234| [RegExpConstant, RegExpNormalChar] i
6600+
# 232| [RegExpDot] .
65986601

6599-
# 234| [RegExpConstant, RegExpNormalChar] abc
6602+
# 232| [RegExpStar] .*
6603+
#-----| 0 -> [RegExpDot] .
66006604

6601-
# 234| [RegExpConstant, RegExpNormalChar] -i
6605+
# 235| [RegExpDot] .
66026606

6603-
# 234| [RegExpConstant, RegExpNormalChar] def
6607+
# 235| [RegExpStar] .*
6608+
#-----| 0 -> [RegExpDot] .

swift/ql/test/library-tests/regex/regex.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,29 +207,38 @@ func myRegexpMethodsTests(b: Bool, str_unknown: String) throws {
207207

208208
// --- parse modes ---
209209

210+
// parse modes encoded in the string
210211
_ = try Regex("(?i)abc").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=(?i)abc
211212
_ = try Regex("(?s)abc").firstMatch(in: input) // $ input=input modes=DOTALL regex=(?s)abc
212213
_ = try Regex("(?is)abc").firstMatch(in: input) // $ input=input modes="DOTALL | IGNORECASE" regex=(?is)abc
214+
_ = try Regex("(?i-s)abc").firstMatch(in: input) // $ input=input regex=(?i-s)abc MISSING: modes=IGNORECASE SPURIOUS: modes="DOTALL | IGNORECASE"
215+
216+
// these cases use parse modes on localized areas of the regex, which we don't currently support
217+
_ = try Regex("abc(?i)def").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=abc(?i)def
218+
_ = try Regex("abc(?i:def)ghi").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=abc(?i:def)ghi
219+
_ = try Regex("(?i)abc(?-i)def").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=(?i)abc(?-i)def SPURIOUS: hasParseFailure=
213220

221+
// parse modes set through Regex
214222
_ = try Regex("abc").dotMatchesNewlines(true).firstMatch(in: input) // $ input=input regex=abc modes=DOTALL
215223
_ = try Regex("abc").dotMatchesNewlines(false).firstMatch(in: input) // $ input=input regex=abc
216224
_ = try Regex("abc").dotMatchesNewlines(true).dotMatchesNewlines(false).firstMatch(in: input) // $ input=input regex=abc
217225
_ = try Regex("abc").dotMatchesNewlines(false).dotMatchesNewlines(true).firstMatch(in: input) // $ input=input regex=abc modes=DOTALL
218226
_ = try Regex("abc").dotMatchesNewlines().ignoresCase().firstMatch(in: input) // $ input=input regex=abc modes="DOTALL | IGNORECASE"
219227
_ = try Regex("abc").anchorsMatchLineEndings().firstMatch(in: input) // $ input=input regex=abc modes=MULTILINE
220228

229+
// parse modes set through NSRegularExpression
221230
_ = try NSRegularExpression(pattern: ".*", options: .caseInsensitive).firstMatch(in: input, range: NSMakeRange(0, input.utf16.count)) // $ regex=.* input=input MISSING: modes=IGNORECASE
222231
_ = try NSRegularExpression(pattern: ".*", options: .dotMatchesLineSeparators).firstMatch(in: input, range: NSMakeRange(0, input.utf16.count)) // $ regex=.* input=input MISSING: modes=DOTALL
223232
_ = try NSRegularExpression(pattern: ".*", options: [.caseInsensitive, .dotMatchesLineSeparators]).firstMatch(in: input, range: NSMakeRange(0, input.utf16.count)) // $ regex=.* input=input MISSING: modes="DOTALL | IGNORECASE"
224233

225-
_ = input.replacingOccurrences(of: ".*", with: "", options: [.regularExpression, .caseInsensitive]) // $ MISSING: regex=.* input=input modes=IGNORECASE
226-
227-
_ = NSString(string: "abc").replacingOccurrences(of: ".*", with: "", options: [.regularExpression, .caseInsensitive], range: NSMakeRange(0, inputNS.length)) // $ MISSING: regex=.* input=inputNS modes=IGNORECASE
234+
let myOptions1 : NSRegularExpression.Options = [.caseInsensitive, .dotMatchesLineSeparators]
235+
_ = try NSRegularExpression(pattern: ".*", options: myOptions1).firstMatch(in: input, range: NSMakeRange(0, input.utf16.count)) // $ regex=.* input=input MISSING: modes="DOTALL | IGNORECASE"
228236

229-
_ = try Regex("(?i-s)abc").firstMatch(in: input) // $ input=input regex=(?i-s)abc MISSING: modes=IGNORECASE SPURIOUS: modes="DOTALL | IGNORECASE"
237+
// parse modes set through other methods
230238

231-
// these cases use parse modes on localized areas of the regex, which we don't currently support
232-
_ = try Regex("abc(?i)def").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=abc(?i)def
233-
_ = try Regex("abc(?i:def)ghi").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=abc(?i:def)ghi
234-
_ = try Regex("(?i)abc(?-i)def").firstMatch(in: input) // $ input=input modes=IGNORECASE regex=(?i)abc(?-i)def SPURIOUS: hasParseFailure=
239+
let myOptions2 : NSString.CompareOptions = [.regularExpression, .caseInsensitive]
240+
_ = input.replacingOccurrences(of: ".*", with: "", options: [.regularExpression, .caseInsensitive]) // $ MISSING: regex=.* input=input modes=IGNORECASE
241+
_ = input.replacingOccurrences(of: ".*", with: "", options: myOptions2) // $ MISSING: regex=.* input=input modes=IGNORECASE
242+
_ = NSString(string: "abc").replacingOccurrences(of: ".*", with: "", options: [.regularExpression, .caseInsensitive], range: NSMakeRange(0, inputNS.length)) // $ MISSING: regex=.* input=inputNS modes=IGNORECASE
243+
_ = NSString(string: "abc").replacingOccurrences(of: ".*", with: "", options: myOptions2, range: NSMakeRange(0, inputNS.length)) // $ MISSING: regex=.* input=inputNS modes=IGNORECASE
235244
}

0 commit comments

Comments
 (0)