Chromium Code Reviews| Index: tests/corelib_2/regexp/regexp_test.dart |
| diff --git a/tests/corelib/regexp/regexp_test.dart b/tests/corelib_2/regexp/regexp_test.dart |
| similarity index 83% |
| rename from tests/corelib/regexp/regexp_test.dart |
| rename to tests/corelib_2/regexp/regexp_test.dart |
| index aeea9c5c4545643fc65249182650df7d2555b313..52c306f1f79488b3c488884be063e42d18d5c6af 100644 |
| --- a/tests/corelib/regexp/regexp_test.dart |
| +++ b/tests/corelib_2/regexp/regexp_test.dart |
| @@ -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. |
|
Bob Nystrom
2017/07/26 23:54:49
There are still some more here and below if you lo
|
| 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)); |
| - |
| - re = new RegExp(r"^foo"); |
| - Expect.isNotNull(re.matchAsPrefix("foobar", 0)); |
| - Expect.isNull(re.matchAsPrefix("..foo", 0)); |
| - Expect.isNull(re.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)); |
| - |
| - re = new RegExp(r"bar$"); |
| - Expect.isNull(re.matchAsPrefix("foobar", 0)); |
| - Expect.isNotNull(re.matchAsPrefix("foobar", 3)); |
| + 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)); |
| + |
| + regexp = new RegExp(r"^foo"); |
| + Expect.isNotNull(regexp.matchAsPrefix("foobar", 0)); |
| + Expect.isNull(regexp.matchAsPrefix("..foo", 0)); |
| + Expect.isNull(regexp.matchAsPrefix("..foo", 2)); |
| + |
| + 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)); |
| + |
| + regexp = new RegExp(r"bar$"); |
| + Expect.isNull(regexp.matchAsPrefix("foobar", 0)); |
| + Expect.isNotNull(regexp.matchAsPrefix("foobar", 3)); |
| } |