Commit 80e5e2b4 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[base][vector] Test constexpr factories

Test some constexpr factories. StaticCharVector is not actually
constexpr, this will be fixed in a follow-up CL.

R=leszeks@chromium.org

Bug: v8:10426
Change-Id: I16fdf79cd7d4b3f54d7cf73e15bdff2306810f06
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2154192
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67210}
parent f11fcde5
......@@ -21,6 +21,10 @@ namespace internal {
template <typename T>
class Vector {
public:
using value_type = T;
using iterator = T*;
using const_iterator = const T*;
constexpr Vector() : start_(nullptr), length_(0) {}
constexpr Vector(T* data, size_t length) : start_(data), length_(length) {
......
......@@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include "src/utils/utils.h"
#include "testing/gmock-support.h"
#include "testing/gtest-support.h"
namespace v8 {
......@@ -73,5 +76,24 @@ TEST(OwnedVectorConstruction, Equals) {
EXPECT_EQ(init_vec1.as_vector(), init_vec2.as_vector());
}
// Test that the constexpr factory methods work.
TEST(VectorTest, ConstexprFactories) {
static constexpr int kInit1[] = {4, 11, 3};
static constexpr auto kVec1 = ArrayVector(kInit1);
STATIC_ASSERT(kVec1.size() == 3);
EXPECT_THAT(kVec1, testing::ElementsAreArray(kInit1));
static constexpr auto kVec2 = VectorOf(kInit1, 2);
STATIC_ASSERT(kVec2.size() == 2);
EXPECT_THAT(kVec2, testing::ElementsAre(4, 11));
// TODO(clemensb): Use StaticCharVector.
static constexpr const char kInit3[] = "foobar";
static constexpr auto kVec3 =
VectorOf(kInit3, 6); // StaticCharVector(kInit3);
STATIC_ASSERT(kVec3.size() == 6);
EXPECT_THAT(kVec3, testing::ElementsAreArray(kInit3, kInit3 + 6));
}
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment