Files
bun.sh/test/regression/issue/yaml-parse-syntax-error.test.ts
robobun fcd628424a Fix YAML.parse to throw SyntaxError instead of BuildMessage (#22924)
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>
2025-09-24 16:29:05 -07:00

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");
}
});