Skip to content

Commit

Permalink
Add test for optionals.
Browse files Browse the repository at this point in the history
  • Loading branch information
Srđan Rašić committed Apr 15, 2015
1 parent 96a03f1 commit 7e8ce51
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions BondTests/DynamicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,44 @@ class DynamicTests: XCTestCase {
XCTAssert(d2w == nil, "Nilling first should delete second")
XCTAssert(d1w == nil, "Nilling first should delete first, too")
}

func testOptionals() {
let dynamic = Dynamic<Int?>(nil)
var observedValue: Int? = 999
let bond = Bond<Int?>() { observedValue = $0 }

XCTAssert(observedValue == 999)
dynamic.bindTo(bond)
XCTAssert(observedValue == nil)

XCTAssert(dynamic.valid == true, "Should be valid")
XCTAssert(dynamic.value == nil, "Should not crash")

dynamic.value = 5
XCTAssert(observedValue == 5)
XCTAssert(dynamic.valid == true, "Should be valid")

dynamic.value = nil
XCTAssert(observedValue == nil)
XCTAssert(dynamic.valid == true, "Should be valid")

dynamic.value = 2
XCTAssert(observedValue == 2)
XCTAssert(dynamic.valid == true, "Should be valid")

let filtered = dynamic.filter { $0 == nil || $0! < 1 }
XCTAssert(filtered.valid == false, "Should not be valid")

dynamic.value = nil
XCTAssert(filtered.valid == true, "Should be valid")
XCTAssert(filtered.value == nil)

dynamic.value = 5
XCTAssert(filtered.valid == true, "Should be valid")
XCTAssert(filtered.value == nil)

dynamic.value = -4
XCTAssert(filtered.valid == true, "Should be valid")
XCTAssert(filtered.value == -4)
}
}

0 comments on commit 7e8ce51

Please sign in to comment.