OLD | NEW |
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/regexp_assembler_ir.h" | 10 #include "vm/regexp_assembler_ir.h" |
11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 static RawArray* Match(const String& pat, const String& str) { | 15 static RawArray* Match(const String& pat, const String& str) { |
16 Thread* thread = Thread::Current(); | 16 Thread* thread = Thread::Current(); |
17 Zone* zone = thread->zone(); | 17 Zone* zone = thread->zone(); |
18 const RegExp& regexp = RegExp::Handle( | 18 const RegExp& regexp = |
19 RegExpEngine::CreateRegExp(thread, pat, false, false)); | 19 RegExp::Handle(RegExpEngine::CreateRegExp(thread, pat, false, false)); |
20 const Smi& idx = Smi::Handle(Smi::New(0)); | 20 const Smi& idx = Smi::Handle(Smi::New(0)); |
21 return IRRegExpMacroAssembler::Execute(regexp, str, idx, zone); | 21 return IRRegExpMacroAssembler::Execute(regexp, str, idx, zone); |
22 } | 22 } |
23 | 23 |
24 TEST_CASE(RegExp_OneByteString) { | 24 TEST_CASE(RegExp_OneByteString) { |
25 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; | 25 uint8_t chars[] = {'a', 'b', 'c', 'b', 'a'}; |
26 intptr_t len = ARRAY_SIZE(chars); | 26 intptr_t len = ARRAY_SIZE(chars); |
27 const String& str = String::Handle( | 27 const String& str = |
28 OneByteString::New(chars, len, Heap::kNew)); | 28 String::Handle(OneByteString::New(chars, len, Heap::kNew)); |
29 | 29 |
30 const String& pat = String::Handle(String::New("bc")); | 30 const String& pat = String::Handle(String::New("bc")); |
31 const Array& res = Array::Handle(Match(pat, str)); | 31 const Array& res = Array::Handle(Match(pat, str)); |
32 EXPECT_EQ(2, res.Length()); | 32 EXPECT_EQ(2, res.Length()); |
33 | 33 |
34 const Object& res_1 = Object::Handle(res.At(0)); | 34 const Object& res_1 = Object::Handle(res.At(0)); |
35 const Object& res_2 = Object::Handle(res.At(1)); | 35 const Object& res_2 = Object::Handle(res.At(1)); |
36 EXPECT(res_1.IsSmi()); | 36 EXPECT(res_1.IsSmi()); |
37 EXPECT(res_2.IsSmi()); | 37 EXPECT(res_2.IsSmi()); |
38 | 38 |
39 const Smi& smi_1 = Smi::Cast(res_1); | 39 const Smi& smi_1 = Smi::Cast(res_1); |
40 const Smi& smi_2 = Smi::Cast(res_2); | 40 const Smi& smi_2 = Smi::Cast(res_2); |
41 EXPECT_EQ(1, smi_1.Value()); | 41 EXPECT_EQ(1, smi_1.Value()); |
42 EXPECT_EQ(3, smi_2.Value()); | 42 EXPECT_EQ(3, smi_2.Value()); |
43 } | 43 } |
44 | 44 |
45 TEST_CASE(RegExp_TwoByteString) { | 45 TEST_CASE(RegExp_TwoByteString) { |
46 uint16_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; | 46 uint16_t chars[] = {'a', 'b', 'c', 'b', 'a'}; |
47 intptr_t len = ARRAY_SIZE(chars); | 47 intptr_t len = ARRAY_SIZE(chars); |
48 const String& str = String::Handle( | 48 const String& str = |
49 TwoByteString::New(chars, len, Heap::kNew)); | 49 String::Handle(TwoByteString::New(chars, len, Heap::kNew)); |
50 | 50 |
51 const String& pat = String::Handle(String::New("bc")); | 51 const String& pat = String::Handle(String::New("bc")); |
52 const Array& res = Array::Handle(Match(pat, str)); | 52 const Array& res = Array::Handle(Match(pat, str)); |
53 EXPECT_EQ(2, res.Length()); | 53 EXPECT_EQ(2, res.Length()); |
54 | 54 |
55 const Object& res_1 = Object::Handle(res.At(0)); | 55 const Object& res_1 = Object::Handle(res.At(0)); |
56 const Object& res_2 = Object::Handle(res.At(1)); | 56 const Object& res_2 = Object::Handle(res.At(1)); |
57 EXPECT(res_1.IsSmi()); | 57 EXPECT(res_1.IsSmi()); |
58 EXPECT(res_2.IsSmi()); | 58 EXPECT(res_2.IsSmi()); |
59 | 59 |
60 const Smi& smi_1 = Smi::Cast(res_1); | 60 const Smi& smi_1 = Smi::Cast(res_1); |
61 const Smi& smi_2 = Smi::Cast(res_2); | 61 const Smi& smi_2 = Smi::Cast(res_2); |
62 EXPECT_EQ(1, smi_1.Value()); | 62 EXPECT_EQ(1, smi_1.Value()); |
63 EXPECT_EQ(3, smi_2.Value()); | 63 EXPECT_EQ(3, smi_2.Value()); |
64 } | 64 } |
65 | 65 |
66 TEST_CASE(RegExp_ExternalOneByteString) { | 66 TEST_CASE(RegExp_ExternalOneByteString) { |
67 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; | 67 uint8_t chars[] = {'a', 'b', 'c', 'b', 'a'}; |
68 intptr_t len = ARRAY_SIZE(chars); | 68 intptr_t len = ARRAY_SIZE(chars); |
69 const String& str = String::Handle( | 69 const String& str = String::Handle( |
70 ExternalOneByteString::New(chars, len, NULL, NULL, Heap::kNew)); | 70 ExternalOneByteString::New(chars, len, NULL, NULL, Heap::kNew)); |
71 | 71 |
72 const String& pat = String::Handle(String::New("bc")); | 72 const String& pat = String::Handle(String::New("bc")); |
73 const Array& res = Array::Handle(Match(pat, str)); | 73 const Array& res = Array::Handle(Match(pat, str)); |
74 EXPECT_EQ(2, res.Length()); | 74 EXPECT_EQ(2, res.Length()); |
75 | 75 |
76 const Object& res_1 = Object::Handle(res.At(0)); | 76 const Object& res_1 = Object::Handle(res.At(0)); |
77 const Object& res_2 = Object::Handle(res.At(1)); | 77 const Object& res_2 = Object::Handle(res.At(1)); |
78 EXPECT(res_1.IsSmi()); | 78 EXPECT(res_1.IsSmi()); |
79 EXPECT(res_2.IsSmi()); | 79 EXPECT(res_2.IsSmi()); |
80 | 80 |
81 const Smi& smi_1 = Smi::Cast(res_1); | 81 const Smi& smi_1 = Smi::Cast(res_1); |
82 const Smi& smi_2 = Smi::Cast(res_2); | 82 const Smi& smi_2 = Smi::Cast(res_2); |
83 EXPECT_EQ(1, smi_1.Value()); | 83 EXPECT_EQ(1, smi_1.Value()); |
84 EXPECT_EQ(3, smi_2.Value()); | 84 EXPECT_EQ(3, smi_2.Value()); |
85 } | 85 } |
86 | 86 |
87 TEST_CASE(RegExp_ExternalTwoByteString) { | 87 TEST_CASE(RegExp_ExternalTwoByteString) { |
88 uint16_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; | 88 uint16_t chars[] = {'a', 'b', 'c', 'b', 'a'}; |
89 intptr_t len = ARRAY_SIZE(chars); | 89 intptr_t len = ARRAY_SIZE(chars); |
90 const String& str = String::Handle( | 90 const String& str = String::Handle( |
91 ExternalTwoByteString::New(chars, len, NULL, NULL, Heap::kNew)); | 91 ExternalTwoByteString::New(chars, len, NULL, NULL, Heap::kNew)); |
92 | 92 |
93 const String& pat = String::Handle(String::New("bc")); | 93 const String& pat = String::Handle(String::New("bc")); |
94 const Array& res = Array::Handle(Match(pat, str)); | 94 const Array& res = Array::Handle(Match(pat, str)); |
95 EXPECT_EQ(2, res.Length()); | 95 EXPECT_EQ(2, res.Length()); |
96 | 96 |
97 const Object& res_1 = Object::Handle(res.At(0)); | 97 const Object& res_1 = Object::Handle(res.At(0)); |
98 const Object& res_2 = Object::Handle(res.At(1)); | 98 const Object& res_2 = Object::Handle(res.At(1)); |
99 EXPECT(res_1.IsSmi()); | 99 EXPECT(res_1.IsSmi()); |
100 EXPECT(res_2.IsSmi()); | 100 EXPECT(res_2.IsSmi()); |
101 | 101 |
102 const Smi& smi_1 = Smi::Cast(res_1); | 102 const Smi& smi_1 = Smi::Cast(res_1); |
103 const Smi& smi_2 = Smi::Cast(res_2); | 103 const Smi& smi_2 = Smi::Cast(res_2); |
104 EXPECT_EQ(1, smi_1.Value()); | 104 EXPECT_EQ(1, smi_1.Value()); |
105 EXPECT_EQ(3, smi_2.Value()); | 105 EXPECT_EQ(3, smi_2.Value()); |
106 } | 106 } |
107 | 107 |
108 } // namespace dart | 108 } // namespace dart |
OLD | NEW |