-
Notifications
You must be signed in to change notification settings - Fork 178
/
Mockingjay.swift
56 lines (47 loc) · 1.4 KB
/
Mockingjay.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Mockingjay.swift
// Mockingjay
//
// Created by Kyle Fuller on 28/02/2015.
// Copyright (c) 2015 Cocode. All rights reserved.
//
import Foundation
public enum Download: ExpressibleByNilLiteral, Equatable {
public init(nilLiteral: ()) {
self = .noContent
}
// Simulate download in one step
case content(Data)
// Simulate download as byte stream
case streamContent(data:Data, inChunksOf:Int)
// Simulate empty download
case noContent
}
public func ==(lhs:Download, rhs:Download) -> Bool {
switch(lhs, rhs) {
case let (.content(lhsData), .content(rhsData)):
return (lhsData == rhsData)
case let (.streamContent(data:lhsData, inChunksOf:lhsBytes), .streamContent(data:rhsData, inChunksOf:rhsBytes)):
return (lhsData == rhsData) && lhsBytes == rhsBytes
case (.noContent, .noContent):
return true
default:
return false
}
}
public enum Response : Equatable {
case success(URLResponse, Download)
case failure(NSError)
}
public func ==(lhs:Response, rhs:Response) -> Bool {
switch (lhs, rhs) {
case let (.failure(lhsError), .failure(rhsError)):
return lhsError == rhsError
case let (.success(lhsResponse, lhsDownload), .success(rhsResponse, rhsDownload)):
return lhsResponse == rhsResponse && lhsDownload == rhsDownload
default:
return false
}
}
public typealias Matcher = (URLRequest) -> (Bool)
public typealias Builder = (URLRequest) -> (Response)