Download packages/app/src/utils/refcount.test.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/refcount.test.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/utils/refcount.test.ts
-
curl -L -o refcount.test.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/refcount.test.ts
1.22 kB
| 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"]) | |
| }) | |
| }) | |