brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 0b05ae4 Raw
72 lines · cpp
1//===-- Unittests for cpp::tuple ------------------------------------------===//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#include "src/__support/CPP/tuple.h"10#include <stddef.h>11 12#include "test/UnitTest/FPMatcher.h"13#include "test/UnitTest/Test.h"14 15using namespace LIBC_NAMESPACE::cpp;16 17TEST(LlvmLibcTupleTest, Construction) {18  tuple<int, double> t(42, 3.14);19  EXPECT_EQ(get<0>(t), 42);20  EXPECT_FP_EQ(get<1>(t), 3.14);21}22 23TEST(LlvmLibcTupleTest, MakeTuple) {24  auto t = make_tuple(1, 2.5, 'x');25  EXPECT_EQ(get<0>(t), 1);26  EXPECT_FP_EQ(get<1>(t), 2.5);27  EXPECT_EQ(get<2>(t), 'x');28}29 30TEST(LlvmLibcTupleTest, TieAssignment) {31  int a = 0;32  double b = 0;33  char c = 0;34  auto t = make_tuple(7, 8.5, 'y');35  tie(a, b, c) = t;36  EXPECT_EQ(a, 7);37  EXPECT_FP_EQ(b, 8.5);38  EXPECT_EQ(c, 'y');39}40 41TEST(LlvmLibcTupleTest, StructuredBindings) {42  auto t = make_tuple(7, 8.5, 'y');43  auto [x, y, z] = t;44  EXPECT_EQ(x, 7);45  EXPECT_FP_EQ(y, 8.5);46  EXPECT_EQ(z, 'y');47}48 49TEST(LlvmLibcTupleTest, TupleCat) {50  tuple<int, double> t(42, 3.14);51  auto t1 = make_tuple(1, 2.5, 'x');52  auto t2 = tuple_cat(t, t1);53  EXPECT_EQ(get<0>(t2), 42);54  EXPECT_FP_EQ(get<1>(t2), 3.14);55  EXPECT_EQ(get<2>(t2), 1);56  EXPECT_FP_EQ(get<3>(t2), 2.5);57  EXPECT_EQ(get<4>(t2), 'x');58}59 60TEST(LlvmLibcTupleTest, ConstTuple) {61  const auto t = make_tuple(100, 200.5);62  EXPECT_EQ(get<0>(t), 100);63  EXPECT_FP_EQ(get<1>(t), 200.5);64}65 66TEST(LlvmLibcTupleTest, RvalueAssignment) {67  auto t = make_tuple(0, 0.0);68  t = make_tuple(9, 9.5);69  EXPECT_EQ(get<0>(t), 9);70  EXPECT_FP_EQ(get<1>(t), 9.5);71}72