mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-08 20:53:21 +00:00
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { createRoot } from "solid-js"
|
|
import { createRefCountMap } from "./refcount"
|
|
import { pathKey } from "./path-key"
|
|
|
|
describe("createRefCountMap", () => {
|
|
test("removes an item after its last owner is disposed", () => {
|
|
const removed: string[] = []
|
|
const map = createRefCountMap(
|
|
(key) => key,
|
|
(key) => removed.push(key),
|
|
)
|
|
const first = createRoot((dispose) => {
|
|
map("/project")
|
|
return dispose
|
|
})
|
|
const second = createRoot((dispose) => {
|
|
map("/project")
|
|
return dispose
|
|
})
|
|
|
|
first()
|
|
expect(removed).toEqual([])
|
|
second()
|
|
expect(removed).toEqual(["/project"])
|
|
})
|
|
|
|
test("keeps equivalent path consumers until the last owner is disposed", () => {
|
|
const removed: string[] = []
|
|
const map = createRefCountMap(
|
|
(key) => key,
|
|
(key) => removed.push(key),
|
|
pathKey,
|
|
)
|
|
const first = createRoot((dispose) => {
|
|
map("C:\\repo")
|
|
return dispose
|
|
})
|
|
const second = createRoot((dispose) => {
|
|
map("C:/repo/")
|
|
return dispose
|
|
})
|
|
|
|
first()
|
|
expect(removed).toEqual([])
|
|
second()
|
|
expect(removed).toEqual(["C:/repo"])
|
|
})
|
|
})
|