Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
kernel_test.cc
Go to the documentation of this file.
1
// Copyright (c) 2022, 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 <type_traits>
6
7
#include "
platform/globals.h
"
8
9
#include "
vm/kernel.h
"
10
#include "
vm/object.h
"
11
#include "
vm/unit_test.h
"
12
13
namespace
dart
{
14
15
const
dart::TypedData
&
CreateLineStartsData
() {
16
const
intptr_t raw_line_starts_data[] = {
17
0, 8, 12, 17, 18, 20, 23, 30, 31, 33,
18
};
19
const
intptr_t
length
= std::extent<
decltype
(raw_line_starts_data)>::value;
20
ASSERT
(
length
> 0);
21
const
TypedData
& line_starts_data =
TypedData::Handle
(
22
TypedData::New
(kTypedDataUint16ArrayCid,
length
,
Heap::kOld
));
23
for
(intptr_t i = 0; i <
length
; ++i) {
24
line_starts_data.SetUint16(i << 1,
25
static_cast<
int16_t
>
(raw_line_starts_data[i]));
26
}
27
return
line_starts_data;
28
}
29
30
ISOLATE_UNIT_TEST_CASE
(KernelLineStartsReader_MaxPosition) {
31
kernel::KernelLineStartsReader reader(
CreateLineStartsData
(), thread->zone());
32
EXPECT_EQ(33u, reader.MaxPosition());
33
}
34
35
void
ExpectLocationForPosition
(
const
kernel::KernelLineStartsReader& reader,
36
intptr_t position,
37
intptr_t expected_line,
38
intptr_t expected_col) {
39
intptr_t line;
40
intptr_t col;
41
EXPECT_EQ(
true
, reader.LocationForPosition(position, &line, &col));
42
EXPECT_EQ(expected_line, line);
43
EXPECT_EQ(expected_col, col);
44
}
45
46
ISOLATE_UNIT_TEST_CASE
(KernelLineStartsReader_LocationForPosition) {
47
kernel::KernelLineStartsReader reader(
CreateLineStartsData
(), thread->zone());
48
ExpectLocationForPosition
(reader, 0, 1, 1);
49
ExpectLocationForPosition
(reader, 4, 1, 5);
50
ExpectLocationForPosition
(reader, 8, 2, 1);
51
ExpectLocationForPosition
(reader, 14, 3, 3);
52
ExpectLocationForPosition
(reader, 17, 4, 1);
53
ExpectLocationForPosition
(reader, 19, 5, 2);
54
ExpectLocationForPosition
(reader, 22, 6, 3);
55
ExpectLocationForPosition
(reader, 29, 7, 7);
56
ExpectLocationForPosition
(reader, 30, 8, 1);
57
ExpectLocationForPosition
(reader, 32, 9, 2);
58
ExpectLocationForPosition
(reader, 33, 10, 1);
59
60
intptr_t line;
61
intptr_t col;
62
EXPECT_EQ(
false
, reader.LocationForPosition(-1, &line, &col));
63
EXPECT_EQ(
false
, reader.LocationForPosition(34, &line, &col));
64
}
65
66
void
ExpectTokenRangeAtLine
(
const
kernel::KernelLineStartsReader& reader,
67
intptr_t line,
68
intptr_t expected_first_token,
69
intptr_t expected_last_token) {
70
TokenPosition
first_token =
TokenPosition::Synthetic
(0);
71
TokenPosition
last_token =
TokenPosition::Synthetic
(0);
72
EXPECT_EQ(
true
, reader.TokenRangeAtLine(line, &first_token, &last_token));
73
EXPECT_EQ(expected_first_token, first_token.
Serialize
());
74
EXPECT_EQ(expected_last_token, last_token.
Serialize
());
75
}
76
77
ISOLATE_UNIT_TEST_CASE
(KernelLineStartsReader_TokenRangeAtLine) {
78
kernel::KernelLineStartsReader reader(
CreateLineStartsData
(), thread->zone());
79
ExpectTokenRangeAtLine
(reader, 1, 0, 7);
80
ExpectTokenRangeAtLine
(reader, 2, 8, 11);
81
ExpectTokenRangeAtLine
(reader, 3, 12, 16);
82
ExpectTokenRangeAtLine
(reader, 4, 17, 17);
83
ExpectTokenRangeAtLine
(reader, 5, 18, 19);
84
ExpectTokenRangeAtLine
(reader, 6, 20, 22);
85
ExpectTokenRangeAtLine
(reader, 7, 23, 29);
86
ExpectTokenRangeAtLine
(reader, 8, 30, 30);
87
ExpectTokenRangeAtLine
(reader, 9, 31, 32);
88
ExpectTokenRangeAtLine
(reader, 10, 33, 33);
89
90
TokenPosition
first_token =
TokenPosition::Synthetic
(0);
91
TokenPosition
last_token =
TokenPosition::Synthetic
(0);
92
EXPECT_EQ(
false
, reader.TokenRangeAtLine(0, &first_token, &last_token));
93
EXPECT_EQ(
false
, reader.TokenRangeAtLine(11, &first_token, &last_token));
94
}
95
96
}
// namespace dart
dart::Heap::kOld
@ kOld
Definition
heap.h:39
dart::Object::Handle
static Object & Handle()
Definition
object.h:407
dart::TokenPosition
Definition
token_position.h:62
dart::TokenPosition::Synthetic
static TokenPosition Synthetic(intptr_t value)
Definition
token_position.h:200
dart::TokenPosition::Serialize
int32_t Serialize() const
Definition
token_position.cc:20
dart::TypedData
Definition
object.h:11608
dart::TypedData::New
static TypedDataPtr New(intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
Definition
object.cc:25666
ASSERT
#define ASSERT(E)
Definition
entrypoints_verification_test.cc:25
kernel.h
length
size_t length
Definition
key_event_handler.cc:41
dart
Definition
dart_vm.cc:33
dart::ExpectTokenRangeAtLine
void ExpectTokenRangeAtLine(const kernel::KernelLineStartsReader &reader, intptr_t line, intptr_t expected_first_token, intptr_t expected_last_token)
Definition
kernel_test.cc:66
dart::CreateLineStartsData
const dart::TypedData & CreateLineStartsData()
Definition
kernel_test.cc:15
dart::ExpectLocationForPosition
void ExpectLocationForPosition(const kernel::KernelLineStartsReader &reader, intptr_t position, intptr_t expected_line, intptr_t expected_col)
Definition
kernel_test.cc:35
object.h
globals.h
unit_test.h
ISOLATE_UNIT_TEST_CASE
#define ISOLATE_UNIT_TEST_CASE(name)
Definition
unit_test.h:64
Generated on Fri Apr 26 2024 06:15:10 for Flutter Engine by
1.9.8