|
1 | 1 | import { parse } from "./parse.ts"; |
2 | 2 |
|
| 3 | +// `<<` is a special key in YAML 1.1 |
| 4 | +// https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/merge.ts |
| 5 | +test(`duplicate '<<' keys should always be allowed`, () => { |
| 6 | + const text = "<<: 1\n<<: 2"; |
| 7 | + expect(parse(text)).toBeDefined(); |
| 8 | + expect(parse(text, { uniqueKeys: false })).toBeDefined(); |
| 9 | + const ast = parse(text, { uniqueKeys: true }); |
| 10 | + expect(ast).toBeDefined(); |
| 11 | + const node = ast.children[0].children[1].children[0]; |
| 12 | + expect(node?.type).toBe("mapping"); |
| 13 | +}); |
| 14 | + |
3 | 15 | for (const { type, text } of [ |
4 | 16 | { type: "mapping", text: "a: 1\na: 2" }, |
5 | | - // `<<` is a special key in YAML 1.1 |
6 | | - // https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/merge.ts |
7 | | - // { type: "mapping", text: "<<: 1\n<<: 2" }, |
8 | 17 | { type: "flowMapping", text: `{"a":1,"a":2}` }, |
9 | 18 | { type: "flowMapping", text: `{"a":1,'a':2}` }, |
| 19 | + { type: "flowMapping", text: `{"<<":1,"<<":2}` }, |
10 | 20 | ]) { |
11 | 21 | test(`(${type}): duplicate keys in ${text}`, () => { |
12 | 22 | expect(() => parse(text)).toThrowError(`Map keys must be unique`); |
|
0 commit comments