@@ -30,16 +30,40 @@ import FoundationBridgeObjC
30
30
31
31
class TestNSString : TestNSStringSuper {
32
32
33
- func test_equalOverflow( ) {
34
- let cyrillic = " чебурашка@ящик-с-апельсинами.рф "
35
- let other = getNSStringEqualTestString ( )
36
- print ( NSStringBridgeTestEqual ( cyrillic, other) )
37
- }
33
+ func test_equalOverflow( ) {
34
+ let cyrillic = " чебурашка@ящик-с-апельсинами.рф "
35
+ let other = getNSStringEqualTestString ( )
36
+ print ( NSStringBridgeTestEqual ( cyrillic, other) )
37
+ }
38
+
39
+ func test_smallString_BOM( ) {
40
+ let bom = " \u{FEFF} " // U+FEFF (ZERO WIDTH NO-BREAK SPACE)
41
+ // expectEqual(1, NSString(string: bom).length)
42
+ // expectEqual(4, NSString(string: "\(bom)abc").length)
43
+ // expectEqual(5, NSString(string: "\(bom)\(bom)abc").length)
44
+ // expectEqual(4, NSString(string: "a\(bom)bc").length)
45
+ // expectEqual(13, NSString(string: "\(bom)234567890123").length)
46
+ // expectEqual(14, NSString(string: "\(bom)2345678901234").length)
47
+
48
+ expectEqual ( 1 , ( bom as NSString ) . length)
49
+ expectEqual ( 4 , ( " \( bom) abc " as NSString ) . length)
50
+ expectEqual ( 5 , ( " \( bom) \( bom) abc " as NSString ) . length)
51
+ expectEqual ( 4 , ( " a \( bom) bc " as NSString ) . length)
52
+ expectEqual ( 13 , ( " \( bom) 234567890123 " as NSString ) . length)
53
+ expectEqual ( 14 , ( " \( bom) 2345678901234 " as NSString ) . length)
54
+
55
+ let string = " \( bom) abc "
56
+ let middleIndex = string. index ( string. startIndex, offsetBy: 2 )
57
+ string. enumerateSubstrings ( in: middleIndex..< string. endIndex, options: . byLines) { ( _, _, _, _) in } //shouldn't crash
58
+ }
38
59
39
60
}
40
61
41
62
#if !FOUNDATION_XCTEST
42
63
var NSStringTests = TestSuite ( " TestNSString " )
43
64
NSStringTests . test ( " test_equalOverflow " ) { TestNSString ( ) . test_equalOverflow ( ) }
65
+ NSStringTests . test ( " test_smallString_BOM " ) {
66
+ TestNSString ( ) . test_smallString_BOM ( )
67
+ }
44
68
runAllTests ( )
45
69
#endif
0 commit comments