Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(yaml): test handling of omap #4851

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yaml/_type/omap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function resolveYamlOmap(data: Any): boolean {
}

function constructYamlOmap(data: Any): Any {
return data !== null ? data : [];
return data;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems to do nothing. Can we remove it?


export const omap = new Type("tag:yaml.org,2002:omap", {
Expand Down
28 changes: 28 additions & 0 deletions yaml/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,31 @@ Deno.test({
});
},
});

Deno.test({
name: "parse() handles omap type",
fn() {
const yaml = `--- !!omap
- Mark McGwire: 65
- Sammy Sosa: 63
- Ken Griffey: 58
`;
assertEquals(parse(yaml), [
{ "Mark McGwire": 65 },
{ "Sammy Sosa": 63 },
{ "Ken Griffey": 58 },
]);

// Invalid omap
// map entry is not an object
assertThrows(() => parse("--- !!omap\n"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the error class and message arguments for assertThrows()? Ditto for the other instances.

// map entry is not an object
assertThrows(() => parse("--- !!omap\n- 1"));
// map entry is empty object
assertThrows(() => parse("--- !!omap\n- {}"));
// map entry is an object with multiple keys
assertThrows(() => parse("--- !!omap\n- foo: 1\n bar: 2"));
// 2 map entries have the same key
assertThrows(() => parse("--- !!omap\n- foo: 1\n- foo: 2"));
},
});
Loading