@@ -25,7 +25,9 @@ class TestNSRegularExpression : XCTestCase {
2525 return [
2626 ( " test_simpleRegularExpressions " , test_simpleRegularExpressions) ,
2727 ( " test_regularExpressionReplacement " , test_regularExpressionReplacement) ,
28- ( " test_complexRegularExpressions " , test_complexRegularExpressions)
28+ ( " test_complexRegularExpressions " , test_complexRegularExpressions) ,
29+ ( " test_Equal " , test_Equal) ,
30+ ( " test_NSCoding " , test_NSCoding) ,
2931 ]
3032 }
3133
@@ -317,4 +319,37 @@ class TestNSRegularExpression : XCTestCase {
317319 complexRegularExpressionTest ( " (a|b)x|123|(c|d)y " , [ ] , " axcy " , [ ] , NSMakeRange ( 0 , 4 ) , 2 , NSMakeRange ( 0 , 2 ) , NSMakeRange ( 0 , 1 ) , NSMakeRange ( NSNotFound, 0 ) )
318320 complexRegularExpressionTest ( " (a|b)x|123|(c|d)y " , [ ] , " cya " , [ ] , NSMakeRange ( 0 , 3 ) , 1 , NSMakeRange ( 0 , 2 ) , NSMakeRange ( NSNotFound, 0 ) , NSMakeRange ( 0 , 1 ) )
319321 }
322+
323+ func test_Equal( ) {
324+ var regularExpressionA = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: [ ] )
325+ var regularExpressionB = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: [ ] )
326+ XCTAssertTrue ( regularExpressionA == regularExpressionB)
327+ XCTAssertFalse ( regularExpressionA === regularExpressionB)
328+
329+ regularExpressionA = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: . caseInsensitive)
330+ regularExpressionB = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: . caseInsensitive)
331+ XCTAssertTrue ( regularExpressionA == regularExpressionB)
332+ XCTAssertFalse ( regularExpressionA === regularExpressionB)
333+
334+ regularExpressionA = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: [ . caseInsensitive, . allowCommentsAndWhitespace] )
335+ regularExpressionB = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: [ . caseInsensitive, . allowCommentsAndWhitespace] )
336+ XCTAssertTrue ( regularExpressionA == regularExpressionB)
337+ XCTAssertFalse ( regularExpressionA === regularExpressionB)
338+
339+ regularExpressionA = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: . caseInsensitive)
340+ regularExpressionB = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: [ . caseInsensitive, . allowCommentsAndWhitespace] )
341+ XCTAssertFalse ( regularExpressionA == regularExpressionB)
342+ XCTAssertFalse ( regularExpressionA === regularExpressionB)
343+
344+ regularExpressionA = try ! NSRegularExpression ( pattern: " [a-y]+ " , options: . caseInsensitive)
345+ regularExpressionB = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: . caseInsensitive)
346+ XCTAssertFalse ( regularExpressionA == regularExpressionB)
347+ XCTAssertFalse ( regularExpressionA === regularExpressionB)
348+ }
349+
350+ func test_NSCoding( ) {
351+ let regularExpressionA = try ! NSRegularExpression ( pattern: " [a-z]+ " , options: [ . caseInsensitive, . allowCommentsAndWhitespace] )
352+ let regularExpressionB = NSKeyedUnarchiver . unarchiveObject ( with: NSKeyedArchiver . archivedData ( withRootObject: regularExpressionA) ) as! NSRegularExpression
353+ XCTAssertEqual ( regularExpressionA, regularExpressionB, " Archived then unarchived `NSRegularExpression` must be equal. " )
354+ }
320355}
0 commit comments