Skip to content

Commit a8db615

Browse files
committed
Doc coverage - 100%
1 parent a5d3824 commit a8db615

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

Sources/M3U8Decoder/Atomic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ func synchronized<T>(_ obj: AnyObject, closure: () -> T) -> T {
3737
class Atomic<T>: @unchecked Sendable {
3838
var _value: T
3939

40-
public init(_ value: T) {
40+
init(_ value: T) {
4141
_value = value
4242
}
4343

44-
public var value: T {
44+
var value: T {
4545
get {
4646
synchronized(self) { _value }
4747
}

Tests/M3U8DecoderTests/M3U8DecoderTests.swift

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
import XCTest
22
import Combine
33

4-
@testable
54
import M3U8Decoder
65

76

7+
class SendableArray<T>: @unchecked Sendable {
8+
private var array: [T]
9+
10+
private func sync<U>(closure: () -> U) -> U {
11+
objc_sync_enter(self)
12+
defer {
13+
objc_sync_exit(self)
14+
}
15+
return closure()
16+
}
17+
18+
init(_ array: [T]) {
19+
self.array = array
20+
}
21+
22+
subscript(i: Int) -> T {
23+
get {
24+
sync { array[i] }
25+
}
26+
set {
27+
sync { array[i] = newValue }
28+
}
29+
}
30+
31+
var count: Int {
32+
sync { array.count }
33+
}
34+
35+
func forEach(body: (T) -> Void) {
36+
sync {
37+
array.forEach(body)
38+
}
39+
}
40+
}
41+
42+
843
final class M3U8_All: XCTestCase {
944

1045
func test_error_empty() {
@@ -575,12 +610,12 @@ final class M3U8_All: XCTestCase {
575610

576611
let decoder = M3U8Decoder()
577612

578-
let playlists = AtomicArray<Playlist?>(repeating: nil, count: 10)
613+
let playlists = SendableArray([Playlist?](repeating: nil, count: 10))
579614
DispatchQueue.concurrentPerform(iterations: playlists.count) {
580615
playlists[$0] = try? decoder.decode(Playlist.self, from: text)
581616
}
582617

583-
playlists.value.forEach {
618+
playlists.forEach {
584619
XCTAssert($0?.ext_x_targetduration == 10)
585620
XCTAssert($0?.segments.count == 3)
586621
XCTAssert($0?.segments[0].extinf.duration == 9.009)

0 commit comments

Comments
 (0)