-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.test.ts
More file actions
63 lines (53 loc) · 1.88 KB
/
index.test.ts
File metadata and controls
63 lines (53 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { describe, it } from "node:test"
import assert from "node:assert/strict"
import { truncate, extractTextFromParts } from "../src/index"
describe("truncate", () => {
it("returns string unchanged when under maxLen", () => {
assert.strictEqual(truncate("hello", 10), "hello")
})
it("returns string unchanged when exactly maxLen", () => {
assert.strictEqual(truncate("hello", 5), "hello")
})
it("truncates and adds ellipsis when over maxLen", () => {
assert.strictEqual(truncate("hello world", 8), "hello...")
})
it("handles maxLen of 3 (minimum for ellipsis)", () => {
assert.strictEqual(truncate("hello", 3), "...")
})
it("handles empty string", () => {
assert.strictEqual(truncate("", 10), "")
})
})
describe("extractTextFromParts", () => {
it("extracts text from text parts", () => {
const parts = [
{ type: "text" as const, text: "hello" },
{ type: "text" as const, text: "world" },
]
assert.strictEqual(extractTextFromParts(parts), "hello world")
})
it("skips non-text parts", () => {
const parts = [
{ type: "text" as const, text: "hello" },
{ type: "tool_use" as const, id: "1", name: "bash", input: {} },
{ type: "text" as const, text: "world" },
] as any[]
assert.strictEqual(extractTextFromParts(parts), "hello world")
})
it("skips text parts with empty text", () => {
const parts = [
{ type: "text" as const, text: "" },
{ type: "text" as const, text: "hello" },
]
assert.strictEqual(extractTextFromParts(parts), "hello")
})
it("returns empty string for no parts", () => {
assert.strictEqual(extractTextFromParts([]), "")
})
it("returns empty string when all parts are non-text", () => {
const parts = [
{ type: "tool_use" as const, id: "1", name: "bash", input: {} },
] as any[]
assert.strictEqual(extractTextFromParts(parts), "")
})
})