Migrated test block 23 to Dart 2.0.
No major changes. Updated regexp_test.dart to not use the same variable for Strings and Regexps. BUG= R=rnystrom@google.com Review-Url: https://codereview.chromium.org/2990603003 .
This commit is contained in:
@@ -270,14 +270,6 @@ regexp/non-capturing-groups_test: Crash
|
||||
regexp/parentheses_test: Crash
|
||||
regexp/pcre-test-4_test: Crash
|
||||
regexp/pcre_test: Crash
|
||||
regexp/range-out-of-order_test: Crash
|
||||
regexp/regexp_kde_test: Crash
|
||||
regexp/regexp_test: Crash
|
||||
regexp/regress-regexp-codeflush_test: Crash
|
||||
regexp/standalones_test: Crash
|
||||
regexp/toString_test: Crash
|
||||
regexp/unicode-handling_test: Crash
|
||||
regexp/unicodeCaseInsensitive_test: Crash
|
||||
regress_r21715_test: RuntimeError
|
||||
set_containsAll_test: Crash
|
||||
set_contains_test: Crash
|
||||
@@ -441,13 +433,6 @@ regexp/non-character_test: Crash
|
||||
regexp/non-greedy-parentheses_test: Crash
|
||||
regexp/norepeat_test: Crash
|
||||
regexp/overflow_test: Crash
|
||||
regexp/quantified-assertions_test: Crash
|
||||
regexp/range-bound-ffff_test: Crash
|
||||
regexp/ranges-and-escaped-hyphens_test: Crash
|
||||
regexp/regress-6-9-regexp_test: Crash
|
||||
regexp/regress-regexp-construct-result_test: Crash
|
||||
regexp/repeat-match-waldemar_test: Crash
|
||||
regexp/results-cache_test: Crash
|
||||
regexp/stack-overflow2_test: Crash
|
||||
regexp/stack-overflow_test: Crash
|
||||
regexp/zero-length-alternatives_test: Crash
|
||||
|
||||
@@ -50,6 +50,12 @@ const_list_set_range_test: RuntimeError # Issue 29921
|
||||
compare_to2_test: RuntimeError # Issue 30170
|
||||
date_time10_test: RuntimeError # Issue 29921
|
||||
hash_set_test/01: RuntimeError # Issue 29921
|
||||
regexp/quantified-assertions_test: RuntimeError # Issue 29921
|
||||
regexp/range-bound-ffff_test: RuntimeError # Issue 29921
|
||||
regexp/range-out-of-order_test: RuntimeError # Issue 29921
|
||||
regexp/ranges-and-escaped-hyphens_test: RuntimeError # Issue 29921
|
||||
regexp/regress-6-9-regexp_test: RuntimeError # Issue 29921
|
||||
regexp/regress-6-9-regexp_test: RuntimeError # Issue 29921
|
||||
regexp/regress-regexp-codeflush_test: RuntimeError # Issue 29921
|
||||
regexp/regress-regexp-construct-result_test: RuntimeError # Issue 29921
|
||||
regexp/repeat-match-waldemar_test: RuntimeError # Issue 29921
|
||||
@@ -275,6 +281,9 @@ int_from_environment3_test/05: Crash
|
||||
int_modulo_arith_test/bignum: Crash
|
||||
int_modulo_arith_test/modPow: Crash
|
||||
int_modulo_arith_test/none: Crash
|
||||
regexp/range-out-of-order_test: Crash
|
||||
regexp/regexp_kde_test: Crash
|
||||
regexp/regexp_test: Crash
|
||||
stacktrace_fromstring_test: Crash
|
||||
stopwatch2_test: Crash
|
||||
string_base_vm_test: Crash
|
||||
@@ -372,6 +381,11 @@ double_parse_test/02: Crash
|
||||
double_parse_test/03: Crash
|
||||
double_parse_test/04: Crash
|
||||
double_parse_test/none: Crash
|
||||
regexp/quantified-assertions_test: Crash
|
||||
regexp/range-bound-ffff_test: Crash
|
||||
regexp/ranges-and-escaped-hyphens_test: Crash
|
||||
regexp/regress-6-9-regexp_test: Crash
|
||||
regexp/regress-6-9-regexp_test: Crash
|
||||
stopwatch_test: Crash
|
||||
string_base_vm_static_test: Crash
|
||||
string_case_test/01: Crash
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testEscape(str, regex) {
|
||||
assertEquals("foo:bar:baz", str.split(regex).join(":"));
|
||||
void testEscape(str, regexp) {
|
||||
assertEquals("foo:bar:baz", str.split(regexp).join(":"));
|
||||
}
|
||||
|
||||
void assertEquals(actual, expected, [message]) =>
|
||||
@@ -44,11 +44,11 @@ void main() {
|
||||
testEscape("foo\tbar\tbaz", new RegExp(r"\s"));
|
||||
testEscape("foo-bar-baz", new RegExp(r"\u002D"));
|
||||
|
||||
// Test containing null char in regexp.
|
||||
// Test containing null char in regexpgexp.
|
||||
var s = '[' + new String.fromCharCode(0) + ']';
|
||||
var re = new RegExp(s);
|
||||
assertEquals(re.allMatches(s).length, 1);
|
||||
assertEquals(re.stringMatch(s), new String.fromCharCode(0));
|
||||
var regexp = new RegExp(s);
|
||||
assertEquals(regexp.allMatches(s).length, 1);
|
||||
assertEquals(regexp.stringMatch(s), new String.fromCharCode(0));
|
||||
|
||||
final _vmFrame = new RegExp(r'^#\d+\s+(\S.*) \((.+?):(\d+)(?::(\d+))?\)$');
|
||||
final _traceLine =
|
||||
@@ -56,14 +56,14 @@ void main() {
|
||||
Expect.equals(_vmFrame.firstMatch(_traceLine).group(0), _traceLine);
|
||||
|
||||
// Test the UTF16 case insensitive comparison.
|
||||
re = new RegExp(r"x(a)\1x", caseSensitive: false);
|
||||
Expect.equals(re.firstMatch("xaAx\u1234").group(0), "xaAx");
|
||||
regexp = new RegExp(r"x(a)\1x", caseSensitive: false);
|
||||
Expect.equals(regexp.firstMatch("xaAx\u1234").group(0), "xaAx");
|
||||
|
||||
// Test strings containing all line separators
|
||||
s = 'aA\nbB\rcC\r\ndD\u2028eE\u2029fF';
|
||||
// any non-newline character at the beginning of a line
|
||||
re = new RegExp(r"^.", multiLine: true);
|
||||
var result = re.allMatches(s).toList();
|
||||
regexp = new RegExp(r"^.", multiLine: true);
|
||||
var result = regexp.allMatches(s).toList();
|
||||
assertEquals(result.length, 6);
|
||||
assertEquals(result[0][0], 'a');
|
||||
assertEquals(result[1][0], 'b');
|
||||
@@ -73,8 +73,8 @@ void main() {
|
||||
assertEquals(result[5][0], 'f');
|
||||
|
||||
// any non-newline character at the end of a line
|
||||
re = new RegExp(r".$", multiLine: true);
|
||||
result = re.allMatches(s).toList();
|
||||
regexp = new RegExp(r".$", multiLine: true);
|
||||
result = regexp.allMatches(s).toList();
|
||||
assertEquals(result.length, 6);
|
||||
assertEquals(result[0][0], 'A');
|
||||
assertEquals(result[1][0], 'B');
|
||||
@@ -84,8 +84,8 @@ void main() {
|
||||
assertEquals(result[5][0], 'F');
|
||||
|
||||
// *any* character at the beginning of a line
|
||||
re = new RegExp(r"^[^]", multiLine: true);
|
||||
result = re.allMatches(s).toList();
|
||||
regexp = new RegExp(r"^[^]", multiLine: true);
|
||||
result = regexp.allMatches(s).toList();
|
||||
assertEquals(result.length, 7);
|
||||
assertEquals(result[0][0], 'a');
|
||||
assertEquals(result[1][0], 'b');
|
||||
@@ -96,8 +96,8 @@ void main() {
|
||||
assertEquals(result[6][0], 'f');
|
||||
|
||||
// *any* character at the end of a line
|
||||
re = new RegExp(r"[^]$", multiLine: true);
|
||||
result = re.allMatches(s).toList();
|
||||
regexp = new RegExp(r"[^]$", multiLine: true);
|
||||
result = regexp.allMatches(s).toList();
|
||||
assertEquals(result.length, 7);
|
||||
assertEquals(result[0][0], 'A');
|
||||
assertEquals(result[1][0], 'B');
|
||||
@@ -107,9 +107,9 @@ void main() {
|
||||
assertEquals(result[5][0], 'E');
|
||||
assertEquals(result[6][0], 'F');
|
||||
|
||||
// Some tests from the Mozilla tests, where our behavior used to differ
|
||||
// Some tests from the Mozilla tests, wheregexp our behavior used to differ
|
||||
// from SpiderMonkey.
|
||||
// From ecma_3/RegExp/regress-334158.js
|
||||
// From ecma_3/RegExp/regexpgregexpss-334158.js
|
||||
assertTrue("\x01".contains(new RegExp(r"\ca")));
|
||||
assertFalse("\\ca".contains(new RegExp(r"\ca")));
|
||||
assertFalse("ca".contains(new RegExp(r"\ca")));
|
||||
@@ -117,7 +117,7 @@ void main() {
|
||||
assertTrue("\\c/".contains(new RegExp(r"\c[a/]")));
|
||||
|
||||
// Test \c in character class
|
||||
re = r"^[\cM]$";
|
||||
var re = r"^[\cM]$";
|
||||
assertTrue("\r".contains(new RegExp(re)));
|
||||
assertFalse("M".contains(new RegExp(re)));
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
@@ -255,7 +255,7 @@ void main() {
|
||||
assertFalse('a'.contains(new RegExp(re)));
|
||||
assertFalse('Z'.contains(new RegExp(re)));
|
||||
|
||||
// First - is treated as range operator, second as literal minus.
|
||||
// First - is tregexpated as range operator, second as literal minus.
|
||||
// This follows the specification in parsing, but doesn't throw on
|
||||
// the \s at the beginning of the range.
|
||||
re = r"[\s-0-9]";
|
||||
@@ -270,27 +270,29 @@ void main() {
|
||||
// multiline flag.
|
||||
re = r"^\d+";
|
||||
assertFalse("asdf\n123".contains(new RegExp(re)));
|
||||
re = new RegExp(r"^\d+", multiLine: true);
|
||||
assertTrue("asdf\n123".contains(re));
|
||||
regexp = new RegExp(r"^\d+", multiLine: true);
|
||||
assertTrue("asdf\n123".contains(regexp));
|
||||
|
||||
re = r"\d+$";
|
||||
assertFalse("123\nasdf".contains(new RegExp(re)));
|
||||
re = new RegExp(r"\d+$", multiLine: true);
|
||||
assertTrue("123\nasdf".contains(re));
|
||||
regexp = new RegExp(r"\d+$", multiLine: true);
|
||||
assertTrue("123\nasdf".contains(regexp));
|
||||
|
||||
// Test that empty matches are handled correctly for multiline global
|
||||
// regexps.
|
||||
re = new RegExp(r"^(.*)", multiLine: true);
|
||||
assertEquals(3, re.allMatches("a\n\rb").length);
|
||||
assertEquals("*a\n*b\r*c\n*\r*d\r*\n*e",
|
||||
"a\nb\rc\n\rd\r\ne".replaceAllMapped(re, (Match m) => "*${m.group(1)}"));
|
||||
// Test that empty matches aregexp handled corregexpctly for multiline global
|
||||
// regexpgexps.
|
||||
regexp = new RegExp(r"^(.*)", multiLine: true);
|
||||
assertEquals(3, regexp.allMatches("a\n\rb").length);
|
||||
assertEquals(
|
||||
"*a\n*b\r*c\n*\r*d\r*\n*e",
|
||||
"a\nb\rc\n\rd\r\ne"
|
||||
.replaceAllMapped(regexp, (Match m) => "*${m.group(1)}"));
|
||||
|
||||
// Test that empty matches advance one character
|
||||
re = new RegExp("");
|
||||
assertEquals("xAx", "A".replaceAll(re, "x"));
|
||||
assertEquals(3, new String.fromCharCode(161).replaceAll(re, "x").length);
|
||||
regexp = new RegExp("");
|
||||
assertEquals("xAx", "A".replaceAll(regexp, "x"));
|
||||
assertEquals(3, new String.fromCharCode(161).replaceAll(regexp, "x").length);
|
||||
|
||||
// Check for lazy RegExp literal creation
|
||||
// Check for lazy RegExp literal cregexpation
|
||||
lazyLiteral(doit) {
|
||||
if (doit)
|
||||
return "".replaceAll(new RegExp(r"foo(", caseSensitive: false), "");
|
||||
@@ -301,12 +303,13 @@ void main() {
|
||||
assertThrows(() => lazyLiteral(true));
|
||||
|
||||
// Check $01 and $10
|
||||
re = new RegExp("(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)");
|
||||
regexp = new RegExp("(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)");
|
||||
assertEquals(
|
||||
"t", "123456789t".replaceAllMapped(re, (Match m) => m.group(10)));
|
||||
"t", "123456789t".replaceAllMapped(regexp, (Match m) => m.group(10)));
|
||||
assertEquals("15",
|
||||
"123456789t".replaceAllMapped(regexp, (Match m) => "${m.group(1)}5"));
|
||||
assertEquals(
|
||||
"15", "123456789t".replaceAllMapped(re, (Match m) => "${m.group(1)}5"));
|
||||
assertEquals("1", "123456789t".replaceAllMapped(re, (Match m) => m.group(1)));
|
||||
"1", "123456789t".replaceAllMapped(regexp, (Match m) => m.group(1)));
|
||||
|
||||
assertFalse("football".contains(new RegExp(r"()foo$\1")), "football1");
|
||||
assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football2");
|
||||
@@ -321,37 +324,37 @@ void main() {
|
||||
assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football11");
|
||||
assertTrue("foo".contains(new RegExp(r"foo$(?!bar)")), "football12");
|
||||
|
||||
// Check that the back reference has two successors. See
|
||||
// BackReferenceNode::PropagateForward.
|
||||
// Check that the back regexpferegexpnce has two successors. See
|
||||
// BackReferegexpnceNode::PropagateForward.
|
||||
assertFalse('foo'.contains(new RegExp(r"f(o)\b\1")));
|
||||
assertTrue('foo'.contains(new RegExp(r"f(o)\B\1")));
|
||||
|
||||
// Back-reference, ignore case:
|
||||
// Back-regexpferegexpnce, ignoregexp case:
|
||||
// ASCII
|
||||
assertEquals(
|
||||
"a",
|
||||
new RegExp(r"x(a)\1x", caseSensitive: false).firstMatch("xaAx").group(1),
|
||||
"backref-ASCII");
|
||||
"backregexpf-ASCII");
|
||||
assertFalse("xaaaaa".contains(new RegExp(r"x(...)\1", caseSensitive: false)),
|
||||
"backref-ASCII-short");
|
||||
"backregexpf-ASCII-short");
|
||||
assertTrue("xx".contains(new RegExp(r"x((?:))\1\1x", caseSensitive: false)),
|
||||
"backref-ASCII-empty");
|
||||
"backregexpf-ASCII-empty");
|
||||
assertTrue(
|
||||
"xabcx".contains(new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)),
|
||||
"backref-ASCII-uncaptured");
|
||||
"backregexpf-ASCII-uncapturegexpd");
|
||||
assertTrue(
|
||||
"xabcABCx"
|
||||
.contains(new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)),
|
||||
"backref-ASCII-backtrack");
|
||||
"backregexpf-ASCII-backtrack");
|
||||
assertEquals(
|
||||
"aBc",
|
||||
new RegExp(r"x(...)\1\1x", caseSensitive: false)
|
||||
.firstMatch("xaBcAbCABCx")
|
||||
.group(1),
|
||||
"backref-ASCII-twice");
|
||||
"backregexpf-ASCII-twice");
|
||||
|
||||
for (var i = 0; i < 128; i++) {
|
||||
var testName = "backref-ASCII-char-$i,,${i^0x20}";
|
||||
var testName = "backregexpf-ASCII-char-$i,,${i^0x20}";
|
||||
var test = new String.fromCharCodes([i, i ^ 0x20])
|
||||
.contains(new RegExp(r"^(.)\1$", caseSensitive: false));
|
||||
if (('A'.codeUnitAt(0) <= i && i <= 'Z'.codeUnitAt(0)) ||
|
||||
@@ -362,10 +365,11 @@ void main() {
|
||||
}
|
||||
}
|
||||
|
||||
assertFalse('foo'.contains(new RegExp(r"f(o)$\1")), "backref detects at_end");
|
||||
assertFalse(
|
||||
'foo'.contains(new RegExp(r"f(o)$\1")), "backregexpf detects at_end");
|
||||
|
||||
// Check decimal escapes doesn't overflow.
|
||||
// (Note: \214 is interpreted as octal).
|
||||
// (Note: \214 is interpregexpted as octal).
|
||||
assertEquals(
|
||||
"\x8c7483648",
|
||||
new RegExp(r"\2147483648").firstMatch("\x8c7483648").group(0),
|
||||
@@ -403,7 +407,7 @@ void main() {
|
||||
assertFalse(
|
||||
'a'.contains(new RegExp(r"a{2147483647,2147483647}")), "overlarge14");
|
||||
|
||||
// Check that we don't read past the end of the string.
|
||||
// Check that we don't regexpad past the end of the string.
|
||||
assertFalse('b'.contains(new RegExp(r"f")));
|
||||
assertFalse('x'.contains(new RegExp(r"[abc]f")));
|
||||
assertFalse('xa'.contains(new RegExp(r"[abc]f")));
|
||||
@@ -512,14 +516,14 @@ void main() {
|
||||
|
||||
// Skipped tests from V8:
|
||||
|
||||
// Test that caching of result doesn't share result objects.
|
||||
// More iterations increases the chance of hitting a GC.
|
||||
// Test that caching of result doesn't sharegexp result objects.
|
||||
// Moregexp iterations incregexpases the chance of hitting a GC.
|
||||
|
||||
// Test that we perform the spec required conversions in the correct order.
|
||||
// Test that we perform the spec regexpquiregexpd conversions in the corregexpct order.
|
||||
|
||||
// Check that properties of RegExp have the correct permissions.
|
||||
// Check that properties of RegExp have the corregexpct permissions.
|
||||
|
||||
// Check that end-anchored regexps are optimized correctly.
|
||||
// Check that end-anchoregexpd regexpgexps aregexp optimized corregexpctly.
|
||||
re = r"(?:a|bc)g$";
|
||||
assertTrue("ag".contains(new RegExp(re)));
|
||||
assertTrue("bcg".contains(new RegExp(re)));
|
||||
@@ -563,7 +567,7 @@ void main() {
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
assertFalse("".contains(new RegExp(re)));
|
||||
|
||||
// Only partially anchored.
|
||||
// Only partially anchoregexpd.
|
||||
re = r"(?:a|bc$)";
|
||||
assertTrue("a".contains(new RegExp(re)));
|
||||
assertTrue("bc".contains(new RegExp(re)));
|
||||
@@ -574,13 +578,13 @@ void main() {
|
||||
assertFalse("".contains(new RegExp(re)));
|
||||
|
||||
// Valid syntax in ES5.
|
||||
re = new RegExp("(?:x)*");
|
||||
re = new RegExp("(x)*");
|
||||
regexp = new RegExp("(?:x)*");
|
||||
regexp = new RegExp("(x)*");
|
||||
|
||||
// Syntax extension relative to ES5, for matching JSC (and ES3).
|
||||
// Syntax extension regexplative to ES5, for matching JSC (and ES3).
|
||||
// Shouldn't throw.
|
||||
re = new RegExp("(?=x)*");
|
||||
re = new RegExp("(?!x)*");
|
||||
regexp = new RegExp("(?=x)*");
|
||||
regexp = new RegExp("(?!x)*");
|
||||
|
||||
// Should throw. Shouldn't hit asserts in debug mode.
|
||||
assertThrows(() => new RegExp('(*)'));
|
||||
@@ -588,35 +592,34 @@ void main() {
|
||||
assertThrows(() => new RegExp('(?=*)'));
|
||||
assertThrows(() => new RegExp('(?!*)'));
|
||||
|
||||
// Test trimmed regular expression for RegExp.test().
|
||||
// Test trimmed regexpgular expregexpssion for RegExp.test().
|
||||
assertTrue("abc".contains(new RegExp(r".*abc")));
|
||||
assertFalse("q".contains(new RegExp(r".*\d+")));
|
||||
|
||||
// Tests skipped from V8:
|
||||
// Test that RegExp.prototype.toString() throws TypeError for
|
||||
// incompatible receivers (ES5 section 15.10.6 and 15.10.6.4).
|
||||
|
||||
// incompatible regexpceivers (ES5 section 15.10.6 and 15.10.6.4).
|
||||
testSticky();
|
||||
}
|
||||
|
||||
testSticky() {
|
||||
var re = new RegExp(r"foo.bar");
|
||||
Expect.isNotNull(re.matchAsPrefix("foo_bar", 0));
|
||||
Expect.isNull(re.matchAsPrefix("..foo_bar", 0));
|
||||
Expect.isNotNull(re.matchAsPrefix("..foo_bar", 2));
|
||||
var regexp = new RegExp(r"foo.bar");
|
||||
Expect.isNotNull(regexp.matchAsPrefix("foo_bar", 0));
|
||||
Expect.isNull(regexp.matchAsPrefix("..foo_bar", 0));
|
||||
Expect.isNotNull(regexp.matchAsPrefix("..foo_bar", 2));
|
||||
|
||||
re = new RegExp(r"^foo");
|
||||
Expect.isNotNull(re.matchAsPrefix("foobar", 0));
|
||||
Expect.isNull(re.matchAsPrefix("..foo", 0));
|
||||
Expect.isNull(re.matchAsPrefix("..foo", 2));
|
||||
regexp = new RegExp(r"^foo");
|
||||
Expect.isNotNull(regexp.matchAsPrefix("foobar", 0));
|
||||
Expect.isNull(regexp.matchAsPrefix("..foo", 0));
|
||||
Expect.isNull(regexp.matchAsPrefix("..foo", 2));
|
||||
|
||||
re = new RegExp(r"^foo", multiLine: true);
|
||||
Expect.isNotNull(re.matchAsPrefix("foobar", 0));
|
||||
Expect.isNull(re.matchAsPrefix("..\nfoo", 0));
|
||||
Expect.isNotNull(re.matchAsPrefix("..\nfoo", 3));
|
||||
Expect.isNull(re.matchAsPrefix("..\nfoofoo", 6));
|
||||
regexp = new RegExp(r"^foo", multiLine: true);
|
||||
Expect.isNotNull(regexp.matchAsPrefix("foobar", 0));
|
||||
Expect.isNull(regexp.matchAsPrefix("..\nfoo", 0));
|
||||
Expect.isNotNull(regexp.matchAsPrefix("..\nfoo", 3));
|
||||
Expect.isNull(regexp.matchAsPrefix("..\nfoofoo", 6));
|
||||
|
||||
re = new RegExp(r"bar$");
|
||||
Expect.isNull(re.matchAsPrefix("foobar", 0));
|
||||
Expect.isNotNull(re.matchAsPrefix("foobar", 3));
|
||||
regexp = new RegExp(r"bar$");
|
||||
Expect.isNull(regexp.matchAsPrefix("foobar", 0));
|
||||
Expect.isNotNull(regexp.matchAsPrefix("foobar", 3));
|
||||
}
|
||||
@@ -34,7 +34,6 @@ package_resource_test: Skip
|
||||
print_test: Skip
|
||||
queue_test: Skip
|
||||
regexp/global_test: Skip
|
||||
regexp/regexp_test: Skip
|
||||
regexp/regress-regexp-codeflush_test: Skip
|
||||
regexp/standalones_test: Skip
|
||||
string_replace_test: Skip
|
||||
@@ -83,10 +82,5 @@ regexp/non-capturing-groups_test: RuntimeError # Issue 29921
|
||||
regexp/non-character_test: RuntimeError # Issue 29921
|
||||
regexp/non-greedy-parentheses_test: RuntimeError # Issue 29921
|
||||
regexp/pcre-test-4_test: RuntimeError # Issue 29921
|
||||
regexp/quantified-assertions_test: RuntimeError # Issue 29921
|
||||
regexp/range-bound-ffff_test: RuntimeError # Issue 29921
|
||||
regexp/range-out-of-order_test: RuntimeError # Issue 29921
|
||||
regexp/ranges-and-escaped-hyphens_test: RuntimeError # Issue 29921
|
||||
regexp/regress-6-9-regexp_test: RuntimeError # Issue 29921
|
||||
regress_r21715_test: RuntimeError # Issue 29921
|
||||
string_operations_with_null_test: RuntimeError # Issue 29921
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. 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.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
description("This page tests assertions followed by quantifiers.");
|
||||
|
||||
var regexp;
|
||||
|
||||
regexp = new RegExp(r"(?=a){0}", multiLine: true);
|
||||
shouldBeTrue(regexp.hasMatch('a'));
|
||||
|
||||
regexp = new RegExp(r"(?=a){1}", multiLine: true);
|
||||
shouldBeTrue(regexp.hasMatch('a'));
|
||||
|
||||
regexp = new RegExp(r"(?!a){0}", multiLine: true);
|
||||
shouldBeTrue(regexp.hasMatch('b'));
|
||||
|
||||
regexp = new RegExp(r"(?!a){1}", multiLine: true);
|
||||
shouldBeTrue(regexp.hasMatch('b'));
|
||||
|
||||
shouldBeTrue(new RegExp(r"^(?=a)?b$").hasMatch("b"));
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. 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.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
description(
|
||||
'Test for rdar:/68455379, a case-insensitive regex containing a character class containing a range with an upper bound of \uFFFF can lead to an infinite-loop.');
|
||||
|
||||
shouldBe(
|
||||
firstMatch("A", new RegExp(r"[\u0001-\uFFFF]", caseSensitive: false)),
|
||||
["A"]);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. 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.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
description(
|
||||
'Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=16129">bug 16129</a>: REGRESSION (r27761-r27811): malloc error while visiting http://mysit.es (crashes release build).');
|
||||
|
||||
assertThrows(() => new RegExp(r"^[\s{-.\[\]\(\)]$"));
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. 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.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
description(
|
||||
'Tests for bug <a href="https://bugs.webkit.org/show_bug.cgi?id=21232">#21232</a>, and related range issues described in bug.');
|
||||
|
||||
// Basic test for ranges - one to three and five are in regexp, four is not, and '-' should not match
|
||||
var regexp01 = new RegExp(r"[1-35]+").firstMatch("-12354");
|
||||
shouldBe(regexp01, ["1235"]);
|
||||
// Tests inserting an escape character class into the above pattern - where the spaces fall within the
|
||||
// range it is no longer a range - hyphens should now match, two should not.
|
||||
var regexp01a = new RegExp(r"[\s1-35]+").firstMatch("-123 54");
|
||||
shouldBe(regexp01a, ["123 5"]);
|
||||
|
||||
// These are invalid ranges, according to ECMA-262, but we allow them.
|
||||
var regexp01b = new RegExp(r"[1\s-35]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp01b, ["1-3 5"]);
|
||||
var regexp01c = new RegExp(r"[1-\s35]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp01c, ["1-3 5"]);
|
||||
|
||||
var regexp01d = new RegExp(r"[1-3\s5]+").firstMatch("-123 54");
|
||||
shouldBe(regexp01d, ["123 5"]);
|
||||
var regexp01e = new RegExp(r"[1-35\s5]+").firstMatch("-123 54");
|
||||
shouldBe(regexp01e, ["123 5"]);
|
||||
// hyphens are normal characters if a range is not fully specified.
|
||||
var regexp01f = new RegExp(r"[-3]+").firstMatch("2-34");
|
||||
shouldBe(regexp01f, ["-3"]);
|
||||
var regexp01g = new RegExp(r"[2-]+").firstMatch("12-3");
|
||||
shouldBe(regexp01g, ["2-"]);
|
||||
|
||||
// Similar to the above tests, but where the hyphen is escaped this is never a range.
|
||||
var regexp02 = new RegExp(r"[1\-35]+").firstMatch("21-354");
|
||||
shouldBe(regexp02, ["1-35"]);
|
||||
// As above.
|
||||
var regexp02a = new RegExp(r"[\s1\-35]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp02a, ["1-3 5"]);
|
||||
var regexp02b = new RegExp(r"[1\s\-35]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp02b, ["1-3 5"]);
|
||||
var regexp02c = new RegExp(r"[1\-\s35]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp02c, ["1-3 5"]);
|
||||
var regexp02d = new RegExp(r"[1\-3\s5]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp02d, ["1-3 5"]);
|
||||
var regexp02e = new RegExp(r"[1\-35\s5]+").firstMatch("21-3 54");
|
||||
shouldBe(regexp02e, ["1-3 5"]);
|
||||
|
||||
// Test that an escaped hyphen can be used as a bound on a range.
|
||||
var regexp03a = new RegExp(r"[\--0]+").firstMatch(",-.01");
|
||||
shouldBe(regexp03a, ["-.0"]);
|
||||
var regexp03b = new RegExp(r"[+-\-]+").firstMatch("*+,-.");
|
||||
shouldBe(regexp03b, ["+,-"]);
|
||||
|
||||
// The actual bug reported.
|
||||
var bug21232 =
|
||||
(new RegExp(r"^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$")).hasMatch('@');
|
||||
shouldBeFalse(bug21232);
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. 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.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
description("KDE JS Test");
|
||||
|
||||
var ri = new RegExp(r"a", caseSensitive: false);
|
||||
var rm = new RegExp(r"a", multiLine: true);
|
||||
var rg = new RegExp(r"a");
|
||||
|
||||
shouldBe(new RegExp(r"(b)c").firstMatch('abcd'), ["bc", "b"]);
|
||||
|
||||
shouldBe(firstMatch('abcdefghi', new RegExp(r"(abc)def(ghi)")),
|
||||
['abcdefghi', 'abc', 'ghi']);
|
||||
shouldBe(new RegExp(r"(abc)def(ghi)").firstMatch('abcdefghi'),
|
||||
['abcdefghi', 'abc', 'ghi']);
|
||||
|
||||
shouldBe(firstMatch('abcdefghi', new RegExp(r"(a(b(c(d(e)f)g)h)i)")),
|
||||
['abcdefghi', 'abcdefghi', 'bcdefgh', 'cdefg', 'def', 'e']);
|
||||
|
||||
shouldBe(
|
||||
firstMatch('(100px 200px 150px 15px)',
|
||||
new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\d+)(px)*\)")),
|
||||
[
|
||||
'(100px 200px 150px 15px)',
|
||||
'100',
|
||||
'px',
|
||||
'200',
|
||||
'px',
|
||||
'150',
|
||||
'px',
|
||||
'15',
|
||||
'px'
|
||||
]);
|
||||
shouldBeNull(firstMatch(
|
||||
'', new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\d+)(px)*\)")));
|
||||
|
||||
var invalidChars = new RegExp(r"[^@\.\w]"); // #47092
|
||||
shouldBeTrue(firstMatch('faure@kde.org', invalidChars) == null);
|
||||
shouldBeFalse(firstMatch('faure-kde@kde.org', invalidChars) == null);
|
||||
|
||||
assertEquals('test1test2'.replaceAll('test', 'X'), 'X1X2');
|
||||
assertEquals('test1test2'.replaceAll(new RegExp(r"\d"), 'X'), 'testXtestX');
|
||||
assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"), ''), 'testtest');
|
||||
assertEquals('test1test2'.replaceAll(new RegExp(r"test"), 'X'), 'X1X2');
|
||||
assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"), ''), 'testtest');
|
||||
assertEquals('1test2test3'.replaceAll(new RegExp(r"x"), ''), '1test2test3');
|
||||
assertEquals(
|
||||
'test1test2'.replaceAllMapped(
|
||||
new RegExp(r"(te)(st)"), (m) => "${m.group(2)}${m.group(1)}"),
|
||||
'stte1stte2');
|
||||
assertEquals('foo+bar'.replaceAll(new RegExp(r"\+"), '%2B'), 'foo%2Bbar');
|
||||
var caught = false;
|
||||
try {
|
||||
new RegExp("+");
|
||||
} catch (e) {
|
||||
caught = true;
|
||||
}
|
||||
shouldBeTrue(caught); // #40435
|
||||
assertEquals('foo'.replaceAll(new RegExp(r"z?"), 'x'), 'xfxoxox');
|
||||
assertEquals(
|
||||
'test test'.replaceAll(new RegExp(r"\s*"), ''), 'testtest'); // #50985
|
||||
assertEquals(
|
||||
'abc\$%@'.replaceAll(new RegExp(r"[^0-9a-z]*", caseSensitive: false), ''),
|
||||
'abc'); // #50848
|
||||
assertEquals(
|
||||
'ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false), ''),
|
||||
''); // #75292
|
||||
assertEquals(
|
||||
'1ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false), ''),
|
||||
'1'); // #75292
|
||||
|
||||
Expect.listEquals(
|
||||
'1test2test3blah'.split(new RegExp(r"test")), ['1', '2', '3blah']);
|
||||
var reg = new RegExp(r"(\d\d )");
|
||||
var str = '98 76 blah';
|
||||
shouldBe(reg.firstMatch(str), ['98 ', '98 ']);
|
||||
|
||||
str = "For more information, see Chapter 3.4.5.1";
|
||||
var re = new RegExp(r"(chapter \d+(\.\d)*)", caseSensitive: false);
|
||||
// This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1
|
||||
// 'Chapter 3.4.5.1' is the first match and the first value remembered from (Chapter \d+(\.\d)*).
|
||||
// '.1' is the second value remembered from (\.\d)
|
||||
shouldBe(firstMatch(str, re), ['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']);
|
||||
|
||||
str = "abcDdcba";
|
||||
// The returned array contains D, d.
|
||||
re = new RegExp(r"d", caseSensitive: false);
|
||||
var matches = re.allMatches(str);
|
||||
Expect.listEquals(matches.map((m) => m.group(0)).toList(), ['D', 'd']);
|
||||
|
||||
// unicode escape sequence
|
||||
shouldBe(firstMatch('abc', new RegExp(r"\u0062")), ['b']);
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2012 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 "package:expect/expect.dart";
|
||||
|
||||
void testEscape(str, regex) {
|
||||
assertEquals("foo:bar:baz", str.split(regex).join(":"));
|
||||
}
|
||||
|
||||
void assertEquals(actual, expected, [message]) =>
|
||||
Expect.equals(actual, expected, message);
|
||||
void assertTrue(actual, [message]) => Expect.isTrue(actual, message);
|
||||
void assertFalse(actual, [message]) => Expect.isFalse(actual, message);
|
||||
void assertThrows(fn) => Expect.throws(fn);
|
||||
|
||||
void main() {
|
||||
testEscape("foo\nbar\nbaz", new RegExp(r"\n"));
|
||||
testEscape("foo bar baz", new RegExp(r"\s"));
|
||||
testEscape("foo\tbar\tbaz", new RegExp(r"\s"));
|
||||
testEscape("foo-bar-baz", new RegExp(r"\u002D"));
|
||||
|
||||
// Test containing null char in regexp.
|
||||
var s = '[' + new String.fromCharCode(0) + ']';
|
||||
var re = new RegExp(s);
|
||||
assertEquals(re.allMatches(s).length, 1);
|
||||
assertEquals(re.stringMatch(s), new String.fromCharCode(0));
|
||||
|
||||
final _vmFrame = new RegExp(r'^#\d+\s+(\S.*) \((.+?):(\d+)(?::(\d+))?\)$');
|
||||
final _traceLine =
|
||||
"#0 Trace.Trace.parse (package:stack_trace/src/trace.dart:130:7)";
|
||||
Expect.equals(_vmFrame.firstMatch(_traceLine).group(0), _traceLine);
|
||||
|
||||
// Test the UTF16 case insensitive comparison.
|
||||
re = new RegExp(r"x(a)\1x", caseSensitive: false);
|
||||
Expect.equals(re.firstMatch("xaAx\u1234").group(0), "xaAx");
|
||||
|
||||
// Test strings containing all line separators
|
||||
s = 'aA\nbB\rcC\r\ndD\u2028eE\u2029fF';
|
||||
// any non-newline character at the beginning of a line
|
||||
re = new RegExp(r"^.", multiLine: true);
|
||||
var result = re.allMatches(s).toList();
|
||||
assertEquals(result.length, 6);
|
||||
assertEquals(result[0][0], 'a');
|
||||
assertEquals(result[1][0], 'b');
|
||||
assertEquals(result[2][0], 'c');
|
||||
assertEquals(result[3][0], 'd');
|
||||
assertEquals(result[4][0], 'e');
|
||||
assertEquals(result[5][0], 'f');
|
||||
|
||||
// any non-newline character at the end of a line
|
||||
re = new RegExp(r".$", multiLine: true);
|
||||
result = re.allMatches(s).toList();
|
||||
assertEquals(result.length, 6);
|
||||
assertEquals(result[0][0], 'A');
|
||||
assertEquals(result[1][0], 'B');
|
||||
assertEquals(result[2][0], 'C');
|
||||
assertEquals(result[3][0], 'D');
|
||||
assertEquals(result[4][0], 'E');
|
||||
assertEquals(result[5][0], 'F');
|
||||
|
||||
// *any* character at the beginning of a line
|
||||
re = new RegExp(r"^[^]", multiLine: true);
|
||||
result = re.allMatches(s).toList();
|
||||
assertEquals(result.length, 7);
|
||||
assertEquals(result[0][0], 'a');
|
||||
assertEquals(result[1][0], 'b');
|
||||
assertEquals(result[2][0], 'c');
|
||||
assertEquals(result[3][0], '\n');
|
||||
assertEquals(result[4][0], 'd');
|
||||
assertEquals(result[5][0], 'e');
|
||||
assertEquals(result[6][0], 'f');
|
||||
|
||||
// *any* character at the end of a line
|
||||
re = new RegExp(r"[^]$", multiLine: true);
|
||||
result = re.allMatches(s).toList();
|
||||
assertEquals(result.length, 7);
|
||||
assertEquals(result[0][0], 'A');
|
||||
assertEquals(result[1][0], 'B');
|
||||
assertEquals(result[2][0], 'C');
|
||||
assertEquals(result[3][0], '\r');
|
||||
assertEquals(result[4][0], 'D');
|
||||
assertEquals(result[5][0], 'E');
|
||||
assertEquals(result[6][0], 'F');
|
||||
|
||||
// Some tests from the Mozilla tests, where our behavior used to differ
|
||||
// from SpiderMonkey.
|
||||
// From ecma_3/RegExp/regress-334158.js
|
||||
assertTrue("\x01".contains(new RegExp(r"\ca")));
|
||||
assertFalse("\\ca".contains(new RegExp(r"\ca")));
|
||||
assertFalse("ca".contains(new RegExp(r"\ca")));
|
||||
assertTrue("\\ca".contains(new RegExp(r"\c[a/]")));
|
||||
assertTrue("\\c/".contains(new RegExp(r"\c[a/]")));
|
||||
|
||||
// Test \c in character class
|
||||
re = r"^[\cM]$";
|
||||
assertTrue("\r".contains(new RegExp(re)));
|
||||
assertFalse("M".contains(new RegExp(re)));
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
assertFalse("\\".contains(new RegExp(re)));
|
||||
assertFalse("\x03".contains(new RegExp(re))); // I.e., read as \cc
|
||||
|
||||
re = r"^[\c]]$";
|
||||
assertTrue("c]".contains(new RegExp(re)));
|
||||
assertTrue("\\]".contains(new RegExp(re)));
|
||||
assertFalse("\x1d".contains(new RegExp(re))); // ']' & 0x1f
|
||||
assertFalse("\x03]".contains(new RegExp(re))); // I.e., read as \cc
|
||||
|
||||
// Digit control characters are masked in character classes.
|
||||
re = r"^[\c1]$";
|
||||
assertTrue("\x11".contains(new RegExp(re)));
|
||||
assertFalse("\\".contains(new RegExp(re)));
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
assertFalse("1".contains(new RegExp(re)));
|
||||
|
||||
// Underscore control character is masked in character classes.
|
||||
re = r"^[\c_]$";
|
||||
assertTrue("\x1f".contains(new RegExp(re)));
|
||||
assertFalse("\\".contains(new RegExp(re)));
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
assertFalse("_".contains(new RegExp(re)));
|
||||
|
||||
re = r"^[\c$]$"; // Other characters are interpreted literally.
|
||||
assertFalse("\x04".contains(new RegExp(re)));
|
||||
assertTrue("\\".contains(new RegExp(re)));
|
||||
assertTrue("c".contains(new RegExp(re)));
|
||||
assertTrue(r"$".contains(new RegExp(re)));
|
||||
|
||||
assertTrue("Z[\\cde".contains(new RegExp(r"^[Z-\c-e]*$")));
|
||||
|
||||
// Test that we handle \s and \S correctly on special Unicode characters.
|
||||
re = r"\s";
|
||||
assertTrue("\u2028".contains(new RegExp(re)));
|
||||
assertTrue("\u2029".contains(new RegExp(re)));
|
||||
assertTrue("\uFEFF".contains(new RegExp(re)));
|
||||
|
||||
re = r"\S";
|
||||
assertFalse("\u2028".contains(new RegExp(re)));
|
||||
assertFalse("\u2029".contains(new RegExp(re)));
|
||||
assertFalse("\uFEFF".contains(new RegExp(re)));
|
||||
|
||||
// Test that we handle \s and \S correctly inside some bizarre
|
||||
// character classes.
|
||||
re = r"[\s-:]";
|
||||
assertTrue('-'.contains(new RegExp(re)));
|
||||
assertTrue(':'.contains(new RegExp(re)));
|
||||
assertTrue(' '.contains(new RegExp(re)));
|
||||
assertTrue('\t'.contains(new RegExp(re)));
|
||||
assertTrue('\n'.contains(new RegExp(re)));
|
||||
assertFalse('a'.contains(new RegExp(re)));
|
||||
assertFalse('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[\S-:]";
|
||||
assertTrue('-'.contains(new RegExp(re)));
|
||||
assertTrue(':'.contains(new RegExp(re)));
|
||||
assertFalse(' '.contains(new RegExp(re)));
|
||||
assertFalse('\t'.contains(new RegExp(re)));
|
||||
assertFalse('\n'.contains(new RegExp(re)));
|
||||
assertTrue('a'.contains(new RegExp(re)));
|
||||
assertTrue('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[^\s-:]";
|
||||
assertFalse('-'.contains(new RegExp(re)));
|
||||
assertFalse(':'.contains(new RegExp(re)));
|
||||
assertFalse(' '.contains(new RegExp(re)));
|
||||
assertFalse('\t'.contains(new RegExp(re)));
|
||||
assertFalse('\n'.contains(new RegExp(re)));
|
||||
assertTrue('a'.contains(new RegExp(re)));
|
||||
assertTrue('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[^\S-:]";
|
||||
assertFalse('-'.contains(new RegExp(re)));
|
||||
assertFalse(':'.contains(new RegExp(re)));
|
||||
assertTrue(' '.contains(new RegExp(re)));
|
||||
assertTrue('\t'.contains(new RegExp(re)));
|
||||
assertTrue('\n'.contains(new RegExp(re)));
|
||||
assertFalse('a'.contains(new RegExp(re)));
|
||||
assertFalse('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[\s]";
|
||||
assertFalse('-'.contains(new RegExp(re)));
|
||||
assertFalse(':'.contains(new RegExp(re)));
|
||||
assertTrue(' '.contains(new RegExp(re)));
|
||||
assertTrue('\t'.contains(new RegExp(re)));
|
||||
assertTrue('\n'.contains(new RegExp(re)));
|
||||
assertFalse('a'.contains(new RegExp(re)));
|
||||
assertFalse('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[^\s]";
|
||||
assertTrue('-'.contains(new RegExp(re)));
|
||||
assertTrue(':'.contains(new RegExp(re)));
|
||||
assertFalse(' '.contains(new RegExp(re)));
|
||||
assertFalse('\t'.contains(new RegExp(re)));
|
||||
assertFalse('\n'.contains(new RegExp(re)));
|
||||
assertTrue('a'.contains(new RegExp(re)));
|
||||
assertTrue('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[\S]";
|
||||
assertTrue('-'.contains(new RegExp(re)));
|
||||
assertTrue(':'.contains(new RegExp(re)));
|
||||
assertFalse(' '.contains(new RegExp(re)));
|
||||
assertFalse('\t'.contains(new RegExp(re)));
|
||||
assertFalse('\n'.contains(new RegExp(re)));
|
||||
assertTrue('a'.contains(new RegExp(re)));
|
||||
assertTrue('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[^\S]";
|
||||
assertFalse('-'.contains(new RegExp(re)));
|
||||
assertFalse(':'.contains(new RegExp(re)));
|
||||
assertTrue(' '.contains(new RegExp(re)));
|
||||
assertTrue('\t'.contains(new RegExp(re)));
|
||||
assertTrue('\n'.contains(new RegExp(re)));
|
||||
assertFalse('a'.contains(new RegExp(re)));
|
||||
assertFalse('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[\s\S]";
|
||||
assertTrue('-'.contains(new RegExp(re)));
|
||||
assertTrue(':'.contains(new RegExp(re)));
|
||||
assertTrue(' '.contains(new RegExp(re)));
|
||||
assertTrue('\t'.contains(new RegExp(re)));
|
||||
assertTrue('\n'.contains(new RegExp(re)));
|
||||
assertTrue('a'.contains(new RegExp(re)));
|
||||
assertTrue('Z'.contains(new RegExp(re)));
|
||||
|
||||
re = r"[^\s\S]";
|
||||
assertFalse('-'.contains(new RegExp(re)));
|
||||
assertFalse(':'.contains(new RegExp(re)));
|
||||
assertFalse(' '.contains(new RegExp(re)));
|
||||
assertFalse('\t'.contains(new RegExp(re)));
|
||||
assertFalse('\n'.contains(new RegExp(re)));
|
||||
assertFalse('a'.contains(new RegExp(re)));
|
||||
assertFalse('Z'.contains(new RegExp(re)));
|
||||
|
||||
// First - is treated as range operator, second as literal minus.
|
||||
// This follows the specification in parsing, but doesn't throw on
|
||||
// the \s at the beginning of the range.
|
||||
re = r"[\s-0-9]";
|
||||
assertTrue(' '.contains(new RegExp(re)));
|
||||
assertTrue('\xA0'.contains(new RegExp(re)));
|
||||
assertTrue('-'.contains(new RegExp(re)));
|
||||
assertTrue('0'.contains(new RegExp(re)));
|
||||
assertTrue('9'.contains(new RegExp(re)));
|
||||
assertFalse('1'.contains(new RegExp(re)));
|
||||
|
||||
// Test beginning and end of line assertions with or without the
|
||||
// multiline flag.
|
||||
re = r"^\d+";
|
||||
assertFalse("asdf\n123".contains(new RegExp(re)));
|
||||
re = new RegExp(r"^\d+", multiLine: true);
|
||||
assertTrue("asdf\n123".contains(re));
|
||||
|
||||
re = r"\d+$";
|
||||
assertFalse("123\nasdf".contains(new RegExp(re)));
|
||||
re = new RegExp(r"\d+$", multiLine: true);
|
||||
assertTrue("123\nasdf".contains(re));
|
||||
|
||||
// Test that empty matches are handled correctly for multiline global
|
||||
// regexps.
|
||||
re = new RegExp(r"^(.*)", multiLine: true);
|
||||
assertEquals(3, re.allMatches("a\n\rb").length);
|
||||
assertEquals("*a\n*b\r*c\n*\r*d\r*\n*e",
|
||||
"a\nb\rc\n\rd\r\ne".replaceAllMapped(re, (Match m) => "*${m.group(1)}"));
|
||||
|
||||
// Test that empty matches advance one character
|
||||
re = new RegExp("");
|
||||
assertEquals("xAx", "A".replaceAll(re, "x"));
|
||||
assertEquals(3, new String.fromCharCode(161).replaceAll(re, "x").length);
|
||||
|
||||
// Check for lazy RegExp literal creation
|
||||
lazyLiteral(doit) {
|
||||
if (doit)
|
||||
return "".replaceAll(new RegExp(r"foo(", caseSensitive: false), "");
|
||||
return true;
|
||||
}
|
||||
|
||||
assertTrue(lazyLiteral(false));
|
||||
assertThrows(() => lazyLiteral(true));
|
||||
|
||||
// Check $01 and $10
|
||||
re = new RegExp("(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)");
|
||||
assertEquals(
|
||||
"t", "123456789t".replaceAllMapped(re, (Match m) => m.group(10)));
|
||||
assertEquals(
|
||||
"15", "123456789t".replaceAllMapped(re, (Match m) => "${m.group(1)}5"));
|
||||
assertEquals("1", "123456789t".replaceAllMapped(re, (Match m) => m.group(1)));
|
||||
|
||||
assertFalse("football".contains(new RegExp(r"()foo$\1")), "football1");
|
||||
assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football2");
|
||||
assertFalse("football".contains(new RegExp(r"foo$(?!bar)")), "football3");
|
||||
assertTrue("foo".contains(new RegExp(r"()foo$\1")), "football4");
|
||||
assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football5");
|
||||
assertTrue("foo".contains(new RegExp(r"()foo$(?!bar)")), "football6");
|
||||
assertFalse("football".contains(new RegExp(r"(x?)foo$\1")), "football7");
|
||||
assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football8");
|
||||
assertFalse("football".contains(new RegExp(r"foo$(?!bar)")), "football9");
|
||||
assertTrue("foo".contains(new RegExp(r"(x?)foo$\1")), "football10");
|
||||
assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football11");
|
||||
assertTrue("foo".contains(new RegExp(r"foo$(?!bar)")), "football12");
|
||||
|
||||
// Check that the back reference has two successors. See
|
||||
// BackReferenceNode::PropagateForward.
|
||||
assertFalse('foo'.contains(new RegExp(r"f(o)\b\1")));
|
||||
assertTrue('foo'.contains(new RegExp(r"f(o)\B\1")));
|
||||
|
||||
// Back-reference, ignore case:
|
||||
// ASCII
|
||||
assertEquals(
|
||||
"a",
|
||||
new RegExp(r"x(a)\1x", caseSensitive: false).firstMatch("xaAx").group(1),
|
||||
"backref-ASCII");
|
||||
assertFalse("xaaaaa".contains(new RegExp(r"x(...)\1", caseSensitive: false)),
|
||||
"backref-ASCII-short");
|
||||
assertTrue("xx".contains(new RegExp(r"x((?:))\1\1x", caseSensitive: false)),
|
||||
"backref-ASCII-empty");
|
||||
assertTrue(
|
||||
"xabcx".contains(new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)),
|
||||
"backref-ASCII-uncaptured");
|
||||
assertTrue(
|
||||
"xabcABCx"
|
||||
.contains(new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)),
|
||||
"backref-ASCII-backtrack");
|
||||
assertEquals(
|
||||
"aBc",
|
||||
new RegExp(r"x(...)\1\1x", caseSensitive: false)
|
||||
.firstMatch("xaBcAbCABCx")
|
||||
.group(1),
|
||||
"backref-ASCII-twice");
|
||||
|
||||
for (var i = 0; i < 128; i++) {
|
||||
var testName = "backref-ASCII-char-$i,,${i^0x20}";
|
||||
var test = new String.fromCharCodes([i, i ^ 0x20])
|
||||
.contains(new RegExp(r"^(.)\1$", caseSensitive: false));
|
||||
if (('A'.codeUnitAt(0) <= i && i <= 'Z'.codeUnitAt(0)) ||
|
||||
('a'.codeUnitAt(0) <= i && i <= 'z'.codeUnitAt(0))) {
|
||||
assertTrue(test, testName);
|
||||
} else {
|
||||
assertFalse(test, testName);
|
||||
}
|
||||
}
|
||||
|
||||
assertFalse('foo'.contains(new RegExp(r"f(o)$\1")), "backref detects at_end");
|
||||
|
||||
// Check decimal escapes doesn't overflow.
|
||||
// (Note: \214 is interpreted as octal).
|
||||
assertEquals(
|
||||
"\x8c7483648",
|
||||
new RegExp(r"\2147483648").firstMatch("\x8c7483648").group(0),
|
||||
"Overflow decimal escape");
|
||||
|
||||
// Check numbers in quantifiers doesn't overflow and doesn't throw on
|
||||
// too large numbers.
|
||||
assertFalse(
|
||||
'b'.contains(
|
||||
new RegExp(r"a{111111111111111111111111111111111111111111111}")),
|
||||
"overlarge1");
|
||||
assertFalse(
|
||||
'b'.contains(
|
||||
new RegExp(r"a{999999999999999999999999999999999999999999999}")),
|
||||
"overlarge2");
|
||||
assertFalse(
|
||||
'b'.contains(
|
||||
new RegExp(r"a{1,111111111111111111111111111111111111111111111}")),
|
||||
"overlarge3");
|
||||
assertFalse(
|
||||
'b'.contains(
|
||||
new RegExp(r"a{1,999999999999999999999999999999999999999999999}")),
|
||||
"overlarge4");
|
||||
assertFalse('b'.contains(new RegExp(r"a{2147483648}")), "overlarge5");
|
||||
assertFalse('b'.contains(new RegExp(r"a{21474836471}")), "overlarge6");
|
||||
assertFalse('b'.contains(new RegExp(r"a{1,2147483648}")), "overlarge7");
|
||||
assertFalse('b'.contains(new RegExp(r"a{1,21474836471}")), "overlarge8");
|
||||
assertFalse(
|
||||
'b'.contains(new RegExp(r"a{2147483648,2147483648}")), "overlarge9");
|
||||
assertFalse(
|
||||
'b'.contains(new RegExp(r"a{21474836471,21474836471}")), "overlarge10");
|
||||
assertFalse('b'.contains(new RegExp(r"a{2147483647}")), "overlarge11");
|
||||
assertFalse('b'.contains(new RegExp(r"a{1,2147483647}")), "overlarge12");
|
||||
assertTrue('a'.contains(new RegExp(r"a{1,2147483647}")), "overlarge13");
|
||||
assertFalse(
|
||||
'a'.contains(new RegExp(r"a{2147483647,2147483647}")), "overlarge14");
|
||||
|
||||
// Check that we don't read past the end of the string.
|
||||
assertFalse('b'.contains(new RegExp(r"f")));
|
||||
assertFalse('x'.contains(new RegExp(r"[abc]f")));
|
||||
assertFalse('xa'.contains(new RegExp(r"[abc]f")));
|
||||
assertFalse('x'.contains(new RegExp(r"[abc]<")));
|
||||
assertFalse('xa'.contains(new RegExp(r"[abc]<")));
|
||||
assertFalse('b'.contains(new RegExp(r"f", caseSensitive: false)));
|
||||
assertFalse('x'.contains(new RegExp(r"[abc]f", caseSensitive: false)));
|
||||
assertFalse('xa'.contains(new RegExp(r"[abc]f", caseSensitive: false)));
|
||||
assertFalse('x'.contains(new RegExp(r"[abc]<", caseSensitive: false)));
|
||||
assertFalse('xa'.contains(new RegExp(r"[abc]<", caseSensitive: false)));
|
||||
assertFalse('x'.contains(new RegExp(r"f[abc]")));
|
||||
assertFalse('xa'.contains(new RegExp(r"f[abc]")));
|
||||
assertFalse('x'.contains(new RegExp(r"<[abc]")));
|
||||
assertFalse('xa'.contains(new RegExp(r"<[abc]")));
|
||||
assertFalse('x'.contains(new RegExp(r"f[abc]", caseSensitive: false)));
|
||||
assertFalse('xa'.contains(new RegExp(r"f[abc]", caseSensitive: false)));
|
||||
assertFalse('x'.contains(new RegExp(r"<[abc]", caseSensitive: false)));
|
||||
assertFalse('xa'.contains(new RegExp(r"<[abc]", caseSensitive: false)));
|
||||
|
||||
// Test that merging of quick test masks gets it right.
|
||||
assertFalse('x7%%y'.contains(new RegExp(r"x([0-7]%%x|[0-6]%%y)")), 'qt');
|
||||
assertFalse(
|
||||
'xy7%%%y'
|
||||
.contains(new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")),
|
||||
'qt2');
|
||||
assertFalse(
|
||||
'xy%%%y'
|
||||
.contains(new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")),
|
||||
'qt3');
|
||||
assertFalse(
|
||||
'xy7%%%y'.contains(new RegExp(r"()x\1y([0-7]%%%x|[0-6]%%%y)")), 'qt4');
|
||||
assertFalse(
|
||||
'xy%%%y'
|
||||
.contains(new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")),
|
||||
'qt5');
|
||||
assertFalse(
|
||||
'xy7%%%y'.contains(new RegExp(r"()x\1y([0-7]%%%x|[0-6]%%%y)")), 'qt6');
|
||||
assertFalse(
|
||||
'xy7%%%y'.contains(new RegExp(r"xy([0-7]%%%x|[0-6]%%%y)")), 'qt7');
|
||||
assertFalse('x7%%%y'.contains(new RegExp(r"x([0-7]%%%x|[0-6]%%%y)")), 'qt8');
|
||||
|
||||
// Don't hang on this one.
|
||||
"".contains(new RegExp(r"[^\xfe-\xff]*"));
|
||||
|
||||
var longbuffer = new StringBuffer("a");
|
||||
for (var i = 0; i < 100000; i++) {
|
||||
longbuffer.write("a?");
|
||||
}
|
||||
var long = longbuffer.toString();
|
||||
|
||||
// Don't crash on this one, but maybe throw an exception.
|
||||
try {
|
||||
new RegExp(long).allMatches("a");
|
||||
} catch (e) {
|
||||
assertTrue(e.toString().indexOf("Stack overflow") >= 0, "overflow");
|
||||
}
|
||||
|
||||
// Test boundary-checks.
|
||||
void assertRegExpTest(re, input, test) {
|
||||
assertEquals(
|
||||
test, input.contains(new RegExp(re)), "test:" + re + ":" + input);
|
||||
}
|
||||
|
||||
assertRegExpTest(r"b\b", "b", true);
|
||||
assertRegExpTest(r"b\b$", "b", true);
|
||||
assertRegExpTest(r"\bb", "b", true);
|
||||
assertRegExpTest(r"^\bb", "b", true);
|
||||
assertRegExpTest(r",\b", ",", false);
|
||||
assertRegExpTest(r",\b$", ",", false);
|
||||
assertRegExpTest(r"\b,", ",", false);
|
||||
assertRegExpTest(r"^\b,", ",", false);
|
||||
|
||||
assertRegExpTest(r"b\B", "b", false);
|
||||
assertRegExpTest(r"b\B$", "b", false);
|
||||
assertRegExpTest(r"\Bb", "b", false);
|
||||
assertRegExpTest(r"^\Bb", "b", false);
|
||||
assertRegExpTest(r",\B", ",", true);
|
||||
assertRegExpTest(r",\B$", ",", true);
|
||||
assertRegExpTest(r"\B,", ",", true);
|
||||
assertRegExpTest(r"^\B,", ",", true);
|
||||
|
||||
assertRegExpTest(r"b\b", "b,", true);
|
||||
assertRegExpTest(r"b\b", "ba", false);
|
||||
assertRegExpTest(r"b\B", "b,", false);
|
||||
assertRegExpTest(r"b\B", "ba", true);
|
||||
|
||||
assertRegExpTest(r"b\Bb", "bb", true);
|
||||
assertRegExpTest(r"b\bb", "bb", false);
|
||||
|
||||
assertRegExpTest(r"b\b[,b]", "bb", false);
|
||||
assertRegExpTest(r"b\B[,b]", "bb", true);
|
||||
assertRegExpTest(r"b\b[,b]", "b,", true);
|
||||
assertRegExpTest(r"b\B[,b]", "b,", false);
|
||||
|
||||
assertRegExpTest(r"[,b]\bb", "bb", false);
|
||||
assertRegExpTest(r"[,b]\Bb", "bb", true);
|
||||
assertRegExpTest(r"[,b]\bb", ",b", true);
|
||||
assertRegExpTest(r"[,b]\Bb", ",b", false);
|
||||
|
||||
assertRegExpTest(r"[,b]\b[,b]", "bb", false);
|
||||
assertRegExpTest(r"[,b]\B[,b]", "bb", true);
|
||||
assertRegExpTest(r"[,b]\b[,b]", ",b", true);
|
||||
assertRegExpTest(r"[,b]\B[,b]", ",b", false);
|
||||
assertRegExpTest(r"[,b]\b[,b]", "b,", true);
|
||||
assertRegExpTest(r"[,b]\B[,b]", "b,", false);
|
||||
|
||||
// Skipped tests from V8:
|
||||
|
||||
// Test that caching of result doesn't share result objects.
|
||||
// More iterations increases the chance of hitting a GC.
|
||||
|
||||
// Test that we perform the spec required conversions in the correct order.
|
||||
|
||||
// Check that properties of RegExp have the correct permissions.
|
||||
|
||||
// Check that end-anchored regexps are optimized correctly.
|
||||
re = r"(?:a|bc)g$";
|
||||
assertTrue("ag".contains(new RegExp(re)));
|
||||
assertTrue("bcg".contains(new RegExp(re)));
|
||||
assertTrue("abcg".contains(new RegExp(re)));
|
||||
assertTrue("zimbag".contains(new RegExp(re)));
|
||||
assertTrue("zimbcg".contains(new RegExp(re)));
|
||||
|
||||
assertFalse("g".contains(new RegExp(re)));
|
||||
assertFalse("".contains(new RegExp(re)));
|
||||
|
||||
// Global regexp (non-zero start).
|
||||
re = r"(?:a|bc)g$";
|
||||
assertTrue("ag".contains(new RegExp(re)));
|
||||
// Near start of string.
|
||||
assertTrue(new RegExp(re).allMatches("zimbag", 1).isNotEmpty);
|
||||
// At end of string.
|
||||
assertTrue(new RegExp(re).allMatches("zimbag", 6).isEmpty);
|
||||
// Near end of string.
|
||||
assertTrue(new RegExp(re).allMatches("zimbag", 5).isEmpty);
|
||||
assertTrue(new RegExp(re).allMatches("zimbag", 4).isNotEmpty);
|
||||
|
||||
// Anchored at both ends.
|
||||
re = r"^(?:a|bc)g$";
|
||||
assertTrue("ag".contains(new RegExp(re)));
|
||||
assertTrue(new RegExp(re).allMatches("ag", 1).isEmpty);
|
||||
assertTrue(new RegExp(re).allMatches("zag", 1).isEmpty);
|
||||
|
||||
// Long max_length of RegExp.
|
||||
re = r"VeryLongRegExp!{1,1000}$";
|
||||
assertTrue("BahoolaVeryLongRegExp!!!!!!".contains(new RegExp(re)));
|
||||
assertFalse("VeryLongRegExp".contains(new RegExp(re)));
|
||||
assertFalse("!".contains(new RegExp(re)));
|
||||
|
||||
// End anchor inside disjunction.
|
||||
re = r"(?:a$|bc$)";
|
||||
assertTrue("a".contains(new RegExp(re)));
|
||||
assertTrue("bc".contains(new RegExp(re)));
|
||||
assertTrue("abc".contains(new RegExp(re)));
|
||||
assertTrue("zimzamzumba".contains(new RegExp(re)));
|
||||
assertTrue("zimzamzumbc".contains(new RegExp(re)));
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
assertFalse("".contains(new RegExp(re)));
|
||||
|
||||
// Only partially anchored.
|
||||
re = r"(?:a|bc$)";
|
||||
assertTrue("a".contains(new RegExp(re)));
|
||||
assertTrue("bc".contains(new RegExp(re)));
|
||||
assertEquals("a", new RegExp(re).firstMatch("abc").group(0));
|
||||
assertEquals(4, new RegExp(re).firstMatch("zimzamzumba").start);
|
||||
assertEquals("bc", new RegExp(re).firstMatch("zimzomzumbc").group(0));
|
||||
assertFalse("c".contains(new RegExp(re)));
|
||||
assertFalse("".contains(new RegExp(re)));
|
||||
|
||||
// Valid syntax in ES5.
|
||||
re = new RegExp("(?:x)*");
|
||||
re = new RegExp("(x)*");
|
||||
|
||||
// Syntax extension relative to ES5, for matching JSC (and ES3).
|
||||
// Shouldn't throw.
|
||||
re = new RegExp("(?=x)*");
|
||||
re = new RegExp("(?!x)*");
|
||||
|
||||
// Should throw. Shouldn't hit asserts in debug mode.
|
||||
assertThrows(() => new RegExp('(*)'));
|
||||
assertThrows(() => new RegExp('(?:*)'));
|
||||
assertThrows(() => new RegExp('(?=*)'));
|
||||
assertThrows(() => new RegExp('(?!*)'));
|
||||
|
||||
// Test trimmed regular expression for RegExp.test().
|
||||
assertTrue("abc".contains(new RegExp(r".*abc")));
|
||||
assertFalse("q".contains(new RegExp(r".*\d+")));
|
||||
|
||||
// Tests skipped from V8:
|
||||
// Test that RegExp.prototype.toString() throws TypeError for
|
||||
// incompatible receivers (ES5 section 15.10.6 and 15.10.6.4).
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Copyright (c) 2014, the Dart project authors. All rights reserved.
|
||||
// Copyright 2009 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';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
// Check that the perfect mask check isn't overly optimistic.
|
||||
|
||||
assertFalse(new RegExp(r"[6-9]").hasMatch('2'));
|
||||
}
|
||||
Reference in New Issue
Block a user