2019-12-02 12:23:10 +01:00
|
|
|
#include <catch2/catch_enum_values_registry.h>
|
2020-02-20 13:57:24 +01:00
|
|
|
#include <catch2/matchers/catch_matchers_vector.h>
|
2020-01-20 23:24:04 +01:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2019-04-25 11:13:11 +02:00
|
|
|
|
|
|
|
enum class EnumClass3 { Value1, Value2, Value3, Value4 };
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE( "parseEnums", "[Strings][enums]" ) {
|
|
|
|
using namespace Catch::Matchers;
|
|
|
|
using Catch::Detail::parseEnums;
|
|
|
|
|
|
|
|
SECTION( "No enums" )
|
2019-09-08 14:07:18 +02:00
|
|
|
CHECK_THAT( parseEnums( "" ), Equals( std::vector<Catch::StringRef>{} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
|
|
|
|
SECTION( "One enum value" ) {
|
|
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ),
|
2019-09-08 14:07:18 +02:00
|
|
|
Equals(std::vector<Catch::StringRef>{"Value1"} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
CHECK_THAT( parseEnums( "Value1" ),
|
2019-09-08 14:07:18 +02:00
|
|
|
Equals( std::vector<Catch::StringRef>{"Value1"} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
CHECK_THAT( parseEnums( "EnumName::Value1" ),
|
2019-09-08 14:07:18 +02:00
|
|
|
Equals(std::vector<Catch::StringRef>{"Value1"} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION( "Multiple enum values" ) {
|
|
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ),
|
2019-09-08 14:07:18 +02:00
|
|
|
Equals( std::vector<Catch::StringRef>{"Value1", "Value2"} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ),
|
2019-09-08 14:07:18 +02:00
|
|
|
Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ),
|
2019-09-08 14:07:18 +02:00
|
|
|
Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) );
|
2019-04-25 11:13:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "Directly creating an EnumInfo" ) {
|
|
|
|
|
|
|
|
using namespace Catch::Detail;
|
|
|
|
std::unique_ptr<EnumInfo> 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 **}" );
|
|
|
|
}
|