Skip to content

Commit

Permalink
test(yaml): test anchor and alias handling of parse() (#5190)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jun 29, 2024
1 parent 05f25df commit 48bff59
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions yaml/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,57 @@ Deno.test({
},
});

Deno.test("parse() handles anchors and aliases", () => {
assertEquals(
parse(`- &anchor Foo
- *anchor`),
["Foo", "Foo"],
);
assertEquals(
parse(`- &anchor 1
- *anchor`),
[1, 1],
);
assertEquals(
parse(`- &anchor { Monday: 3, Tuesday: 4 }
- *anchor`),
[{ Monday: 3, Tuesday: 4 }, { Monday: 3, Tuesday: 4 }],
);
assertEquals(
parse(`- &anchor
Monday: 3
Tuesday: 4
- <<: *anchor
Wednesday: 5`),
[
{ Monday: 3, Tuesday: 4 },
{ Monday: 3, Tuesday: 4, Wednesday: 5 },
],
);
assertEquals(
parse(`- &anchor !!binary "SGVsbG8="
- *anchor`),
[
new Uint8Array([72, 101, 108, 108, 111]),
new Uint8Array([72, 101, 108, 108, 111]),
],
);
assertThrows(
() =>
parse(`- &anchor Foo
- *anchor2`),
YamlError,
'unidentified alias "anchor2" at line 2, column 11:\n - *anchor2\n ^',
);
assertThrows(
() =>
parse(`- &anchor Foo
- *`),
YamlError,
"name of an alias node must contain at least one character at line 2, column 4:\n - *\n ^",
);
});

Deno.test("parse() handles escaped strings in double quotes", () => {
assertEquals(parse('"\\"bar\\""'), '"bar"');
assertEquals(parse('"\\x30\\x31"'), "01");
Expand Down

0 comments on commit 48bff59

Please sign in to comment.