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

Side by Side Diff: runtime/vm/regexp_test.cc

Issue 1071713003: - Remove JSCRE from the runtime. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« runtime/vm/raw_object_snapshot.cc ('K') | « runtime/vm/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 (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/regexp.h" 9 #include "vm/regexp.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 DECLARE_FLAG(bool, use_jscre); 14 DECLARE_FLAG(bool, use_jscre);
15 15
16 static RawArray* Match(const String& pat, const String& str) { 16 static RawArray* Match(const String& pat, const String& str) {
17 Zone* zone = Thread::Current()->zone(); 17 Zone* zone = Thread::Current()->zone();
18 const JSRegExp& regexp = JSRegExp::Handle( 18 const JSRegExp& regexp = JSRegExp::Handle(
19 RegExpEngine::CreateJSRegExp(zone, pat, false, false)); 19 RegExpEngine::CreateJSRegExp(zone, pat, false, false));
20 const intptr_t cid = str.GetClassId(); 20 const intptr_t cid = str.GetClassId();
21 const Function& fn = Function::Handle(regexp.function(cid)); 21 const Function& fn = Function::Handle(regexp.function(cid));
22 EXPECT(!fn.IsNull()); 22 EXPECT(!fn.IsNull());
23 const Smi& idx = Smi::Handle(Smi::New(0)); 23 const Smi& idx = Smi::Handle(Smi::New(0));
24 return IRRegExpMacroAssembler::Execute(fn, str, idx, zone); 24 return IRRegExpMacroAssembler::Execute(fn, str, idx, zone);
25 } 25 }
26 26
27 TEST_CASE(RegExp_OneByteString) { 27 TEST_CASE(RegExp_OneByteString) {
28 if (FLAG_use_jscre)
29 return;
30
31 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; 28 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' };
32 intptr_t len = ARRAY_SIZE(chars); 29 intptr_t len = ARRAY_SIZE(chars);
33 const String& str = String::Handle( 30 const String& str = String::Handle(
34 OneByteString::New(chars, len, Heap::kNew)); 31 OneByteString::New(chars, len, Heap::kNew));
35 32
36 const String& pat = String::Handle(String::New("bc")); 33 const String& pat = String::Handle(String::New("bc"));
37 const Array& res = Array::Handle(Match(pat, str)); 34 const Array& res = Array::Handle(Match(pat, str));
38 EXPECT_EQ(2, res.Length()); 35 EXPECT_EQ(2, res.Length());
39 36
40 const Object& res_1 = Object::Handle(res.At(0)); 37 const Object& res_1 = Object::Handle(res.At(0));
41 const Object& res_2 = Object::Handle(res.At(1)); 38 const Object& res_2 = Object::Handle(res.At(1));
42 EXPECT(res_1.IsSmi()); 39 EXPECT(res_1.IsSmi());
43 EXPECT(res_2.IsSmi()); 40 EXPECT(res_2.IsSmi());
44 41
45 const Smi& smi_1 = Smi::Cast(res_1); 42 const Smi& smi_1 = Smi::Cast(res_1);
46 const Smi& smi_2 = Smi::Cast(res_2); 43 const Smi& smi_2 = Smi::Cast(res_2);
47 EXPECT_EQ(1, smi_1.Value()); 44 EXPECT_EQ(1, smi_1.Value());
48 EXPECT_EQ(3, smi_2.Value()); 45 EXPECT_EQ(3, smi_2.Value());
49 } 46 }
50 47
51 TEST_CASE(RegExp_TwoByteString) { 48 TEST_CASE(RegExp_TwoByteString) {
52 if (FLAG_use_jscre)
53 return;
54
55 uint16_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; 49 uint16_t chars[] = { 'a', 'b', 'c', 'b', 'a' };
56 intptr_t len = ARRAY_SIZE(chars); 50 intptr_t len = ARRAY_SIZE(chars);
57 const String& str = String::Handle( 51 const String& str = String::Handle(
58 TwoByteString::New(chars, len, Heap::kNew)); 52 TwoByteString::New(chars, len, Heap::kNew));
59 53
60 const String& pat = String::Handle(String::New("bc")); 54 const String& pat = String::Handle(String::New("bc"));
61 const Array& res = Array::Handle(Match(pat, str)); 55 const Array& res = Array::Handle(Match(pat, str));
62 EXPECT_EQ(2, res.Length()); 56 EXPECT_EQ(2, res.Length());
63 57
64 const Object& res_1 = Object::Handle(res.At(0)); 58 const Object& res_1 = Object::Handle(res.At(0));
65 const Object& res_2 = Object::Handle(res.At(1)); 59 const Object& res_2 = Object::Handle(res.At(1));
66 EXPECT(res_1.IsSmi()); 60 EXPECT(res_1.IsSmi());
67 EXPECT(res_2.IsSmi()); 61 EXPECT(res_2.IsSmi());
68 62
69 const Smi& smi_1 = Smi::Cast(res_1); 63 const Smi& smi_1 = Smi::Cast(res_1);
70 const Smi& smi_2 = Smi::Cast(res_2); 64 const Smi& smi_2 = Smi::Cast(res_2);
71 EXPECT_EQ(1, smi_1.Value()); 65 EXPECT_EQ(1, smi_1.Value());
72 EXPECT_EQ(3, smi_2.Value()); 66 EXPECT_EQ(3, smi_2.Value());
73 } 67 }
74 68
75 TEST_CASE(RegExp_ExternalOneByteString) { 69 TEST_CASE(RegExp_ExternalOneByteString) {
76 if (FLAG_use_jscre)
77 return;
78
79 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; 70 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' };
80 intptr_t len = ARRAY_SIZE(chars); 71 intptr_t len = ARRAY_SIZE(chars);
81 const String& str = String::Handle( 72 const String& str = String::Handle(
82 ExternalOneByteString::New(chars, len, NULL, NULL, Heap::kNew)); 73 ExternalOneByteString::New(chars, len, NULL, NULL, Heap::kNew));
83 74
84 const String& pat = String::Handle(String::New("bc")); 75 const String& pat = String::Handle(String::New("bc"));
85 const Array& res = Array::Handle(Match(pat, str)); 76 const Array& res = Array::Handle(Match(pat, str));
86 EXPECT_EQ(2, res.Length()); 77 EXPECT_EQ(2, res.Length());
87 78
88 const Object& res_1 = Object::Handle(res.At(0)); 79 const Object& res_1 = Object::Handle(res.At(0));
89 const Object& res_2 = Object::Handle(res.At(1)); 80 const Object& res_2 = Object::Handle(res.At(1));
90 EXPECT(res_1.IsSmi()); 81 EXPECT(res_1.IsSmi());
91 EXPECT(res_2.IsSmi()); 82 EXPECT(res_2.IsSmi());
92 83
93 const Smi& smi_1 = Smi::Cast(res_1); 84 const Smi& smi_1 = Smi::Cast(res_1);
94 const Smi& smi_2 = Smi::Cast(res_2); 85 const Smi& smi_2 = Smi::Cast(res_2);
95 EXPECT_EQ(1, smi_1.Value()); 86 EXPECT_EQ(1, smi_1.Value());
96 EXPECT_EQ(3, smi_2.Value()); 87 EXPECT_EQ(3, smi_2.Value());
97 } 88 }
98 89
99 TEST_CASE(RegExp_ExternalTwoByteString) { 90 TEST_CASE(RegExp_ExternalTwoByteString) {
100 if (FLAG_use_jscre)
101 return;
102
103 uint16_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; 91 uint16_t chars[] = { 'a', 'b', 'c', 'b', 'a' };
104 intptr_t len = ARRAY_SIZE(chars); 92 intptr_t len = ARRAY_SIZE(chars);
105 const String& str = String::Handle( 93 const String& str = String::Handle(
106 ExternalTwoByteString::New(chars, len, NULL, NULL, Heap::kNew)); 94 ExternalTwoByteString::New(chars, len, NULL, NULL, Heap::kNew));
107 95
108 const String& pat = String::Handle(String::New("bc")); 96 const String& pat = String::Handle(String::New("bc"));
109 const Array& res = Array::Handle(Match(pat, str)); 97 const Array& res = Array::Handle(Match(pat, str));
110 EXPECT_EQ(2, res.Length()); 98 EXPECT_EQ(2, res.Length());
111 99
112 const Object& res_1 = Object::Handle(res.At(0)); 100 const Object& res_1 = Object::Handle(res.At(0));
113 const Object& res_2 = Object::Handle(res.At(1)); 101 const Object& res_2 = Object::Handle(res.At(1));
114 EXPECT(res_1.IsSmi()); 102 EXPECT(res_1.IsSmi());
115 EXPECT(res_2.IsSmi()); 103 EXPECT(res_2.IsSmi());
116 104
117 const Smi& smi_1 = Smi::Cast(res_1); 105 const Smi& smi_1 = Smi::Cast(res_1);
118 const Smi& smi_2 = Smi::Cast(res_2); 106 const Smi& smi_2 = Smi::Cast(res_2);
119 EXPECT_EQ(1, smi_1.Value()); 107 EXPECT_EQ(1, smi_1.Value());
120 EXPECT_EQ(3, smi_2.Value()); 108 EXPECT_EQ(3, smi_2.Value());
121 } 109 }
122 110
123 } // namespace dart 111 } // namespace dart
OLDNEW
« runtime/vm/raw_object_snapshot.cc ('K') | « runtime/vm/regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698