This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User { | |
struct Prefs { | |
let email: Bool, sms: Bool | |
} | |
let name: String, prefs: Prefs | |
} | |
let user = User(name: "Test", prefs: Prefs(email: true, sms: false)) | |
// Previously: | |
assert(user.name.isEmpty) == true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dynamicMemberLookup | |
struct Assert<T> { | |
let value: T | |
subscript<Value>(dynamicMember keyPath: KeyPath<T, Value>) -> Assert<Value> { | |
.init(value: value[keyPath: keyPath]) | |
} | |
} | |
func assert<T>(_ root: T, _ closure: (Assert<T>) throws -> Void) rethrows { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func == <T: Equatable>(lhs: Assert<T>, rhs: T) { | |
lhs.equal(to: rhs) | |
} | |
// usage: | |
assert(actual) == expected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let actual = "Test" | |
let expected = "Test" | |
assert(actual).equal(to: expected) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Assert where T: Equatable { | |
func equal(to other: T, file: StaticString = #file, line: UInt = #line) { | |
XCTAssertEqual(value, other, file: file, line: line) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Assert<T> { | |
let value: T | |
} | |
func assert<T>(_ value: @autoclosure () throws -> T) rethrows -> Assert<T> { | |
try .init(value: value()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@resultBuilder | |
struct AssertionBuilder { | |
static func buildArray(_ components: [Bool]) -> Bool { | |
components.reduce(true) { $0 && $1 } | |
} | |
static func buildBlock(_ components: Bool...) -> Bool { | |
components.reduce(true) { $0 && $1 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Resolver { | |
func resolve<T>(_ type: T.Type) -> T | |
} | |
class MainResolver: Resolver { | |
static let shared = MainResolver() | |
private var dependencies: [Any] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addSubview(redView) { | |
$0.edges(20).equalToSuperview() | |
$0.addSubview(greenView) { | |
$0.edges(30).equalToSuperview() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addSubview(redView) { | |
$0.edges(20).equalToSuperview() | |
} |