Skip to content

Commit

Permalink
Add unit test for AtomicBox and ObjectCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Sep 16, 2024
1 parent 8c59edd commit afb97a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Tests/OpenSwiftUICoreTests/Data/Other/AtomicBoxTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AtomicBoxTests.swift
// OpenSwiftUICoreTests

@testable import OpenSwiftUICore
import Testing

struct AtomicBoxTests {
@Test
func expressibleByNilLiteral() {
let box: AtomicBox<Int?> = AtomicBox()
#expect(box.wrappedValue == nil)
box.wrappedValue = 3
#expect(box.wrappedValue == 3)
}

@Test
func access() {
@AtomicBox var box: Int = 3
#expect($box.access { $0.description } == "3")
}
}
16 changes: 16 additions & 0 deletions Tests/OpenSwiftUICoreTests/Data/Other/ObjectCacheTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ObjectCacheTests.swift
// OpenSwiftUICoreTests

@testable import OpenSwiftUICore
import Testing

struct ObjectCacheTests {
@Test
func example() {
let cache: ObjectCache<Int, String> = ObjectCache { key in "\(key)" }
#expect(cache[0] == "0")
#expect(cache[1] == "1")
#expect(cache[0] == "0")
}
}

0 comments on commit afb97a7

Please sign in to comment.