Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 153 |
| 154 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) | 154 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) |
| 155 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); | 155 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); |
| 156 #define CHECK_MIN_MAX(input, min, max) \ | 156 #define CHECK_MIN_MAX(input, min, max) \ |
| 157 { MinMaxPair min_max = CheckMinMaxMatch(input); \ | 157 { MinMaxPair min_max = CheckMinMaxMatch(input); \ |
| 158 CHECK_EQ(min, min_max.min_match); \ | 158 CHECK_EQ(min, min_max.min_match); \ |
| 159 CHECK_EQ(max, min_max.max_match); \ | 159 CHECK_EQ(max, min_max.max_match); \ |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST(Parser) { | 162 TEST(Parser) { |
| 163 FLAG_harmony_regexp_lookbehind = true; | |
|
erikcorry
2015/11/11 15:39:04
Probably better to put this whole test in a static
Yang
2015/11/12 08:25:35
Done.
| |
| 164 | |
| 163 CHECK_PARSE_ERROR("?"); | 165 CHECK_PARSE_ERROR("?"); |
| 164 | 166 |
| 165 CheckParseEq("abc", "'abc'"); | 167 CheckParseEq("abc", "'abc'"); |
| 166 CheckParseEq("", "%"); | 168 CheckParseEq("", "%"); |
| 167 CheckParseEq("abc|def", "(| 'abc' 'def')"); | 169 CheckParseEq("abc|def", "(| 'abc' 'def')"); |
| 168 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); | 170 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); |
| 169 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); | 171 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); |
| 170 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); | 172 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); |
| 171 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); | 173 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); |
| 172 CheckParseEq("a*", "(# 0 - g 'a')"); | 174 CheckParseEq("a*", "(# 0 - g 'a')"); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 184 CheckParseEq("xyz{1,}", "(: 'xy' (# 1 - g 'z'))"); | 186 CheckParseEq("xyz{1,}", "(: 'xy' (# 1 - g 'z'))"); |
| 185 CheckParseEq("xyz{1,}?", "(: 'xy' (# 1 - n 'z'))"); | 187 CheckParseEq("xyz{1,}?", "(: 'xy' (# 1 - n 'z'))"); |
| 186 CheckParseEq("a\\fb\\nc\\rd\\te\\vf", "'a\\x0cb\\x0ac\\x0dd\\x09e\\x0bf'"); | 188 CheckParseEq("a\\fb\\nc\\rd\\te\\vf", "'a\\x0cb\\x0ac\\x0dd\\x09e\\x0bf'"); |
| 187 CheckParseEq("a\\nb\\bc", "(: 'a\\x0ab' @b 'c')"); | 189 CheckParseEq("a\\nb\\bc", "(: 'a\\x0ab' @b 'c')"); |
| 188 CheckParseEq("(?:foo)", "'foo'"); | 190 CheckParseEq("(?:foo)", "'foo'"); |
| 189 CheckParseEq("(?: foo )", "' foo '"); | 191 CheckParseEq("(?: foo )", "' foo '"); |
| 190 CheckParseEq("(foo|bar|baz)", "(^ (| 'foo' 'bar' 'baz'))"); | 192 CheckParseEq("(foo|bar|baz)", "(^ (| 'foo' 'bar' 'baz'))"); |
| 191 CheckParseEq("foo|(bar|baz)|quux", "(| 'foo' (^ (| 'bar' 'baz')) 'quux')"); | 193 CheckParseEq("foo|(bar|baz)|quux", "(| 'foo' (^ (| 'bar' 'baz')) 'quux')"); |
| 192 CheckParseEq("foo(?=bar)baz", "(: 'foo' (-> + 'bar') 'baz')"); | 194 CheckParseEq("foo(?=bar)baz", "(: 'foo' (-> + 'bar') 'baz')"); |
| 193 CheckParseEq("foo(?!bar)baz", "(: 'foo' (-> - 'bar') 'baz')"); | 195 CheckParseEq("foo(?!bar)baz", "(: 'foo' (-> - 'bar') 'baz')"); |
| 196 CheckParseEq("foo(?<=bar)baz", "(: 'foo' (<- + 'bar') 'baz')"); | |
| 197 CheckParseEq("foo(?<!bar)baz", "(: 'foo' (<- - 'bar') 'baz')"); | |
| 194 CheckParseEq("()", "(^ %)"); | 198 CheckParseEq("()", "(^ %)"); |
| 195 CheckParseEq("(?=)", "(-> + %)"); | 199 CheckParseEq("(?=)", "(-> + %)"); |
| 196 CheckParseEq("[]", "^[\\x00-\\uffff]"); // Doesn't compile on windows | 200 CheckParseEq("[]", "^[\\x00-\\uffff]"); // Doesn't compile on windows |
| 197 CheckParseEq("[^]", "[\\x00-\\uffff]"); // \uffff isn't in codepage 1252 | 201 CheckParseEq("[^]", "[\\x00-\\uffff]"); // \uffff isn't in codepage 1252 |
| 198 CheckParseEq("[x]", "[x]"); | 202 CheckParseEq("[x]", "[x]"); |
| 199 CheckParseEq("[xyz]", "[x y z]"); | 203 CheckParseEq("[xyz]", "[x y z]"); |
| 200 CheckParseEq("[a-zA-Z0-9]", "[a-z A-Z 0-9]"); | 204 CheckParseEq("[a-zA-Z0-9]", "[a-z A-Z 0-9]"); |
| 201 CheckParseEq("[-123]", "[- 1 2 3]"); | 205 CheckParseEq("[-123]", "[- 1 2 3]"); |
| 202 CheckParseEq("[^123]", "^[1 2 3]"); | 206 CheckParseEq("[^123]", "^[1 2 3]"); |
| 203 CheckParseEq("]", "']'"); | 207 CheckParseEq("]", "']'"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 CheckParseEq("(x)(x)(x)\\4*", | 257 CheckParseEq("(x)(x)(x)\\4*", |
| 254 "(: (^ 'x') (^ 'x') (^ 'x')" | 258 "(: (^ 'x') (^ 'x') (^ 'x')" |
| 255 " (# 0 - g '\\x04'))"); | 259 " (# 0 - g '\\x04'))"); |
| 256 CheckParseEq("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\10", | 260 CheckParseEq("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\10", |
| 257 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" | 261 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" |
| 258 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') (<- 10))"); | 262 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') (<- 10))"); |
| 259 CheckParseEq("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\11", | 263 CheckParseEq("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\11", |
| 260 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" | 264 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" |
| 261 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); | 265 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); |
| 262 CheckParseEq("(a)\\1", "(: (^ 'a') (<- 1))"); | 266 CheckParseEq("(a)\\1", "(: (^ 'a') (<- 1))"); |
| 263 CheckParseEq("(a\\1)", "(^ 'a')"); | 267 CheckParseEq("(a\\1)", "(^ (: 'a' (<- 1)))"); |
| 264 CheckParseEq("(\\1a)", "(^ 'a')"); | 268 CheckParseEq("(\\1a)", "(^ (: (<- 1) 'a'))"); |
| 265 CheckParseEq("(?=a)?a", "'a'"); | 269 CheckParseEq("(?=a)?a", "'a'"); |
| 266 CheckParseEq("(?=a){0,10}a", "'a'"); | 270 CheckParseEq("(?=a){0,10}a", "'a'"); |
| 267 CheckParseEq("(?=a){1,10}a", "(: (-> + 'a') 'a')"); | 271 CheckParseEq("(?=a){1,10}a", "(: (-> + 'a') 'a')"); |
| 268 CheckParseEq("(?=a){9,10}a", "(: (-> + 'a') 'a')"); | 272 CheckParseEq("(?=a){9,10}a", "(: (-> + 'a') 'a')"); |
| 269 CheckParseEq("(?!a)?a", "'a'"); | 273 CheckParseEq("(?!a)?a", "'a'"); |
| 270 CheckParseEq("\\1(a)", "(^ 'a')"); | 274 CheckParseEq("\\1(a)", "(: (<- 1) (^ 'a'))"); |
| 271 CheckParseEq("(?!(a))\\1", "(: (-> - (^ 'a')) (<- 1))"); | 275 CheckParseEq("(?!(a))\\1", "(: (-> - (^ 'a')) (<- 1))"); |
| 272 CheckParseEq("(?!\\1(a\\1)\\1)\\1", "(: (-> - (: (^ 'a') (<- 1))) (<- 1))"); | 276 CheckParseEq("(?!\\1(a\\1)\\1)\\1", |
| 277 "(: (-> - (: (<- 1) (^ (: 'a' (<- 1))) (<- 1))) (<- 1))"); | |
| 273 CheckParseEq("[\\0]", "[\\x00]"); | 278 CheckParseEq("[\\0]", "[\\x00]"); |
| 274 CheckParseEq("[\\11]", "[\\x09]"); | 279 CheckParseEq("[\\11]", "[\\x09]"); |
| 275 CheckParseEq("[\\11a]", "[\\x09 a]"); | 280 CheckParseEq("[\\11a]", "[\\x09 a]"); |
| 276 CheckParseEq("[\\011]", "[\\x09]"); | 281 CheckParseEq("[\\011]", "[\\x09]"); |
| 277 CheckParseEq("[\\00011]", "[\\x00 1 1]"); | 282 CheckParseEq("[\\00011]", "[\\x00 1 1]"); |
| 278 CheckParseEq("[\\118]", "[\\x09 8]"); | 283 CheckParseEq("[\\118]", "[\\x09 8]"); |
| 279 CheckParseEq("[\\111]", "[I]"); | 284 CheckParseEq("[\\111]", "[I]"); |
| 280 CheckParseEq("[\\1111]", "[I 1]"); | 285 CheckParseEq("[\\1111]", "[I 1]"); |
| 281 CheckParseEq("\\x34", "'\x34'"); | 286 CheckParseEq("\\x34", "'\x34'"); |
| 282 CheckParseEq("\\x60", "'\x60'"); | 287 CheckParseEq("\\x60", "'\x60'"); |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1381 // ^f(o)o. | 1386 // ^f(o)o. |
| 1382 Label start, fail, backtrack; | 1387 Label start, fail, backtrack; |
| 1383 | 1388 |
| 1384 m.SetRegister(4, 42); | 1389 m.SetRegister(4, 42); |
| 1385 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); | 1390 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1386 m.AdvanceRegister(4, 42); | 1391 m.AdvanceRegister(4, 42); |
| 1387 m.GoTo(&start); | 1392 m.GoTo(&start); |
| 1388 m.Fail(); | 1393 m.Fail(); |
| 1389 m.Bind(&start); | 1394 m.Bind(&start); |
| 1390 m.PushBacktrack(&fail); | 1395 m.PushBacktrack(&fail); |
| 1391 m.CheckNotAtStart(NULL); | 1396 m.CheckNotAtStart(0, NULL); |
| 1392 m.LoadCurrentCharacter(0, NULL); | 1397 m.LoadCurrentCharacter(0, NULL); |
| 1393 m.CheckNotCharacter('f', NULL); | 1398 m.CheckNotCharacter('f', NULL); |
| 1394 m.LoadCurrentCharacter(1, NULL); | 1399 m.LoadCurrentCharacter(1, NULL); |
| 1395 m.CheckNotCharacter('o', NULL); | 1400 m.CheckNotCharacter('o', NULL); |
| 1396 m.LoadCurrentCharacter(2, NULL); | 1401 m.LoadCurrentCharacter(2, NULL); |
| 1397 m.CheckNotCharacter('o', NULL); | 1402 m.CheckNotCharacter('o', NULL); |
| 1398 m.WriteCurrentPositionToRegister(0, 0); | 1403 m.WriteCurrentPositionToRegister(0, 0); |
| 1399 m.WriteCurrentPositionToRegister(1, 3); | 1404 m.WriteCurrentPositionToRegister(1, 3); |
| 1400 m.WriteCurrentPositionToRegister(2, 1); | 1405 m.WriteCurrentPositionToRegister(2, 1); |
| 1401 m.WriteCurrentPositionToRegister(3, 2); | 1406 m.WriteCurrentPositionToRegister(3, 2); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1812 | 1817 |
| 1813 ZoneList<CharacterRange> first_only(4, &zone); | 1818 ZoneList<CharacterRange> first_only(4, &zone); |
| 1814 ZoneList<CharacterRange> second_only(4, &zone); | 1819 ZoneList<CharacterRange> second_only(4, &zone); |
| 1815 ZoneList<CharacterRange> both(4, &zone); | 1820 ZoneList<CharacterRange> both(4, &zone); |
| 1816 } | 1821 } |
| 1817 | 1822 |
| 1818 | 1823 |
| 1819 TEST(Graph) { | 1824 TEST(Graph) { |
| 1820 Execute("\\b\\w+\\b", false, true, true); | 1825 Execute("\\b\\w+\\b", false, true, true); |
| 1821 } | 1826 } |
| OLD | NEW |