Skip to content

Commit

Permalink
Merge pull request #46 from JanNash/remove-deprecated-call-to-String.…
Browse files Browse the repository at this point in the history
…characters

Remove/replace deprecated property and function calls
  • Loading branch information
fangpenlin authored Feb 1, 2018
2 parents bad3b51 + b21f401 commit ca880d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Sources/HTTPHeaderParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Foundation
extension String {
/// String without leading spaces
var withoutLeadingSpaces: String {
var firstNoneSpace: Int = characters.count
for (i, char) in characters.enumerated() {
var firstNoneSpace: Int = count
for (i, char) in enumerated() {
if char != " " {
firstNoneSpace = i
break
Expand Down
15 changes: 5 additions & 10 deletions Tests/EmbassyTests/TestingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,11 @@ func getUnusedTCPPort() throws -> Int {

func makeRandomString(_ length: Int) -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var result: [String] = []
for _ in 0..<length {
let randomIndex = Int(randomUniform(UInt32(letters.characters.count)))
let char = letters.substring(
with: letters.characters.index(letters.startIndex, offsetBy: randomIndex) ..<
letters.characters.index(letters.startIndex, offsetBy: randomIndex + 1)
)
result.append(char)
}
return result.joined(separator: "")
let endIndex = UInt32(letters.count - 1)
let result: [Any?] = Array(repeating: nil, count: length)
return String(result.map({ _ in
letters[String.Index(encodedOffset: Int(arc4random_uniform(endIndex)))]
}))
}

extension XCTestCase {
Expand Down
10 changes: 5 additions & 5 deletions Tests/EmbassyTests/TransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class TransportTests: XCTestCase {
dataChunk4,
dataChunk5,
dataChunk6
].reduce(0) { $0 + $1.characters.count }
].reduce(0) { $0 + $1.count }

let clientSocket = try! TCPSocket()
let clientTransport = Transport(socket: clientSocket, eventLoop: loop) { data in
clientReceivedData.append(String(bytes: data, encoding: String.Encoding.utf8)!)
totalReceivedSize += clientReceivedData.last!.characters.count
totalReceivedSize += clientReceivedData.last!.count
if totalReceivedSize >= totalDataSize {
loop.stop()
}
Expand All @@ -66,7 +66,7 @@ class TransportTests: XCTestCase {
acceptedSocket = try! listenSocket.accept()
serverTransport = Transport(socket: acceptedSocket, eventLoop: loop) { data in
serverReceivedData.append(String(bytes: data, encoding: String.Encoding.utf8)!)
totalReceivedSize += serverReceivedData.last!.characters.count
totalReceivedSize += serverReceivedData.last!.count
if totalReceivedSize >= totalDataSize {
loop.stop()
}
Expand Down Expand Up @@ -234,8 +234,8 @@ class TransportTests: XCTestCase {
XCTAssert(clientTransport.closed)
XCTAssert(serverTransport.closed)
XCTAssertEqual(
serverReceivedData.joined(separator: "").characters.count,
"hello".characters.count + bigDataChunk.characters.count
serverReceivedData.joined(separator: "").count,
"hello".count + bigDataChunk.count
)
}

Expand Down

0 comments on commit ca880d6

Please sign in to comment.