39 lines
1.1 KiB
Swift
39 lines
1.1 KiB
Swift
import Foundation
|
|
import HelderCore
|
|
import HelderServices
|
|
|
|
/// Declared class names and lookups set by the test; counts invalidations.
|
|
final class FakeSymbols: SymbolServicing, @unchecked Sendable {
|
|
private struct State {
|
|
var declared: Set<String> = []
|
|
var lookups: [String: SymbolLookup] = [:]
|
|
var invalidations = 0
|
|
var nameLoads = 0
|
|
}
|
|
|
|
private let state = Locked(State())
|
|
|
|
var declared: Set<String> {
|
|
get { state.current.declared }
|
|
set { state.mutate { $0.declared = newValue } }
|
|
}
|
|
|
|
var lookups: [String: SymbolLookup] {
|
|
get { state.current.lookups }
|
|
set { state.mutate { $0.lookups = newValue } }
|
|
}
|
|
|
|
var invalidations: Int { state.current.invalidations }
|
|
var nameLoads: Int { state.current.nameLoads }
|
|
|
|
func names() async -> Set<String> {
|
|
state.mutate { state in
|
|
state.nameLoads += 1
|
|
return state.declared
|
|
}
|
|
}
|
|
|
|
func lookup(_ name: String) async -> SymbolLookup { state.current.lookups[name] ?? .empty(name) }
|
|
func invalidate() async { state.mutate { $0.invalidations += 1 } }
|
|
}
|