Skip to content
This repository has been archived by the owner on Jul 18, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from timgcarlson/issue-7-add-support-for-lists
Browse files Browse the repository at this point in the history
[FIXES #7] Allow arrays of certain types to be a value of TrackedProperty
  • Loading branch information
VojtaStavik authored Jul 24, 2017
2 parents 4e8ba1e + d86472b commit 98f4a41
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Pods/Nimble/Sources/Nimble/Matchers/AllPass.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Trackable/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public func ~>> (key: Key, value: Set<TrackedProperty>) -> TrackedProperty {
return TrackedProperty(key: key, value: value)
}

public func ~>> (key: Key, value: [String]) -> TrackedProperty {
return TrackedProperty(key: key, value: value)
}

public func ~>> (key: Key, value: [Double]) -> TrackedProperty {
return TrackedProperty(key: key, value: value)
}

public func ~>> (key: Key, value: [Int]) -> TrackedProperty {
return TrackedProperty(key: key, value: value)
}

public func ~>> (key: Key, value: [Bool]) -> TrackedProperty {
return TrackedProperty(key: key, value: value)
}

extension TrackedProperty : Equatable { }
public func ==(l: TrackedProperty, r: TrackedProperty) -> Bool {
return l.key == r.key
Expand Down
37 changes: 32 additions & 5 deletions TrackableTests/Property-Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PropertyTests: QuickSpec {
case value2
case value3
case value4
case value5

enum Details: String, Key {
case detail1
Expand Down Expand Up @@ -99,7 +100,27 @@ class PropertyTests: QuickSpec {
let testPropery = TestKeys.value1 ~>> true
expect(testPropery.value as? Bool) == true
}


it("should init with [String]") {
let testPropery = TestKeys.value1 ~>> ["TestString1", "TestString2"]
expect(testPropery.value as? [String]) == ["TestString1", "TestString2"]
}

it("should init with [Int]") {
let testPropery = TestKeys.value1 ~>> [5, 6]
expect(testPropery.value as? [Int]) == [5, 6]
}

it("should init with [Double]") {
let testPropery = TestKeys.value1 ~>> [5.63, 6.53]
expect(testPropery.value as? [Double]) == [5.63, 6.53]
}

it("should init with [Bool]") {
let testPropery = TestKeys.value1 ~>> [true, false]
expect(testPropery.value as? [Bool]) == [true, false]
}

it("should init with Set of properties") {
let value: Set<TrackedProperty> = [TestKeys.Details.detail1 ~>> "detail1"]
let testProperty = TestKeys.value1 ~>> value
Expand All @@ -115,18 +136,20 @@ class PropertyTests: QuickSpec {
}

it("should convert self to dictionary") {
let testProperties: Set<TrackedProperty>= [
let testProperties: Set<TrackedProperty> = [
TestKeys.value1 ~>> true,
TestKeys.value2 ~>> "STP",
TestKeys.value3 ~>> 5.66,
TestKeys.value4 ~>> [TestKeys.Details.detail2 ~>> "detail"]
TestKeys.value4 ~>> [TestKeys.Details.detail2 ~>> "detail"],
TestKeys.value5 ~>> ["TestString1", "TestString2"]
]

let dictionary = testProperties.dictionaryRepresentation
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value1"] as? Bool).to(beTrue())
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value2"] as? String) == "STP"
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value3"] as? Double) == 5.66
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value4.Details.detail2"] as? String) == "detail"
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value5"] as? [String]) == ["TestString1", "TestString2"]
}
}

Expand All @@ -138,14 +161,16 @@ class PropertyTests: QuickSpec {

let set2: Set<TrackedProperty> = [
TestKeys.value3 ~>> 5.66,
TestKeys.value4 ~>> [TestKeys.Details.detail2 ~>> "detail"]
TestKeys.value4 ~>> [TestKeys.Details.detail2 ~>> "detail"],
TestKeys.value5 ~>> ["TestString1", "TestString2"]
]

let dictionary = (set1 + set2).dictionaryRepresentation
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value1"] as? Bool).to(beTrue())
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value2"] as? String) == "STP"
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value3"] as? Double) == 5.66
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value4.Details.detail2"] as? String) == "detail"
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value5"] as? [String]) == ["TestString1", "TestString2"]
}

it("should properly implement += for sets") {
Expand All @@ -156,7 +181,8 @@ class PropertyTests: QuickSpec {

let set2: Set<TrackedProperty> = [
TestKeys.value3 ~>> 5.66,
TestKeys.value4 ~>> [TestKeys.Details.detail2 ~>> "detail"]
TestKeys.value4 ~>> [TestKeys.Details.detail2 ~>> "detail"],
TestKeys.value5 ~>> ["TestString1", "TestString2"]
]

set1 += set2
Expand All @@ -165,6 +191,7 @@ class PropertyTests: QuickSpec {
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value2"] as? String) == "STP"
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value3"] as? Double) == 5.66
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value4.Details.detail2"] as? String) == "detail"
expect(dictionary["TrackableTests.PropertyTests.TestKeys.value5"] as? [String]) == ["TestString1", "TestString2"]
}
}
}

0 comments on commit 98f4a41

Please sign in to comment.