Skip to content

Commit

Permalink
Make range support a count of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc authored and kzaher committed Feb 7, 2019
1 parent 9404f89 commit 268ccda
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions RxSwift/Observables/Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
1 change: 1 addition & 0 deletions Sources/AllTestz/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
] }
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/RxSwiftTests/Observable+RangeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 268ccda

Please sign in to comment.