[test] Breakup named-captures_test to preserve test coverage.

Apparently the web implementation of RegExp has drifted from the native implementation in a very subtle way. To prevent further drift, this CL refactors named-captures_test into two tests, one which fails on all web backends currently(named_captures_2_test), and one that passes on all backends(named-captures_test, named unchanged to preserve history).

Change-Id: Ie94185948873fe3e592c10a45c6127dc6d0a4238
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267282
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
This commit is contained in:
Joshua Litt 2022-11-16 16:19:34 +00:00 committed by Commit Queue
parent 0210b58d68
commit 2e0784a6c5
5 changed files with 130 additions and 28 deletions

View file

@ -368,7 +368,7 @@
"../../../tests/corelib/regexp/malformed-escapes_test.dart",
"../../../tests/corelib/regexp/many-brackets_test.dart",
"../../../tests/corelib/regexp/multiline_test.dart",
"../../../tests/corelib/regexp/named-captures_test.dart",
"../../../tests/corelib/regexp/named_captures_test.dart",
"../../../tests/corelib/regexp/negative-special-characters_test.dart",
"../../../tests/corelib/regexp/no-extensions_test.dart",
"../../../tests/corelib/regexp/non-bmp_test.dart",
@ -3772,7 +3772,7 @@
"../../../tests/corelib_2/regexp/malformed-escapes_test.dart",
"../../../tests/corelib_2/regexp/many-brackets_test.dart",
"../../../tests/corelib_2/regexp/multiline_test.dart",
"../../../tests/corelib_2/regexp/named-captures_test.dart",
"../../../tests/corelib_2/regexp/named_captures_test.dart",
"../../../tests/corelib_2/regexp/negative-special-characters_test.dart",
"../../../tests/corelib_2/regexp/no-extensions_test.dart",
"../../../tests/corelib_2/regexp/non-bmp_test.dart",

View file

@ -0,0 +1,46 @@
// Copyright (c) 2022, the Dart project authors. All rights reserved.
// Copyright 2017 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import 'v8_regexp_utils.dart';
// These test cases really belong in `named_captures_test` but they've been
// broken out because they currently fail on all web backends.
void main() {
assertThrows(() => RegExp(r"(?<$𐒤>a)"));
assertThrows(() => RegExp("(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp("(?<a\uD801>.)"));
assertThrows(() => RegExp(r"(?<a\uD801>.)"));
assertThrows(() => RegExp("(?<a\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uDCA4>.)"));
assertThrows(() => RegExp("(?<a\u{104A4}>.)"));
assertThrows(() => RegExp(r"(?<a\u{104A4}>.)"));
assertThrows(() => RegExp("(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\\u{110000}>.)"));
}

View file

@ -30,6 +30,10 @@ import 'package:expect/expect.dart';
import 'v8_regexp_utils.dart';
// TODO(50437): A number of test cases in this group currently fail on
// web backends, and so those cases were moved to `named_captures_2_test`.
// To highlight the connection between these tests, those test cases have been
// left in this file but commented out.
void main() {
void execRE(RegExp re, String input, List<String?> expectedResult) {
assertTrue(re.hasMatch(input));
@ -261,7 +265,7 @@ void main() {
execStringGroups(r"(?<π>a)", "bab", {"π": "a"}, unicode: false);
execStringGroups(r"(?<$>a)", "bab", {"\$": "a"}, unicode: false);
execStringGroups(r"(?<_>a)", "bab", {"_": "a"}, unicode: false);
assertThrows(() => RegExp(r"(?<$𐒤>a)"));
// assertThrows(() => RegExp(r"(?<$𐒤>a)"));
execStringGroups(r"(?<ಠ_ಠ>a)", "bab", {"ಠ_ಠ": "a"}, unicode: false);
// ID_Continue but not ID_Start.
assertThrows(() => RegExp(r"/(?<❤>a)"));
@ -322,17 +326,17 @@ void main() {
// Also checking non-unicode patterns, where surrogate pairs will not
// be combined (so only \u0041 will have any success).
assertThrows(() => RegExp("(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp("(?<a\uD801>.)"));
assertThrows(() => RegExp(r"(?<a\uD801>.)"));
assertThrows(() => RegExp("(?<a\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uDCA4>.)"));
// assertThrows(() => RegExp("(?<a\uD801\uDCA4>.)"));
// assertThrows(() => RegExp(r"(?<a\uD801\uDCA4>.)"));
// assertThrows(() => RegExp("(?<a\uD801>.)"));
// assertThrows(() => RegExp(r"(?<a\uD801>.)"));
// assertThrows(() => RegExp("(?<a\uDCA4>.)"));
// assertThrows(() => RegExp(r"(?<a\uDCA4>.)"));
assertTrue(RegExp("(?<\u0041>.)").hasMatch("a"));
assertTrue(RegExp(r"(?<\u0041>.)").hasMatch("a"));
assertThrows(() => RegExp("(?<a\u{104A4}>.)"));
assertThrows(() => RegExp(r"(?<a\u{104A4}>.)"));
assertThrows(() => RegExp("(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\\u{110000}>.)"));
// assertThrows(() => RegExp("(?<a\u{104A4}>.)"));
// assertThrows(() => RegExp(r"(?<a\u{104A4}>.)"));
// assertThrows(() => RegExp("(?<a\u{10FFFF}>.)"));
// assertThrows(() => RegExp(r"(?<a\u{10FFFF}>.)"));
// assertThrows(() => RegExp(r"(?<a\\u{110000}>.)"));
}

View file

@ -0,0 +1,48 @@
// Copyright (c) 2022, the Dart project authors. All rights reserved.
// Copyright 2017 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// @dart = 2.9
import 'v8_regexp_utils.dart';
// These test cases really belong in `named_captures_test` but they've been
// broken out because they currently fail on all web backends.
void main() {
assertThrows(() => RegExp(r"(?<$𐒤>a)"));
assertThrows(() => RegExp("(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp("(?<a\uD801>.)"));
assertThrows(() => RegExp(r"(?<a\uD801>.)"));
assertThrows(() => RegExp("(?<a\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uDCA4>.)"));
assertThrows(() => RegExp("(?<a\u{104A4}>.)"));
assertThrows(() => RegExp(r"(?<a\u{104A4}>.)"));
assertThrows(() => RegExp("(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\\u{110000}>.)"));
}

View file

@ -32,6 +32,10 @@ import 'package:expect/expect.dart';
import 'v8_regexp_utils.dart';
// TODO(50437): A number of test cases in this group currently fail on
// web backends, and so those cases were moved to `named_captures_2_test`.
// To highlight the connection between these tests, those test cases have been
// left in this file but commented out.
void main() {
void execRE(RegExp re, String input, List<String> expectedResult) {
assertTrue(re.hasMatch(input));
@ -39,7 +43,7 @@ void main() {
}
void execString(String pattern, String input, List<String> expectedResult,
{bool unicode = true, bool caseSensitive: false}) {
{bool unicode = true, bool caseSensitive = false}) {
execRE(RegExp(pattern, unicode: unicode, caseSensitive: caseSensitive),
input, expectedResult);
}
@ -54,7 +58,7 @@ void main() {
void execStringGroups(
String pattern, String input, Map<String, String> expectedResults,
{bool unicode = true, bool caseSensitive: false}) {
{bool unicode = true, bool caseSensitive = false}) {
namedRE(RegExp(pattern, unicode: unicode, caseSensitive: caseSensitive),
input, expectedResults);
}
@ -263,7 +267,7 @@ void main() {
execStringGroups(r"(?<π>a)", "bab", {"π": "a"}, unicode: false);
execStringGroups(r"(?<$>a)", "bab", {"\$": "a"}, unicode: false);
execStringGroups(r"(?<_>a)", "bab", {"_": "a"}, unicode: false);
assertThrows(() => RegExp(r"(?<$𐒤>a)"));
// assertThrows(() => RegExp(r"(?<$𐒤>a)"));
execStringGroups(r"(?<ಠ_ಠ>a)", "bab", {"ಠ_ಠ": "a"}, unicode: false);
// ID_Continue but not ID_Start.
assertThrows(() => RegExp(r"/(?<❤>a)"));
@ -324,17 +328,17 @@ void main() {
// Also checking non-unicode patterns, where surrogate pairs will not
// be combined (so only \u0041 will have any success).
assertThrows(() => RegExp("(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uD801\uDCA4>.)"));
assertThrows(() => RegExp("(?<a\uD801>.)"));
assertThrows(() => RegExp(r"(?<a\uD801>.)"));
assertThrows(() => RegExp("(?<a\uDCA4>.)"));
assertThrows(() => RegExp(r"(?<a\uDCA4>.)"));
// assertThrows(() => RegExp("(?<a\uD801\uDCA4>.)"));
// assertThrows(() => RegExp(r"(?<a\uD801\uDCA4>.)"));
// assertThrows(() => RegExp("(?<a\uD801>.)"));
// assertThrows(() => RegExp(r"(?<a\uD801>.)"));
// assertThrows(() => RegExp("(?<a\uDCA4>.)"));
// assertThrows(() => RegExp(r"(?<a\uDCA4>.)"));
assertTrue(RegExp("(?<\u0041>.)").hasMatch("a"));
assertTrue(RegExp(r"(?<\u0041>.)").hasMatch("a"));
assertThrows(() => RegExp("(?<a\u{104A4}>.)"));
assertThrows(() => RegExp(r"(?<a\u{104A4}>.)"));
assertThrows(() => RegExp("(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\u{10FFFF}>.)"));
assertThrows(() => RegExp(r"(?<a\\u{110000}>.)"));
// assertThrows(() => RegExp("(?<a\u{104A4}>.)"));
// assertThrows(() => RegExp(r"(?<a\u{104A4}>.)"));
// assertThrows(() => RegExp("(?<a\u{10FFFF}>.)"));
// assertThrows(() => RegExp(r"(?<a\u{10FFFF}>.)"));
// assertThrows(() => RegExp(r"(?<a\\u{110000}>.)"));
}