diff options
author | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-03-04 23:16:59 -0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-05 11:30:13 +0100 |
commit | fc5b252010aeb6155d22e752914b8b9e371c5398 (patch) | |
tree | 91a0b8d67cdb6ab093a22f9a64e9d6390c85ac57 /AK/Tests | |
parent | 17e7cdc6cc906831f8253fdffae59c02b2513dca (diff) | |
download | serenity-fc5b252010aeb6155d22e752914b8b9e371c5398.zip |
AK: Implement IsEnum<T> and UnderlyingType<T> type traits
I needed these meta-programming type traits while working on something else.
Add basic support for these two type traits as well as some tests.
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/TestTypeTraits.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/AK/Tests/TestTypeTraits.cpp b/AK/Tests/TestTypeTraits.cpp index 184dabcdc1..c00e6e617e 100644 --- a/AK/Tests/TestTypeTraits.cpp +++ b/AK/Tests/TestTypeTraits.cpp @@ -55,6 +55,10 @@ struct Empty { }; +enum class Enummer : u8 { + Dummmy, +}; + TEST_CASE(FundamentalTypeClassification) { EXPECT_TRAIT_TRUE(IsVoid, void); @@ -89,6 +93,12 @@ TEST_CASE(FundamentalTypeClassification) EXPECT_TRAIT_FALSE(IsUnsigned, short); EXPECT_TRAIT_FALSE(IsUnsigned, char); EXPECT_TRAIT_FALSE(IsUnsigned, long); + + EXPECT_TRAIT_TRUE(IsEnum, Enummer); + EXPECT_TRAIT_FALSE(IsEnum, Empty); + EXPECT_TRAIT_FALSE(IsEnum, int); + EXPECT_TRAIT_FALSE(IsEnum, void); + EXPECT_TRAIT_FALSE(IsEnum, std::nullptr_t); } TEST_CASE(AddConst) @@ -101,4 +111,11 @@ TEST_CASE(AddConst) EXPECT_EQ_WITH_TRAIT(AddConst, NoConstList, YesConstList); } +TEST_CASE(UnderlyingType) +{ + using Type = UnderlyingType<Enummer>::Type; + + STATIC_EXPECT_EQ(Type, u8); +} + TEST_MAIN(TypeTraits) |