+ assertEquals(
+ [...new Matcher(
+ /.(?<wow>(?:.(?=.))*)(.)?/u,
+ undefined,
+ ($) => $ === "success",
+ ).exec("success")],
+ ["success", "ucces", "s"],
+ );
+ });
+
+ it("[[Call]] calls the constraint if the match succeeds", () => {
+ const constraint = spy((_) => true);
+ const matcher = new Matcher("(.).*", undefined, constraint);
+ const result = matcher.exec({
+ toString() {
+ return "etaoin";
+ },
+ });
+ assertSpyCalls(constraint, 1);
+ assertStrictEquals(constraint.calls[0].args[0], "etaoin");
+ assertEquals([...constraint.calls[0].args[1]], ["etaoin", "e"]);
+ assertStrictEquals(constraint.calls[0].args[2], matcher);
+ assertStrictEquals(constraint.calls[0].self, undefined);
+ });
+
+ it("[[Call]] does not call the constraint if the match fails", () => {
+ const constraint = spy((_) => true);
+ const matcher = new Matcher("", undefined, constraint);
+ matcher.exec("failure");
+ assertSpyCalls(constraint, 0);