From 42fafe33bba2c6887b8dcff357dfa500ec1e6726 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 4 Sep 2026 11:30:25 -0300 Subject: [PATCH] Add some more ECMA validity tests Signed-off-by: Juan Cruz Viotti --- test/regex/regex_is_ecma_test.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/regex/regex_is_ecma_test.cc b/test/regex/regex_is_ecma_test.cc index 483840138..f811371dd 100644 --- a/test/regex/regex_is_ecma_test.cc +++ b/test/regex/regex_is_ecma_test.cc @@ -870,6 +870,16 @@ TEST(script_value_alias) { EXPECT_TRUE(sourcemeta::core::is_regex_ecma("\\p{Script=Grek}")); } +// ECMA-262 22.2.1 defers to PropertyValueAliases.txt, which lists this value +// even though no code point carries it, so Node turns it down and we do not +TEST(script_value_that_no_code_point_carries) { + EXPECT_TRUE(sourcemeta::core::is_regex_ecma("\\p{Script=Hrkt}")); +} + +TEST(script_value_alias_that_no_code_point_carries) { + EXPECT_TRUE(sourcemeta::core::is_regex_ecma("\\p{sc=Katakana_Or_Hiragana}")); +} + // Without a Unicode reading Annex B of ECMA-262 has Node take this literally TEST(script_value_unknown) { EXPECT_FALSE(sourcemeta::core::is_regex_ecma("\\p{Script=Nowhere}")); @@ -908,6 +918,22 @@ TEST(set_notation_strings_cannot_be_negated) { EXPECT_FALSE(sourcemeta::core::is_regex_ecma("[^\\q{abc}]")); } +// ECMA-262 22.2.1.8 carries the flag past a range, as a union that starts with +// one returns "MayContainStrings of the ClassUnion" that trails it +TEST(set_notation_strings_cannot_be_negated_after_a_range) { + EXPECT_FALSE(sourcemeta::core::is_regex_ecma("[^a-z\\q{ab}]")); +} + +// ECMA-262 22.2.1.8 gives the empty string the same flag, as the empty +// alternative of a string disjunction "returns true" +TEST(set_notation_empty_string_cannot_be_negated) { + EXPECT_FALSE(sourcemeta::core::is_regex_ecma("[^\\q{}]")); +} + +TEST(set_notation_one_character_string_can_be_negated) { + EXPECT_TRUE(sourcemeta::core::is_regex_ecma("[^\\q{a}]")); +} + // Only the set notation reading rejects this, so Node accepts it TEST(set_notation_range_cannot_lead_an_operator) { EXPECT_FALSE(sourcemeta::core::is_regex_ecma("[a-z--[aeiou]]"));