@@ -1072,6 +1072,50 @@ class TestData : TestDataSuper {
1072
1072
let actual = d2. map { $0 }
1073
1073
expectEqual ( expected, actual)
1074
1074
}
1075
+
1076
+ func test_dropFirst( ) {
1077
+ var data = Data ( [ 0 , 1 , 2 , 3 , 4 , 5 ] )
1078
+ let sliced = data. dropFirst ( )
1079
+ expectEqual ( data. count - 1 , sliced. count)
1080
+ expectEqual ( UInt8 ( 1 ) , sliced [ 1 ] )
1081
+ expectEqual ( UInt8 ( 2 ) , sliced [ 2 ] )
1082
+ expectEqual ( UInt8 ( 3 ) , sliced [ 3 ] )
1083
+ expectEqual ( UInt8 ( 4 ) , sliced [ 4 ] )
1084
+ expectEqual ( UInt8 ( 5 ) , sliced [ 5 ] )
1085
+ }
1086
+
1087
+ func test_dropFirst2( ) {
1088
+ var data = Data ( [ 0 , 1 , 2 , 3 , 4 , 5 ] )
1089
+ let sliced = data. dropFirst ( 2 )
1090
+ expectEqual ( data. count - 2 , sliced. count)
1091
+ expectEqual ( UInt8 ( 2 ) , sliced [ 2 ] )
1092
+ expectEqual ( UInt8 ( 3 ) , sliced [ 3 ] )
1093
+ expectEqual ( UInt8 ( 4 ) , sliced [ 4 ] )
1094
+ expectEqual ( UInt8 ( 5 ) , sliced [ 5 ] )
1095
+ }
1096
+
1097
+ func test_copyBytes1( ) {
1098
+ var array : [ UInt8 ] = [ 0 , 1 , 2 , 3 ]
1099
+ var data = Data ( bytes: array)
1100
+
1101
+ array. withUnsafeMutableBufferPointer {
1102
+ data [ 1 ..< 3 ] . copyBytes ( to: $0. baseAddress!, from: 1 ..< 3 )
1103
+ }
1104
+ expectEqual ( [ UInt8 ( 1 ) , UInt8 ( 2 ) , UInt8 ( 2 ) , UInt8 ( 3 ) ] , array)
1105
+ }
1106
+
1107
+ func test_copyBytes2( ) {
1108
+ let array : [ UInt8 ] = [ 0 , 1 , 2 , 3 ]
1109
+ var data = Data ( bytes: array)
1110
+
1111
+ let expectedSlice = array [ 1 ..< 3 ]
1112
+
1113
+ let start = data. index ( after: data. startIndex)
1114
+ let end = data. index ( before: data. endIndex)
1115
+ let slice = data [ start..< end]
1116
+
1117
+ expectEqual ( expectedSlice [ expectedSlice. startIndex] , slice [ slice. startIndex] )
1118
+ }
1075
1119
}
1076
1120
1077
1121
#if !FOUNDATION_XCTEST
@@ -1128,6 +1172,10 @@ DataTests.test("test_sliceEquality") { TestData().test_sliceEquality() }
1128
1172
DataTests . test ( " test_sliceEquality2 " ) { TestData ( ) . test_sliceEquality2 ( ) }
1129
1173
DataTests . test ( " test_splittingHttp " ) { TestData ( ) . test_splittingHttp ( ) }
1130
1174
DataTests . test ( " test_map " ) { TestData ( ) . test_map ( ) }
1175
+ DataTests . test ( " test_dropFirst " ) { TestData ( ) . test_dropFirst ( ) }
1176
+ DataTests . test ( " test_dropFirst2 " ) { TestData ( ) . test_dropFirst2 ( ) }
1177
+ DataTests . test ( " test_copyBytes1 " ) { TestData ( ) . test_copyBytes1 ( ) }
1178
+ DataTests . test ( " test_copyBytes2 " ) { TestData ( ) . test_copyBytes2 ( ) }
1131
1179
1132
1180
// XCTest does not have a crash detection, whereas lit does
1133
1181
DataTests . test ( " bounding failure subdata " ) {
0 commit comments