mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-14 09:49:54 +01:00
1d1ccf8f3c
Doing some benchmarking with ClangBuildAnalyzer suggests that compiling Catch2's `SelfTest` spends 10% of the time instantiating `std::unique_ptr` for some interface types required for registering and running tests. The lesser compilation overhead of `Catch::Detail::unique_ptr` should significantly reduce that time. The compiled implementation was also changed to use the custom impl, to avoid having to convert between using `std::unique_ptr` and `Catch::Detail::unique_ptr`. This will likely also improve the compile times of the implementation, but that is less important than improving compilation times of the user's TUs with tests.
43 lines
1.8 KiB
C++
43 lines
1.8 KiB
C++
#include <catch2/internal/catch_enum_values_registry.hpp>
|
|
#include <catch2/matchers/catch_matchers_vector.hpp>
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
enum class EnumClass3 { Value1, Value2, Value3, Value4 };
|
|
|
|
|
|
TEST_CASE( "parseEnums", "[Strings][enums]" ) {
|
|
using namespace Catch::Matchers;
|
|
using Catch::Detail::parseEnums;
|
|
|
|
SECTION( "No enums" )
|
|
CHECK_THAT( parseEnums( "" ), Equals( std::vector<Catch::StringRef>{} ) );
|
|
|
|
SECTION( "One enum value" ) {
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ),
|
|
Equals(std::vector<Catch::StringRef>{"Value1"} ) );
|
|
CHECK_THAT( parseEnums( "Value1" ),
|
|
Equals( std::vector<Catch::StringRef>{"Value1"} ) );
|
|
CHECK_THAT( parseEnums( "EnumName::Value1" ),
|
|
Equals(std::vector<Catch::StringRef>{"Value1"} ) );
|
|
}
|
|
|
|
SECTION( "Multiple enum values" ) {
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ),
|
|
Equals( std::vector<Catch::StringRef>{"Value1", "Value2"} ) );
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ),
|
|
Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) );
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ),
|
|
Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) );
|
|
}
|
|
}
|
|
|
|
TEST_CASE( "Directly creating an EnumInfo" ) {
|
|
|
|
using namespace Catch::Detail;
|
|
auto enumInfo = makeEnumInfo( "EnumName", "EnumName::Value1, EnumName::Value2", {0, 1} );
|
|
|
|
CHECK( enumInfo->lookup(0) == "Value1" );
|
|
CHECK( enumInfo->lookup(1) == "Value2" );
|
|
CHECK( enumInfo->lookup(3) == "{** unexpected enum value **}" );
|
|
}
|