             XCTAssertNil(Data(hexString: badHexString))
         }
     }
+    
+    func testDataToBytesArray() {
+        let count = 10
+        let unsafe = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: count)
+        unsafe.initialize(repeating: 0)
+        for index in 0..<count {
+            unsafe[index] = UInt8(count - index)
+        }
+        
+        let data = Data(buffer: unsafe)
+        let array = data.bytesArray
+        
+        for index in 0..<count {
+            XCTAssertTrue(array[index] == count - index)
+        }
+    }
 
 }


        hex = data.toHexString()
        XCTAssertTrue(hex == "6261736520313020697320736F2062617369632E206261736520313620697320776865726520697427732061742C20796F2E")

    }

    func testHexToData() {
        var hexString = "6261736520313020697320736F2062617369632E206261736520313620697320776865726520697427732061742C20796F2E"
        do { // adding scope level so we can reuse variable names
            guard let data = Data(hexString: hexString) else {XCTFail("Couldn't make data out of provided string"); return}
            guard let string = String(data: data, encoding: .utf8) else {XCTFail("Couldn't make string out of data"); return}

            XCTAssertTrue(testString == string, "\(testString) == \(string)")
        }

        hexString = "62617365 20313020 69732073 6F206261 7369632E 20626173 65203136 20697320 77686572 65206974 27732061 742C2079 6F2E"
        do { // adding scope level so we can reuse variable names
            guard let data = Data(hexString: hexString) else {XCTFail("Couldn't make data out of provided string"); return}
            guard let string = String(data: data, encoding: .utf8) else {XCTFail("Couldn't make string out of data"); return}

            XCTAssertTrue(testString == string, "\(testString) == \(string)")
        }

        hexString = "0x6261736520313020697320736F2062617369632E206261736520313620697320776865726520697427732061742C20796F2E"
        do { // adding scope level so we can reuse variable names
            guard let data = Data(hexString: hexString) else {XCTFail("Couldn't make data out of provided string"); return}
            guard let string = String(data: data, encoding: .utf8) else {XCTFail("Couldn't make string out of data"); return}

            XCTAssertTrue(testString == string, "\(testString) == \(string)")
        }

extension DataExtensionTests {

    func testToHexString() {
        guard let data = testString.data(using: .utf8) else {
            XCTFail("Couldn't make data out of provided string")
            return
        }
        var hex = data.toHexString(spaces: true)
        XCTAssertTrue(hex == "62617365 20313020 69732073 6F206261 7369632E 20626173 65203136 20697320 77686572 65206974 27732061 742C2079 6F2E", "'\(hex)' == '62617365 20313020 69732073 6F206261 7369632E 20626173 65203136 20697320 77686572 65206974 27732061 742C2079 6F2E'")

