Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / __support / CPP / cstddef_test.cpp
blob8337081345a02d6da5209eeeff3bf0fea44d1038
1 //===-- Unittests for byte ------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "src/__support/CPP/cstddef.h"
10 #include "test/UnitTest/Test.h"
12 namespace LIBC_NAMESPACE::cpp {
14 TEST(LlvmLibcByteTest, to_integer) {
15 const char str[] = "abc";
16 const byte *const ptr = reinterpret_cast<const byte *>(str);
17 ASSERT_EQ(to_integer<char>(ptr[0]), 'a');
18 ASSERT_EQ(to_integer<char>(ptr[1]), 'b');
19 ASSERT_EQ(to_integer<char>(ptr[2]), 'c');
20 ASSERT_EQ(to_integer<char>(ptr[3]), '\0');
23 TEST(LlvmLibcByteTest, bitwise) {
24 byte b{42};
25 ASSERT_EQ(b, byte{0b00101010});
27 b <<= 1;
28 ASSERT_EQ(b, byte{0b01010100});
29 b >>= 1;
31 ASSERT_EQ((b << 1), byte{0b01010100});
32 ASSERT_EQ((b >> 1), byte{0b00010101});
34 b |= byte{0b11110000};
35 ASSERT_EQ(b, byte{0b11111010});
37 b &= byte{0b11110000};
38 ASSERT_EQ(b, byte{0b11110000});
40 b ^= byte{0b11111111};
41 ASSERT_EQ(b, byte{0b00001111});
44 } // namespace LIBC_NAMESPACE::cpp