Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
regexp_test.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6
7#include "vm/isolate.h"
8#include "vm/object.h"
9#include "vm/regexp.h"
11#include "vm/unit_test.h"
12
13namespace dart {
14
15static ArrayPtr Match(const String& pat, const String& str) {
16 Thread* thread = Thread::Current();
17 Zone* zone = thread->zone();
18 const RegExp& regexp =
20 const Smi& idx = Object::smi_zero();
21 return IRRegExpMacroAssembler::Execute(regexp, str, idx, /*sticky=*/false,
22 zone);
23}
24
25ISOLATE_UNIT_TEST_CASE(RegExp_OneByteString) {
26 uint8_t chars[] = {'a', 'b', 'c', 'b', 'a'};
27 intptr_t len = ARRAY_SIZE(chars);
28 const String& str =
30
31 const String& pat =
33 const Array& res = Array::Handle(Match(pat, str));
34 EXPECT_EQ(2, res.Length());
35
36 const Object& res_1 = Object::Handle(res.At(0));
37 const Object& res_2 = Object::Handle(res.At(1));
38 EXPECT(res_1.IsSmi());
39 EXPECT(res_2.IsSmi());
40
41 const Smi& smi_1 = Smi::Cast(res_1);
42 const Smi& smi_2 = Smi::Cast(res_2);
43 EXPECT_EQ(1, smi_1.Value());
44 EXPECT_EQ(3, smi_2.Value());
45}
46
47ISOLATE_UNIT_TEST_CASE(RegExp_TwoByteString) {
48 uint16_t chars[] = {'a', 'b', 'c', 'b', 'a'};
49 intptr_t len = ARRAY_SIZE(chars);
50 const String& str =
52
53 const String& pat =
55 const Array& res = Array::Handle(Match(pat, str));
56 EXPECT_EQ(2, res.Length());
57
58 const Object& res_1 = Object::Handle(res.At(0));
59 const Object& res_2 = Object::Handle(res.At(1));
60 EXPECT(res_1.IsSmi());
61 EXPECT(res_2.IsSmi());
62
63 const Smi& smi_1 = Smi::Cast(res_1);
64 const Smi& smi_2 = Smi::Cast(res_2);
65 EXPECT_EQ(1, smi_1.Value());
66 EXPECT_EQ(3, smi_2.Value());
67}
68
69} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
ObjectPtr At(intptr_t index) const
Definition object.h:10854
intptr_t Length() const
Definition object.h:10808
@ kNew
Definition heap.h:38
static ArrayPtr Execute(const RegExp &regexp, const String &input, const Smi &start_offset, bool sticky, Zone *zone)
static Object & Handle()
Definition object.h:407
static OneByteStringPtr New(intptr_t len, Heap::Space space)
Definition object.cc:24447
static RegExpPtr CreateRegExp(Thread *thread, const String &pattern, RegExpFlags flags)
Definition regexp.cc:5573
intptr_t Value() const
Definition object.h:9969
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition object.cc:23777
static StringPtr New(Thread *thread, const char *cstr)
Definition symbols.h:722
Zone * zone() const
static Thread * Current()
Definition thread.h:361
static TwoByteStringPtr New(intptr_t len, Heap::Space space)
Definition object.cc:24641
static ArrayPtr Match(const String &pat, const String &str)
#define ISOLATE_UNIT_TEST_CASE(name)
Definition unit_test.h:64
#define ARRAY_SIZE(array)
Definition globals.h:72