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

Side by Side Diff: test/mjsunit/regexp.js

Issue 6171001: Change interpretation of malformed \c? escapes in RegExp to match JSC. (Closed)
Patch Set: Addressed review comments. Created 9 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 result = s.match(re); 77 result = s.match(re);
78 assertEquals(result.length, 7); 78 assertEquals(result.length, 7);
79 assertEquals(result[0], 'A'); 79 assertEquals(result[0], 'A');
80 assertEquals(result[1], 'B'); 80 assertEquals(result[1], 'B');
81 assertEquals(result[2], 'C'); 81 assertEquals(result[2], 'C');
82 assertEquals(result[3], '\r'); 82 assertEquals(result[3], '\r');
83 assertEquals(result[4], 'D'); 83 assertEquals(result[4], 'D');
84 assertEquals(result[5], 'E'); 84 assertEquals(result[5], 'E');
85 assertEquals(result[6], 'F'); 85 assertEquals(result[6], 'F');
86 86
87 // Some tests from the Mozilla tests, where our behavior differs from 87 // Some tests from the Mozilla tests, where our behavior used to differ from
88 // SpiderMonkey. 88 // SpiderMonkey.
89 // From ecma_3/RegExp/regress-334158.js 89 // From ecma_3/RegExp/regress-334158.js
90 assertTrue(/\ca/.test( "\x01" )); 90 assertTrue(/\ca/.test( "\x01" ));
91 assertFalse(/\ca/.test( "\\ca" )); 91 assertFalse(/\ca/.test( "\\ca" ));
92 // Passes in KJS, fails in IrregularExpressions. 92 assertFalse(/\ca/.test( "ca" ));
93 // See http://code.google.com/p/v8/issues/detail?id=152 93 assertTrue(/\c[a/]/.test( "\\ca" ));
94 //assertTrue(/\c[a/]/.test( "\x1ba/]" )); 94 assertTrue(/\c[a/]/.test( "\\c/" ));
95
96 95
97 // Test \c in character class 96 // Test \c in character class
98 re = /^[\cM]$/; 97 re = /^[\cM]$/;
99 assertTrue(re.test("\r")); 98 assertTrue(re.test("\r"));
100 assertFalse(re.test("M")); 99 assertFalse(re.test("M"));
101 assertFalse(re.test("c")); 100 assertFalse(re.test("c"));
102 assertFalse(re.test("\\")); 101 assertFalse(re.test("\\"));
103 assertFalse(re.test("\x03")); // I.e., read as \cc 102 assertFalse(re.test("\x03")); // I.e., read as \cc
104 103
105 re = /^[\c]]$/; 104 re = /^[\c]]$/;
106 assertTrue(re.test("c]")); 105 assertTrue(re.test("c]"));
107 assertFalse(re.test("\\]")); 106 assertTrue(re.test("\\]"));
108 assertFalse(re.test("\x1d")); // ']' & 0x1f 107 assertFalse(re.test("\x1d")); // ']' & 0x1f
109 assertFalse(re.test("\\]"));
110 assertFalse(re.test("\x03]")); // I.e., read as \cc 108 assertFalse(re.test("\x03]")); // I.e., read as \cc
111 109
110 re = /^[\c1]$/; // Digit control characters are masked in character classes.
111 assertTrue(re.test("\x11"));
112 assertFalse(re.test("\\"));
113 assertFalse(re.test("c"));
114 assertFalse(re.test("1"));
115
116 re = /^[\c_]$/; // Underscore control character is masked in character classes.
117 assertTrue(re.test("\x1f"));
118 assertFalse(re.test("\\"));
119 assertFalse(re.test("c"));
120 assertFalse(re.test("_"));
121
122 re = /^[\c$]$/; // Other characters are interpreted literally.
123 assertFalse(re.test("\x04"));
124 assertTrue(re.test("\\"));
125 assertTrue(re.test("c"));
126 assertTrue(re.test("$"));
127
128 assertTrue(/^[Z-\c-e]*$/.test("Z[\\cde"));
112 129
113 // Test that we handle \s and \S correctly inside some bizarre 130 // Test that we handle \s and \S correctly inside some bizarre
114 // character classes. 131 // character classes.
115 re = /[\s-:]/; 132 re = /[\s-:]/;
116 assertTrue(re.test('-')); 133 assertTrue(re.test('-'));
117 assertTrue(re.test(':')); 134 assertTrue(re.test(':'));
118 assertTrue(re.test(' ')); 135 assertTrue(re.test(' '));
119 assertTrue(re.test('\t')); 136 assertTrue(re.test('\t'));
120 assertTrue(re.test('\n')); 137 assertTrue(re.test('\n'));
121 assertFalse(re.test('a')); 138 assertFalse(re.test('a'));
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 // Only partially anchored. 669 // Only partially anchored.
653 var re = /(?:a|bc$)/; 670 var re = /(?:a|bc$)/;
654 assertTrue(re.test("a")); 671 assertTrue(re.test("a"));
655 assertTrue(re.test("bc")); 672 assertTrue(re.test("bc"));
656 assertEquals(["a"], re.exec("abc")); 673 assertEquals(["a"], re.exec("abc"));
657 assertEquals(4, re.exec("zimzamzumba").index); 674 assertEquals(4, re.exec("zimzamzumba").index);
658 assertEquals(["bc"], re.exec("zimzomzumbc")); 675 assertEquals(["bc"], re.exec("zimzomzumbc"));
659 assertFalse(re.test("c")); 676 assertFalse(re.test("c"));
660 assertFalse(re.test("")); 677 assertFalse(re.test(""));
661 678
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698