mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
YAML.parse now throws SyntaxError for invalid syntax matching JSON.parse behavior --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { YAML } from "bun";
|
|
import { expect, test } from "bun:test";
|
|
|
|
test("YAML.parse throws SyntaxError like JSON.parse", () => {
|
|
// Test that YAML.parse throws a SyntaxError for invalid YAML
|
|
try {
|
|
YAML.parse("[ invalid");
|
|
throw new Error("Should have thrown");
|
|
} catch (e) {
|
|
expect(e).toBeInstanceOf(SyntaxError);
|
|
expect(e.constructor.name).toBe("SyntaxError");
|
|
expect(e.message).toContain("YAML Parse error");
|
|
}
|
|
|
|
// Test with another invalid YAML
|
|
try {
|
|
YAML.parse("{ key: value");
|
|
throw new Error("Should have thrown");
|
|
} catch (e) {
|
|
expect(e).toBeInstanceOf(SyntaxError);
|
|
expect(e.constructor.name).toBe("SyntaxError");
|
|
expect(e.message).toContain("YAML Parse error");
|
|
}
|
|
|
|
// Test with invalid YAML structure
|
|
try {
|
|
YAML.parse(":\n : - invalid");
|
|
throw new Error("Should have thrown");
|
|
} catch (e) {
|
|
expect(e).toBeInstanceOf(SyntaxError);
|
|
expect(e.constructor.name).toBe("SyntaxError");
|
|
expect(e.message).toContain("YAML Parse error");
|
|
}
|
|
|
|
// Compare with JSON.parse behavior
|
|
try {
|
|
JSON.parse("{ invalid");
|
|
throw new Error("Should have thrown");
|
|
} catch (e) {
|
|
expect(e).toBeInstanceOf(SyntaxError);
|
|
expect(e.constructor.name).toBe("SyntaxError");
|
|
expect(e.message).toContain("JSON Parse error");
|
|
}
|
|
});
|