Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import Foundation
6
import XCTest
7
8
class HexExtensionsTests: XCTestCase {
9
func testHexEncodedString() {
10
XCTAssertEqual("Hello, world!".data(using: .utf8)!.hexEncodedString, "48656c6c6f2c20776f726c6421")
11
XCTAssertEqual("Hello, world!!".data(using: .utf8)!.hexEncodedString, "48656c6c6f2c20776f726c642121")
12
}
13
14
func testHexDecodedData() {
15
XCTAssertEqual("48656c6c6f2c20776f726c6421".hexDecodedData, "Hello, world!".data(using: .utf8))
16
XCTAssertEqual("48656c6c6f2c20776f726c642121".hexDecodedData, "Hello, world!!".data(using: .utf8))
17
}
18
19
func testHexDecodedDataWithInvalidInput() {
20
XCTAssertEqual("".hexDecodedData, Data())
21
XCTAssertEqual("cheese".hexDecodedData, Data())
22
XCTAssertEqual("a".hexDecodedData, Data())
23
}
24
}