brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 5e69405 Raw
44 lines · cpp
1//===-- unittests/Runtime/TypeCode.cpp --------------------------*- C++ -*-===//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 "gtest/gtest.h"10#include "flang-rt/runtime/type-code.h"11 12using namespace Fortran::runtime;13using namespace Fortran::common;14 15TEST(TypeCode, ComplexTypes) {16  // Test all Complex type kinds to ensure they map correctly17  struct ComplexTypeMapping {18    int kind;19    Fortran::ISO::CFI_type_t expectedType;20  };21 22  ComplexTypeMapping mappings[] = {23      {2, CFI_type_half_float_Complex},24      {3, CFI_type_bfloat_Complex},25      {4, CFI_type_float_Complex},26      {8, CFI_type_double_Complex},27      {10, CFI_type_extended_double_Complex},28      {16, CFI_type_float128_Complex},29  };30 31  for (const auto &mapping : mappings) {32    TypeCode tc(TypeCategory::Complex, mapping.kind);33    EXPECT_EQ(tc.raw(), mapping.expectedType)34        << "Complex kind " << mapping.kind << " should map to CFI type "35        << mapping.expectedType;36    EXPECT_TRUE(tc.IsComplex());37 38    auto categoryAndKind = tc.GetCategoryAndKind();39    ASSERT_TRUE(categoryAndKind.has_value());40    EXPECT_EQ(categoryAndKind->first, TypeCategory::Complex);41    EXPECT_EQ(categoryAndKind->second, mapping.kind);42  }43}44