Skip to content

Commit 1f8a839

Browse files
committed
Descriptions are not guaranteed to remain constant. (Indeed, all three of these need to change vis-a-vis Darwin equivalents.)
1 parent 42a3cc9 commit 1f8a839

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Tests/Foundation/Tests/TestNSRegularExpression.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,35 +364,41 @@ class TestNSRegularExpression : XCTestCase {
364364
XCTAssertEqual(regex!.replaceMatches(in: str, range: range, withTemplate: "$1-$2-$3"), 1)
365365
}
366366

367-
func test_badPattern() {
367+
func test_badPattern() throws {
368368
do {
369369
_ = try NSRegularExpression(pattern: "(", options: [])
370370
XCTFail()
371371
} catch {
372-
let err = String(describing: error)
373-
XCTAssertEqual(err, "Error Domain=NSCocoaErrorDomain Code=2048 \"(null)\" UserInfo={NSInvalidValue=(}")
372+
let err = try XCTUnwrap(error as? NSError)
373+
XCTAssertEqual(err.domain, NSCocoaErrorDomain)
374+
XCTAssertEqual(err.code, CocoaError.formatting.rawValue)
375+
XCTAssertEqual(err.userInfo["NSInvalidValue"] as? String, "(")
374376
}
375377
}
376378

377-
func test_unicodeNamedGroup() {
379+
func test_unicodeNamedGroup() throws {
378380
let patternString = "(?<りんご>a)"
379381
do {
380382
_ = try NSRegularExpression(pattern: patternString, options: [])
381383
XCTFail("Building regular expression for pattern with unicode group name should fail.")
382384
} catch {
383-
let err = String(describing: error)
384-
XCTAssertEqual(err, "Error Domain=NSCocoaErrorDomain Code=2048 \"(null)\" UserInfo={NSInvalidValue=(?<りんご>a)}")
385+
let err = try XCTUnwrap(error as? NSError)
386+
XCTAssertEqual(err.domain, NSCocoaErrorDomain)
387+
XCTAssertEqual(err.code, CocoaError.formatting.rawValue)
388+
XCTAssertEqual(err.userInfo["NSInvalidValue"] as? String, patternString)
385389
}
386390
}
387391

388-
func test_conflictingNamedGroups() {
392+
func test_conflictingNamedGroups() throws {
389393
let patternString = "(?<name>a)(?<name>b)"
390394
do {
391395
_ = try NSRegularExpression(pattern: patternString, options: [])
392396
XCTFail("Building regular expression for pattern with identically named groups should fail.")
393397
} catch {
394-
let err = String(describing: error)
395-
XCTAssertEqual(err, "Error Domain=NSCocoaErrorDomain Code=2048 \"(null)\" UserInfo={NSInvalidValue=(?<name>a)(?<name>b)}")
398+
let err = try XCTUnwrap(error as? NSError)
399+
XCTAssertEqual(err.domain, NSCocoaErrorDomain)
400+
XCTAssertEqual(err.code, CocoaError.formatting.rawValue)
401+
XCTAssertEqual(err.userInfo["NSInvalidValue"] as? String, patternString)
396402
}
397403
}
398404

0 commit comments

Comments
 (0)