51 lines · cpp
1//===- span-test.cpp ------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// Tests orc-rt's span implementation.10//11//===----------------------------------------------------------------------===//12 13#include "orc-rt/span.h"14#include "gtest/gtest.h"15 16#include <sstream>17#include <string>18 19using namespace orc_rt;20 21TEST(SpanTest, SpanDefaultConstruction) {22 span<int> S;23 EXPECT_TRUE(S.empty()) << "Default constructed span not empty";24 EXPECT_EQ(S.size(), 0U) << "Default constructed span size not zero";25 EXPECT_EQ(S.begin(), S.end()) << "Default constructed span begin != end";26}27 28TEST(SpanTest, SpanConstructFromFixedArray) {29 int A[] = {1, 2, 3, 4, 5};30 span<int> S(A);31 EXPECT_FALSE(S.empty()) << "Span should be non-empty";32 EXPECT_EQ(S.size(), 5U) << "Span has unexpected size";33 EXPECT_EQ(std::distance(S.begin(), S.end()), 5U)34 << "Unexpected iterator range size";35 EXPECT_EQ(S.data(), &A[0]) << "Span data has unexpected value";36 for (unsigned I = 0; I != S.size(); ++I)37 EXPECT_EQ(S[I], A[I]) << "Unexpected span element value";38}39 40TEST(SpanTest, SpanConstructFromIteratorAndSize) {41 int A[] = {1, 2, 3, 4, 5};42 span<int> S(&A[0], 5);43 EXPECT_FALSE(S.empty()) << "Span should be non-empty";44 EXPECT_EQ(S.size(), 5U) << "Span has unexpected size";45 EXPECT_EQ(std::distance(S.begin(), S.end()), 5U)46 << "Unexpected iterator range size";47 EXPECT_EQ(S.data(), &A[0]) << "Span data has unexpected value";48 for (unsigned I = 0; I != S.size(); ++I)49 EXPECT_EQ(S[I], A[I]) << "Unexpected span element value";50}51