Initial commit with translated description

This commit is contained in:
2026-03-29 10:19:19 +08:00
commit 5aa1f324c6
81 changed files with 27526 additions and 0 deletions

39
tests/openclaw.test.js Normal file
View File

@@ -0,0 +1,39 @@
const { describe, it } = require("node:test");
const assert = require("node:assert");
const { extractJSON } = require("../src/openclaw");
describe("openclaw module", () => {
describe("extractJSON()", () => {
it("returns null for null input", () => {
assert.strictEqual(extractJSON(null), null);
});
it("returns null for empty string", () => {
assert.strictEqual(extractJSON(""), null);
});
it("returns null for non-JSON text", () => {
assert.strictEqual(extractJSON("no json here"), null);
});
it("extracts JSON object from clean input", () => {
const result = extractJSON('{"key": "value"}');
assert.strictEqual(result, '{"key": "value"}');
});
it("extracts JSON array from clean input", () => {
const result = extractJSON("[1, 2, 3]");
assert.strictEqual(result, "[1, 2, 3]");
});
it("strips non-JSON prefix from output", () => {
const result = extractJSON('Some warning text\n{"key": "value"}');
assert.strictEqual(result, '{"key": "value"}');
});
it("handles prefix with special characters", () => {
const result = extractJSON('Doctor warnings: OK\n[{"id": 1}]');
assert.strictEqual(result, '[{"id": 1}]');
});
});
});