use super::{Failed, Refused, V, check};
use serde_json::json;
#[test]
fn matches_finds_the_pattern_in_a_part_of_the_text() {
check(&[
(r#""release 1.2".matches(r"\d+\.\d+")"#, V(json!(true))),
(r#""release 1.2".matches(r"^\d")"#, V(json!(false))),
(r#"md.doc.title.matches("(?i)^release$")"#, V(json!(true))),
(
r#"md.data.sales.filter(s, s.region.matches("^e")).size()"#,
V(json!(2)),
),
]);
}
#[test]
fn captures_gives_the_groups_when_the_whole_text_matches() {
check(&[
(
r#""2026-10".captures(r"(\d+)-(\d+)")"#,
V(json!(["2026", "10"])),
),
(
r#""2026-10-21".captures(r"(\d+)-(\d+)").hasValue()"#,
V(json!(false)),
),
(
r#""v2".captures(r"v(\d+)(\.\d+)?").value()"#,
V(json!(["2", ""])),
),
(r#""a".captures("a|b").value()"#, V(json!([]))),
(
r#"md.doc.released.captures(r"(\d+)-.*").optMap(g, int(g[0])).orValue(0)"#,
V(json!(2026)),
),
]);
}
#[test]
fn the_pattern_is_a_string_literal_in_re2_s_syntax() {
check(&[
(r#""a".matches(md.doc.title)"#, Refused(13)),
(r#""a".matches("[")"#, Refused(13)),
(r#""a".captures(r"\x{41}\U00000041")"#, Refused(14)),
(r#""a".matches(r"(?x)a")"#, Refused(13)),
("1.matches(\"a\")", Refused(3)),
]);
}
#[test]
fn a_receiver_the_checker_cant_type_is_checked_when_evaluated() {
check(&[(r#"[1, "a"][0].matches("a")"#, Failed(13))]);
}