| 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 Zone* zone = Thread::Current()->zone(); | 16 Zone* zone = Thread::Current()->zone(); |
| 17 const JSRegExp& regexp = JSRegExp::Handle( | 17 const JSRegExp& regexp = JSRegExp::Handle( |
| 18 RegExpEngine::CreateJSRegExp(zone, pat, false, false)); | 18 RegExpEngine::CreateJSRegExp(zone, pat, false, false)); |
| 19 const intptr_t cid = str.GetClassId(); | |
| 20 const Function& fn = Function::Handle(regexp.function(cid)); | |
| 21 EXPECT(!fn.IsNull()); | |
| 22 const Smi& idx = Smi::Handle(Smi::New(0)); | 19 const Smi& idx = Smi::Handle(Smi::New(0)); |
| 23 return IRRegExpMacroAssembler::Execute(fn, str, idx, zone); | 20 return IRRegExpMacroAssembler::Execute(regexp, str, idx, zone); |
| 24 } | 21 } |
| 25 | 22 |
| 26 TEST_CASE(RegExp_OneByteString) { | 23 TEST_CASE(RegExp_OneByteString) { |
| 27 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; | 24 uint8_t chars[] = { 'a', 'b', 'c', 'b', 'a' }; |
| 28 intptr_t len = ARRAY_SIZE(chars); | 25 intptr_t len = ARRAY_SIZE(chars); |
| 29 const String& str = String::Handle( | 26 const String& str = String::Handle( |
| 30 OneByteString::New(chars, len, Heap::kNew)); | 27 OneByteString::New(chars, len, Heap::kNew)); |
| 31 | 28 |
| 32 const String& pat = String::Handle(String::New("bc")); | 29 const String& pat = String::Handle(String::New("bc")); |
| 33 const Array& res = Array::Handle(Match(pat, str)); | 30 const Array& res = Array::Handle(Match(pat, str)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 EXPECT(res_1.IsSmi()); | 98 EXPECT(res_1.IsSmi()); |
| 102 EXPECT(res_2.IsSmi()); | 99 EXPECT(res_2.IsSmi()); |
| 103 | 100 |
| 104 const Smi& smi_1 = Smi::Cast(res_1); | 101 const Smi& smi_1 = Smi::Cast(res_1); |
| 105 const Smi& smi_2 = Smi::Cast(res_2); | 102 const Smi& smi_2 = Smi::Cast(res_2); |
| 106 EXPECT_EQ(1, smi_1.Value()); | 103 EXPECT_EQ(1, smi_1.Value()); |
| 107 EXPECT_EQ(3, smi_2.Value()); | 104 EXPECT_EQ(3, smi_2.Value()); |
| 108 } | 105 } |
| 109 | 106 |
| 110 } // namespace dart | 107 } // namespace dart |
| OLD | NEW |