Permalink
Browse files

Make range support a count of 0

  • Loading branch information...
freak4pc authored and kzaher committed Feb 7, 2019
1 parent 9404f89 commit 268ccda7c3786ff202f6491605ef45413dbce314
Showing with 15 additions and 2 deletions.
  1. +2 −2 RxSwift/Observables/Range.swift
  2. +1 −0 Sources/AllTestz/main.swift
  3. +12 −0 Tests/RxSwiftTests/Observable+RangeTests.swift
@@ -28,11 +28,11 @@ final private class RangeProducer<E: RxAbstractInteger>: Producer<E> {
fileprivate let _scheduler: ImmediateSchedulerType

init(start: E, count: E, scheduler: ImmediateSchedulerType) {
if count < 0 {
guard count >= 0 else {
rxFatalError("count can't be negative")
}

if start &+ (count - 1) < start {
guard start &+ (count - 1) >= start || count == 0 else {
rxFatalError("overflow of count")
}

@@ -1097,6 +1097,7 @@ final class ObservableRangeTest_ : ObservableRangeTest, RxTestCase {

static var allTests: [(String, (ObservableRangeTest_) -> () -> Void)] { return [
("testRange_Boundaries", ObservableRangeTest.testRange_Boundaries),
("testRange_ZeroCount", ObservableRangeTest.testRange_ZeroCount),
("testRange_Dispose", ObservableRangeTest.testRange_Dispose),
] }
}
@@ -27,6 +27,18 @@ extension ObservableRangeTest {
])
}

func testRange_ZeroCount() {
let scheduler = TestScheduler(initialClock: 0)

let res = scheduler.start {
Observable.range(start: 0, count: 0, scheduler: scheduler)
}

XCTAssertEqual(res.events, [
.completed(201)
])
}

func testRange_Dispose() {
let scheduler = TestScheduler(initialClock: 0)

0 comments on commit 268ccda

Please sign in to comment.