Skip to content

Commit

Permalink
test(yaml): add regexp type tests (#5862)
Browse files Browse the repository at this point in the history
* initial commit

* update

* update
  • Loading branch information
timreichen authored Aug 29, 2024
1 parent fab118b commit 0b59bfd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions yaml/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,3 +1086,47 @@ Deno.test("parse() handles string", () => {
assertEquals(parse("!!str"), "");
assertEquals(parse("!!str 2002-04-28"), "2002-04-28");
});

Deno.test({
name: "parse() handles regexp value with extended schema option",
fn() {
assertEquals(
parse("!<tag:yaml.org,2002:js/regexp> ^foo$\n", { schema: "extended" }),
/^foo$/,
);
assertEquals(
parse("!<tag:yaml.org,2002:js/regexp> /^foo$/\n", { schema: "extended" }),
/^foo$/,
);
assertEquals(
parse("!<tag:yaml.org,2002:js/regexp> /^foo$/g\n", {
schema: "extended",
}),
/^foo$/g,
);
assertThrows(
() =>
parse("!<tag:yaml.org,2002:js/regexp> /^foo$/gg\n", {
schema: "extended",
}),
SyntaxError,
"Cannot resolve a node",
);
assertThrows(
() =>
parse("!<tag:yaml.org,2002:js/regexp> \n", {
schema: "extended",
}),
SyntaxError,
"Cannot resolve a node",
);
assertThrows(
() =>
parse("!<tag:yaml.org,2002:js/regexp> /\n", {
schema: "extended",
}),
SyntaxError,
"Cannot resolve a node",
);
},
});

0 comments on commit 0b59bfd

Please sign in to comment.