Skip to content

Commit

Permalink
[BitArray] Fix description implementation; update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentey committed Feb 1, 2024
1 parent e01391e commit ae641c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Sources/BitCollections/BitArray/BitArray+Descriptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ extension UInt8 {
internal static var _ascii1: Self { 49 }

@inline(__always)
internal static var _asciiLT: Self { 49 }
internal static var _asciiLT: Self { 60 }

@inline(__always)
internal static var _asciiGT: Self { 49 }
internal static var _asciiGT: Self { 62 }
}

extension BitArray: CustomStringConvertible {
Expand Down Expand Up @@ -62,15 +62,15 @@ extension BitArray {
var result: String
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
result = String(unsafeUninitializedCapacity: self.count + 2) { target in
target.initializeElement(at: count - 1, to: ._asciiGT)
var i = count - 2
target.initializeElement(at: count + 1, to: ._asciiGT)
var i = count
for v in self {
target.initializeElement(at: i, to: v ? ._ascii1 : ._ascii0)
i &-= 1
}
assert(i == 0)
target.initializeElement(at: 0, to: ._asciiLT)
return count
return count + 2
}
} else {
result = "<"
Expand Down
12 changes: 6 additions & 6 deletions Tests/BitCollectionsTests/BitArrayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -959,24 +959,24 @@ final class BitArrayTests: CollectionTestCase {

func test_description() {
let a: BitArray = []
expectEqual("\(a)", "")
expectEqual("\(a)", "<>")

let b: BitArray = [true, false, true, true, true]
expectEqual("\(b)", "11101")
expectEqual("\(b)", "<11101>")

let c: BitArray = [false, false, false, false, true, true, true, false]
expectEqual("\(c)", "01110000")
expectEqual("\(c)", "<01110000>")
}

func test_debugDescription() {
let a: BitArray = []
expectEqual("\(String(reflecting: a))", "[]")
expectEqual("\(String(reflecting: a))", "<>")

let b: BitArray = [true, false, true, true, true]
expectEqual("\(String(reflecting: b))", "11101")
expectEqual("\(String(reflecting: b))", "<11101>")

let c: BitArray = [false, false, false, false, true, true, true, false]
expectEqual("\(String(reflecting: c))", "01110000")
expectEqual("\(String(reflecting: c))", "<01110000>")
}

func test_mirror() {
Expand Down

0 comments on commit ae641c3

Please sign in to comment.