Skip to content

Commit

Permalink
Add IndexSet overload init to make sure Sequence-based init is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Oct 23, 2024
1 parent d2f8dcd commit 5cd5068
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Rearrange/IndexSet+NSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public extension IndexSet {
self.init(integersIn: Range<IndexSet.Element>(range)!)
}

init(_ range: NSRange) {
self.init(integersIn: range)
}

init(ranges: [NSRange]) {
self.init()

Expand Down
10 changes: 10 additions & 0 deletions Tests/RearrangeTests/IndexSetExtenstionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
import XCTest

final class IndexSetExtenstionTests: XCTestCase {
func testInitialization() {
let setA = IndexSet(integersIn: NSRange(0..<5))
let setB = IndexSet(NSRange(0..<5))
let setC = IndexSet(arrayLiteral: 0, 1, 2, 3, 4)

XCTAssertEqual(setA, setB)
XCTAssertEqual(setA, setC)
XCTAssertEqual(setB, setC)
}

func testSpanningRange() {
var set = IndexSet()

Expand Down

0 comments on commit 5cd5068

Please sign in to comment.