|
| 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-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "gtest/gtest.h" |
| 10 | +#include "flang-rt/runtime/type-code.h" |
| 11 | + |
| 12 | +using namespace Fortran::runtime; |
| 13 | +using namespace Fortran::common; |
| 14 | + |
| 15 | +TEST(TypeCode, ComplexTypes) { |
| 16 | + // Test all Complex type kinds to ensure they map correctly |
| 17 | + 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 | +} |
0 commit comments