-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ObservableCollection<Array<T>> subscript issue
- Loading branch information
1 parent
b43fd63
commit be9d892
Showing
5 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "ReactiveKit" | ||
s.version = "1.0.4" | ||
s.version = "1.0.5" | ||
s.summary = "A Swift Reactive Programming Framework" | ||
s.description = "ReactiveKit is a collection of Swift frameworks for reactive and functional reactive programming." | ||
s.homepage = "https://github.com/ReactiveKit/ReactiveKit" | ||
s.license = 'MIT' | ||
s.author = { "Srdan Rasic" => "[email protected]" } | ||
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v1.0.4" } | ||
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v1.0.5" } | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.osx.deployment_target = '10.9' | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// | ||
// ObservableCollectionSpec.swift | ||
// ReactiveKit | ||
// | ||
// Created by Srdan Rasic on 22/11/15. | ||
// Copyright © 2015 Srdan Rasic. All rights reserved. | ||
// | ||
|
||
import Quick | ||
import Nimble | ||
@testable import ReactiveKit | ||
|
||
class ObservableCollectionSpec: QuickSpec { | ||
|
||
override func spec() { | ||
|
||
// MARK: - Array | ||
|
||
describe("ObservableCollection<Array<T>>") { | ||
var observableCollection: ObservableCollection<[Int]>! | ||
|
||
beforeEach { | ||
observableCollection = ObservableCollection([1, 2, 3]) | ||
} | ||
|
||
context("when observed") { | ||
var observedEvents: [ObservableCollectionEvent<[Int]>] = [] | ||
|
||
beforeEach { | ||
observedEvents = [] | ||
observableCollection.observe(on: ImmediateExecutionContext) { | ||
observedEvents.append($0) | ||
} | ||
} | ||
|
||
it("generates initial event") { | ||
expect(observedEvents[0]).to(equal(ObservableCollectionEvent(collection: [1, 2, 3], inserts: [], deletes: [], updates: []))) | ||
} | ||
|
||
describe("append") { | ||
beforeEach { | ||
observableCollection.append(4) | ||
} | ||
|
||
it("appends") { | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [1, 2, 3, 4], inserts: [3], deletes: [], updates: []))) | ||
} | ||
} | ||
|
||
describe("insert") { | ||
beforeEach { | ||
observableCollection.insert(0, atIndex: 0) | ||
} | ||
|
||
it("inserts") { | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [0, 1, 2, 3], inserts: [0], deletes: [], updates: []))) | ||
} | ||
} | ||
|
||
describe("insertContentsOf") { | ||
beforeEach { | ||
observableCollection.insertContentsOf([10, 11], at: 1) | ||
} | ||
|
||
it("insertContentsOf") { | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [1, 10, 11, 2, 3], inserts: [1, 2], deletes: [], updates: []))) | ||
} | ||
} | ||
|
||
describe("removeAtIndex") { | ||
beforeEach { | ||
observableCollection.removeAtIndex(1) | ||
} | ||
|
||
it("removeAtIndex") { | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [1, 3], inserts: [], deletes: [1], updates: []))) | ||
} | ||
} | ||
|
||
describe("removeLast") { | ||
beforeEach { | ||
observableCollection.removeLast() | ||
} | ||
|
||
it("removeLast") { | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [1, 2], inserts: [], deletes: [2], updates: []))) | ||
} | ||
} | ||
|
||
describe("removeAll") { | ||
beforeEach { | ||
observableCollection.removeAll() | ||
} | ||
|
||
it("removeAll") { | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [], inserts: [], deletes: [0, 1, 2], updates: []))) | ||
} | ||
} | ||
|
||
describe("subscript") { | ||
beforeEach { | ||
observableCollection[1] = 20 | ||
} | ||
|
||
it("subscript") { | ||
expect(observableCollection[1]) == 20 | ||
expect(observedEvents[1]).to(equal(ObservableCollectionEvent(collection: [1, 20, 3], inserts: [], deletes: [], updates: [1]))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Set | ||
|
||
describe("ObservableCollection<Set<T>>") { | ||
var observableCollection: ObservableCollection<Set<Int>>! | ||
|
||
beforeEach { | ||
observableCollection = ObservableCollection([1, 2, 3]) | ||
} | ||
|
||
context("when observed") { | ||
var observedEvents: [ObservableCollectionEvent<Set<Int>>] = [] | ||
|
||
beforeEach { | ||
observedEvents = [] | ||
observableCollection.observe(on: ImmediateExecutionContext) { | ||
observedEvents.append($0) | ||
} | ||
} | ||
|
||
it("generates initial event") { | ||
expect(observedEvents[0]).to(equal(ObservableCollectionEvent(collection: [1, 2, 3], inserts: [], deletes: [], updates: []))) | ||
} | ||
|
||
describe("contains") { | ||
it("contains") { | ||
expect(observableCollection.contains(1)) == true | ||
expect(observableCollection.contains(5)) == false | ||
} | ||
} | ||
|
||
describe("insert") { | ||
beforeEach { | ||
observableCollection.insert(0) | ||
} | ||
|
||
it("inserts") { | ||
expect(observedEvents[1].collection).to(contain(0)) | ||
} | ||
} | ||
|
||
describe("remove") { | ||
beforeEach { | ||
observableCollection.remove(1) | ||
} | ||
|
||
it("remove") { | ||
expect(observedEvents[1].collection).toNot(contain(0)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
public func equal<C: CollectionType where C.Generator.Element: Equatable>(expectedValue: ObservableCollectionEvent<C>) -> MatcherFunc<ObservableCollectionEvent<C>> { | ||
return MatcherFunc { actualExpression, failureMessage in | ||
failureMessage.postfixMessage = "equal <\(expectedValue)>" | ||
return try! actualExpression.evaluate()! == expectedValue | ||
} | ||
} | ||
|
||
|
||
func == <C: CollectionType where C.Generator.Element: Equatable, C.Index: Equatable>(left: ObservableCollectionEvent<C>, right: ObservableCollectionEvent<C>) -> Bool { | ||
return left.collection == right.collection && left.inserts == right.inserts && left.updates == right.updates && left.deletes == right.deletes | ||
} | ||
|
||
func == <C: CollectionType where C.Generator.Element: Equatable>(left: C, right: C) -> Bool { | ||
guard left.count == right.count else { return false } | ||
for (l, r) in zip(left, right) { | ||
if l != r { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|