test-array-list.cc 1.33 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stdlib.h>

7
#include "src/heap/factory.h"
8
#include "src/objects/objects-inl.h"
9 10
#include "test/cctest/cctest.h"

11 12
namespace v8 {
namespace internal {
13 14 15 16 17

TEST(ArrayList) {
  LocalContext context;
  Isolate* isolate = CcTest::i_isolate();
  HandleScope scope(isolate);
18 19
  Handle<ArrayList> array(
      ArrayList::cast(ReadOnlyRoots(isolate).empty_fixed_array()), isolate);
20
  CHECK_EQ(0, array->Length());
21
  array = ArrayList::Add(isolate, array, handle(Smi::FromInt(100), isolate));
22
  CHECK_EQ(1, array->Length());
jgruber's avatar
jgruber committed
23
  CHECK_EQ(100, Smi::ToInt(array->Get(0)));
24
  array = ArrayList::Add(isolate, array, handle(Smi::FromInt(200), isolate),
25 26
                         handle(Smi::FromInt(300), isolate));
  CHECK_EQ(3, array->Length());
jgruber's avatar
jgruber committed
27 28 29
  CHECK_EQ(100, Smi::ToInt(array->Get(0)));
  CHECK_EQ(200, Smi::ToInt(array->Get(1)));
  CHECK_EQ(300, Smi::ToInt(array->Get(2)));
30
  array->Set(2, Smi::FromInt(400));
jgruber's avatar
jgruber committed
31
  CHECK_EQ(400, Smi::ToInt(array->Get(2)));
32
  array->Clear(2, ReadOnlyRoots(isolate).undefined_value());
33 34
  array->SetLength(2);
  CHECK_EQ(2, array->Length());
jgruber's avatar
jgruber committed
35 36
  CHECK_EQ(100, Smi::ToInt(array->Get(0)));
  CHECK_EQ(200, Smi::ToInt(array->Get(1)));
37
}
38

39 40
}  // namespace internal
}  // namespace v8