- 品牌替换:OpenCode/opencode → AirCoding/aircoding(16+ 文件) - Logo ASCII art:修复 left/right 行数不匹配导致的启动崩溃 - 启动诊断:添加 OPENCODE_PRINT_TIMING 计时探针 - dev 模式默认 --pure 跳过外部插件加载 - AGENTS.md 模板:追加 AirCoding 多 Agent 专项段落 - architect prompt + plugin:强化 AGENTS.md 产出验证
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { lazy } from "../../src/util/lazy"
|
|
|
|
describe("util.lazy", () => {
|
|
test("should call function only once", () => {
|
|
let callCount = 0
|
|
const getValue = () => {
|
|
callCount++
|
|
return "expensive value"
|
|
}
|
|
|
|
const lazyValue = lazy(getValue)
|
|
|
|
expect(callCount).toBe(0)
|
|
|
|
const result1 = lazyValue()
|
|
expect(result1).toBe("expensive value")
|
|
expect(callCount).toBe(1)
|
|
|
|
const result2 = lazyValue()
|
|
expect(result2).toBe("expensive value")
|
|
expect(callCount).toBe(1)
|
|
})
|
|
|
|
test("should preserve the same reference", () => {
|
|
const obj = { value: 42 }
|
|
const lazyObj = lazy(() => obj)
|
|
|
|
const result1 = lazyObj()
|
|
const result2 = lazyObj()
|
|
|
|
expect(result1).toBe(obj)
|
|
expect(result2).toBe(obj)
|
|
expect(result1).toBe(result2)
|
|
})
|
|
|
|
test("should work with different return types", () => {
|
|
const lazyString = lazy(() => "string")
|
|
const lazyNumber = lazy(() => 123)
|
|
const lazyBoolean = lazy(() => true)
|
|
const lazyNull = lazy(() => null)
|
|
const lazyUndefined = lazy(() => undefined)
|
|
|
|
expect(lazyString()).toBe("string")
|
|
expect(lazyNumber()).toBe(123)
|
|
expect(lazyBoolean()).toBe(true)
|
|
expect(lazyNull()).toBe(null)
|
|
expect(lazyUndefined()).toBe(undefined)
|
|
})
|
|
})
|