| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { terminalClipboardText } from "./terminal-clipboard.mjs"; |
| 4 | |
| 5 | test("OSC 52 accepts UTF-8 clipboard writes within the shared clipboard limit", () => { |
| 6 | const text = "Claude 回复\n含有换行和 emoji 🖼️"; |
| 7 | assert.equal(terminalClipboardText(`c;${Buffer.from(text).toString("base64")}`), text); |
| 8 | assert.equal(terminalClipboardText(";"), ""); |
| 9 | const maximum = "x".repeat(2 * 1024 * 1024); |
| 10 | assert.equal(terminalClipboardText(`c;${Buffer.from(maximum).toString("base64")}`), maximum); |
| 11 | assert.equal(terminalClipboardText(`c;${Buffer.from(maximum + "x").toString("base64")}`), undefined); |
| 12 | }); |
| 13 | |
| 14 | test("OSC 52 ignores clipboard reads, other selections and malformed content", () => { |
| 15 | for (const value of ["c;?", "p;eA==", "c", "c;%%%", "c;eA", "c;e===", "c;/w=="]) |
| 16 | assert.equal(terminalClipboardText(value), undefined, value); |
| 17 | }); |