1 | //===-- Unittests for Limits ----------------------------------------------===// |
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 "src/__support/CPP/limits.h" |
10 | #include "src/__support/big_int.h" |
11 | #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 |
12 | #include "test/UnitTest/Test.h" |
13 | |
14 | namespace LIBC_NAMESPACE { |
15 | |
16 | // This just checks against the C spec, almost all implementations will surpass |
17 | // this. |
18 | TEST(LlvmLibcLimitsTest, LimitsFollowSpec) { |
19 | ASSERT_EQ(cpp::numeric_limits<int>::max(), INT_MAX); |
20 | ASSERT_EQ(cpp::numeric_limits<int>::min(), INT_MIN); |
21 | |
22 | ASSERT_EQ(cpp::numeric_limits<unsigned int>::max(), UINT_MAX); |
23 | |
24 | ASSERT_EQ(cpp::numeric_limits<long>::max(), LONG_MAX); |
25 | ASSERT_EQ(cpp::numeric_limits<long>::min(), LONG_MIN); |
26 | |
27 | ASSERT_EQ(cpp::numeric_limits<unsigned long>::max(), ULONG_MAX); |
28 | |
29 | ASSERT_EQ(cpp::numeric_limits<long long>::max(), LLONG_MAX); |
30 | ASSERT_EQ(cpp::numeric_limits<long long>::min(), LLONG_MIN); |
31 | |
32 | ASSERT_EQ(cpp::numeric_limits<unsigned long long>::max(), ULLONG_MAX); |
33 | } |
34 | |
35 | TEST(LlvmLibcLimitsTest, UInt128Limits) { |
36 | auto umax128 = cpp::numeric_limits<LIBC_NAMESPACE::UInt<128>>::max(); |
37 | auto umax64 = LIBC_NAMESPACE::UInt<128>(cpp::numeric_limits<uint64_t>::max()); |
38 | EXPECT_GT(umax128, umax64); |
39 | ASSERT_EQ(~LIBC_NAMESPACE::UInt<128>(0), umax128); |
40 | #ifdef LIBC_TYPES_HAS_INT128 |
41 | ASSERT_EQ(~__uint128_t(0), cpp::numeric_limits<__uint128_t>::max()); |
42 | #endif // LIBC_TYPES_HAS_INT128 |
43 | } |
44 | |
45 | } // namespace LIBC_NAMESPACE |
46 | |