Skip to content

Commit dea600c

Browse files
committed
improve doc. improve & fix tests
1 parent 68b0dd5 commit dea600c

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Sources/Web3Core/Utility/Array+Extension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ extension Array where Element: BinaryInteger {
107107
}
108108
}
109109

110-
//MARK: - Conversion
110+
// MARK: - Conversion
111111

112-
/// Transforms an Array of Any? into an Array of AnyObject
112+
/// Transforms `[Any?]` into `[AnyObject]`
113113
extension Array where Element == Any? {
114114
func toAnyObject() -> [AnyObject] {
115115
self.map{ $0 as AnyObject }

Tests/web3swiftTests/localTests/ArrayExtensionTests.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@testable import Core
77
import XCTest
8+
import BigInt
89

910
final class ArrayExtensionTests: XCTestCase {
1011
func testToAnyObjectEmpty() {
@@ -20,11 +21,23 @@ final class ArrayExtensionTests: XCTestCase {
2021
}
2122

2223
func testToAnyObjectNilAndNonNils() throws {
23-
let result = [1, nil, "", NSNull()].toAnyObject()
24-
XCTAssertEqual(result.count, 4)
24+
let result = [1,
25+
nil,
26+
"2",
27+
NSNull(),
28+
Data(hex: "FA"),
29+
BigInt(3),
30+
BigUInt(4),
31+
EthereumAddress(Data(count: 20))
32+
].toAnyObject()
33+
XCTAssertEqual(result.count, 8)
2534
XCTAssertEqual(result.first as? Int, 1)
26-
XCTAssertTrue(result.dropFirst().first is NSNull)
27-
XCTAssertNil(result.dropFirst().first as? String, "2")
28-
XCTAssertTrue(result.dropFirst().first is NSNull)
35+
XCTAssertTrue(result.dropFirst(1).first is NSNull)
36+
XCTAssertEqual(result.dropFirst(2).first as? String, "2")
37+
XCTAssertTrue(result.dropFirst(3).first is NSNull)
38+
XCTAssertEqual(result.dropFirst(4).first as? Data, Data(hex: "FA"))
39+
XCTAssertEqual(result.dropFirst(5).first as? BigInt, BigInt(3))
40+
XCTAssertEqual(result.dropFirst(6).first as? BigUInt, BigUInt(4))
41+
XCTAssertEqual(result.dropFirst(7).first as? EthereumAddress, EthereumAddress(Data(count: 20)))
2942
}
3043
}

0 commit comments

Comments
 (0)