Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1562)

Unified Diff: test/mjsunit/regexp.js

Issue 5703001: Revert 5911 (RegExp fail on invalid range syntax).
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/mjsunit/third_party/regexp-pcre.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/regexp.js
diff --git a/test/mjsunit/regexp.js b/test/mjsunit/regexp.js
index 59c3ba8d2874f08dff99445f2de61257a80b4add..b57b86d2d88bbf2a882e0116e3c8be38b13f3cd7 100644
--- a/test/mjsunit/regexp.js
+++ b/test/mjsunit/regexp.js
@@ -110,6 +110,44 @@ assertFalse(re.test("\\]"));
assertFalse(re.test("\x03]")); // I.e., read as \cc
+// Test that we handle \s and \S correctly inside some bizarre
+// character classes.
+re = /[\s-:]/;
+assertTrue(re.test('-'));
+assertTrue(re.test(':'));
+assertTrue(re.test(' '));
+assertTrue(re.test('\t'));
+assertTrue(re.test('\n'));
+assertFalse(re.test('a'));
+assertFalse(re.test('Z'));
+
+re = /[\S-:]/;
+assertTrue(re.test('-'));
+assertTrue(re.test(':'));
+assertFalse(re.test(' '));
+assertFalse(re.test('\t'));
+assertFalse(re.test('\n'));
+assertTrue(re.test('a'));
+assertTrue(re.test('Z'));
+
+re = /[^\s-:]/;
+assertFalse(re.test('-'));
+assertFalse(re.test(':'));
+assertFalse(re.test(' '));
+assertFalse(re.test('\t'));
+assertFalse(re.test('\n'));
+assertTrue(re.test('a'));
+assertTrue(re.test('Z'));
+
+re = /[^\S-:]/;
+assertFalse(re.test('-'));
+assertFalse(re.test(':'));
+assertTrue(re.test(' '));
+assertTrue(re.test('\t'));
+assertTrue(re.test('\n'));
+assertFalse(re.test('a'));
+assertFalse(re.test('Z'));
+
re = /[\s]/;
assertFalse(re.test('-'));
assertFalse(re.test(':'));
@@ -609,47 +647,3 @@ assertEquals(4, re.exec("zimzamzumba").index);
assertEquals(["bc"], re.exec("zimzomzumbc"));
assertFalse(re.test("c"));
assertFalse(re.test(""));
-
-
-function testInvalidRange(str) {
- try {
- RegExp(str).test("x");
- } catch (e) {
- return;
- }
- assetUnreachable("Allowed invalid range in " + str);
-}
-
-function testValidRange(str) {
- try {
- RegExp(str).test("x");
- } catch (e) {
- assertUnreachable("Shouldn't fail parsing: " + str + ", was: " + e);
- }
-}
-
-testInvalidRange("[\\d-z]");
-testInvalidRange("[z-\\d]");
-testInvalidRange("[\\d-\\d]");
-testInvalidRange("[z-x]"); // Larger value first.
-testInvalidRange("[x-\\d-\\d]");
-
-testValidRange("[x-z]");
-testValidRange("[!--\d]"); // Second "-" is end of range.
-testValidRange("[\d-]");
-testValidRange("[-\d]");
-testValidRange("[-\d-]");
-testValidRange("[^-\d-]");
-testValidRange("[^-\d-]");
-testValidRange("[0-9-\w]");
-
-// Escaped dashes do not count as range operators.
-testValidRange("[\\d\\-z]");
-testValidRange("[z\\-\\d]");
-testValidRange("[\\d\\-\\d]");
-testValidRange("[z\\-x]");
-testValidRange("[x\\-\\d\\-\\d]");
-
-
-
-
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/mjsunit/third_party/regexp-pcre.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698