import { It, ItThrows } from "../test-utils";
import "./last";

It("Finds the last item of a sequence", (s) => s.last(), 3);
It(
  "Finds the last matching item of a sequence",
  (s) => s.last((i) => i === 2),
  2
);
ItThrows(
  "Throws if no matches",
  (s) => s.last((i) => i === 4),
  new Error("No matches for sequence")
);
ItThrows(
  "Throws if empty sequence",
  (s) => s.last(),
  new Error("No matches for sequence"),
  []
);
It(
  "Returns undefined when there are no matches and allowed",
  (s) => s.last((i) => i === 4, "or-default"),
  undefined
);
It(
  "Returns undefined when sequence is empty",
  (s) => s.last("or-default"),
  undefined,
  []
);
