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

Side by Side Diff: test/cctest/test-regexp.cc

Issue 9415: Add bytecodes and an interpreter for executing regular expressions. Very... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/regexp2000/
Patch Set: '' Created 12 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/regexp-codegen-re2k.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 18 matching lines...) Expand all
29 #include <stdlib.h> 29 #include <stdlib.h>
30 #include <set> 30 #include <set>
31 31
32 #include "v8.h" 32 #include "v8.h"
33 33
34 #include "cctest.h" 34 #include "cctest.h"
35 #include "zone-inl.h" 35 #include "zone-inl.h"
36 #include "parser.h" 36 #include "parser.h"
37 #include "ast.h" 37 #include "ast.h"
38 #include "jsregexp-inl.h" 38 #include "jsregexp-inl.h"
39 #include "assembler-re2k.h"
40 #include "interpreter-re2k.h"
39 41
40 42
41 using namespace v8::internal; 43 using namespace v8::internal;
42 44
43 45
44 class RegExpTestCase { 46 class RegExpTestCase {
45 public: 47 public:
46 RegExpTestCase() 48 RegExpTestCase()
47 : pattern_(NULL), 49 : pattern_(NULL),
48 flags_(NULL), 50 flags_(NULL),
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 OutSet outs = table.Get(p); 425 OutSet outs = table.Get(p);
424 for (int j = 0; j < kRangeCount; j++) { 426 for (int j = 0; j < kRangeCount; j++) {
425 uc16* range = ranges[j]; 427 uc16* range = ranges[j];
426 bool is_on = false; 428 bool is_on = false;
427 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) 429 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2)
428 is_on = (range[k] <= p && p <= range[k + 1]); 430 is_on = (range[k] <= p && p <= range[k + 1]);
429 CHECK_EQ(is_on, outs.Get(j)); 431 CHECK_EQ(is_on, outs.Get(j));
430 } 432 }
431 } 433 }
432 } 434 }
435
436
437 TEST(Assembler) {
438 V8::Initialize(NULL);
439
440 byte codes[1024];
441 Re2kAssembler assembler(codes, 1024);
442 #define __ assembler.
443 Label advance;
444 Label look_for_foo;
445 __ GoTo(&look_for_foo);
446 __ Bind(&advance);
447 __ AdvanceCP();
448 __ Bind(&look_for_foo);
449 __ FailIfWithin(3);
450 __ LoadCurrentChar(0);
451 __ CheckChar('f', &advance);
452 __ LoadCurrentChar(1);
453 __ CheckChar('o', &advance);
454 __ LoadCurrentChar(2);
455 __ CheckChar('o', &advance);
456 __ SetCapture(0);
457 __ SetCapture(1, 2);
458 __ Succeed();
459
460 v8::HandleScope scope;
461 Handle<ByteArray> array = Factory::NewByteArray(assembler.length());
462 assembler.Copy(array->GetDataStartAddress());
463 int captures[2];
464
465 Handle<String> f1 = Factory::NewStringFromAscii(CStrVector("Now is the time")) ;
466 CHECK(!Re2kInterpreter::Match(*array, *f1, captures, 0));
467
468 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz"));
469 CHECK(Re2kInterpreter::Match(*array, *f2, captures, 0));
470 CHECK_EQ(0, captures[0]);
471 CHECK_EQ(2, captures[1]);
472
473 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery"));
474 CHECK(Re2kInterpreter::Match(*array, *f3, captures, 0));
475 CHECK_EQ(3, captures[0]);
476 CHECK_EQ(5, captures[1]);
477 }
478
479
480
OLDNEW
« no previous file with comments | « src/regexp-codegen-re2k.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698