test(yaml): add regexp type tests (#5862)

* initial commit

* update

* update
This commit is contained in:
Tim Reichen 2024-08-30 00:53:08 +02:00 committed by GitHub
parent fab118b515
commit 0b59bfd465
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1086,3 +1086,47 @@ Deno.test("parse() handles string", () => {
assertEquals(parse("!!str"), ""); assertEquals(parse("!!str"), "");
assertEquals(parse("!!str 2002-04-28"), "2002-04-28"); 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",
);
},
});