@@ -25,7 +25,9 @@ class TestNSRegularExpression : XCTestCase {
25
25
return [
26
26
( " test_simpleRegularExpressions " , test_simpleRegularExpressions) ,
27
27
( " test_regularExpressionReplacement " , test_regularExpressionReplacement) ,
28
- ( " test_complexRegularExpressions " , test_complexRegularExpressions)
28
+ ( " test_complexRegularExpressions " , test_complexRegularExpressions) ,
29
+ ( " test_Equal " , test_Equal) ,
30
+ ( " test_NSCoding " , test_NSCoding) ,
29
31
]
30
32
}
31
33
@@ -317,4 +319,37 @@ class TestNSRegularExpression : XCTestCase {
317
319
complexRegularExpressionTest ( " (a|b)x|123|(c|d)y " , [ ] , " axcy " , [ ] , NSMakeRange ( 0 , 4 ) , 2 , NSMakeRange ( 0 , 2 ) , NSMakeRange ( 0 , 1 ) , NSMakeRange ( NSNotFound, 0 ) )
318
320
complexRegularExpressionTest ( " (a|b)x|123|(c|d)y " , [ ] , " cya " , [ ] , NSMakeRange ( 0 , 3 ) , 1 , NSMakeRange ( 0 , 2 ) , NSMakeRange ( NSNotFound, 0 ) , NSMakeRange ( 0 , 1 ) )
319
321
}
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
+ }
320
355
}
0 commit comments