diff options
| author | Phil nash | 2019-04-25 10:13:11 +0100 |
|---|---|---|
| committer | Phil nash | 2019-04-25 10:13:11 +0100 |
| commit | f2ee4f17ad7040160eea73b326d431b4112ad25b (patch) | |
| tree | 3d0f0da892d54d746eb7a890daa3f07438659d77 /projects/SelfTest/IntrospectiveTests/ToString.tests.cpp | |
| parent | e02d9e788fe201094ed365a140a8beb39cfb97c5 (diff) | |
| download | catch3-f2ee4f17ad7040160eea73b326d431b4112ad25b.tar.gz | |
Moved enum tests that depend on internals to IntrospectiveTests.
- also factored out makeEnumInfo, so tests don't need to touch registry
- and added usage test that involves namespace
Diffstat (limited to 'projects/SelfTest/IntrospectiveTests/ToString.tests.cpp')
| -rw-r--r-- | projects/SelfTest/IntrospectiveTests/ToString.tests.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/projects/SelfTest/IntrospectiveTests/ToString.tests.cpp b/projects/SelfTest/IntrospectiveTests/ToString.tests.cpp new file mode 100644 index 00000000..fc0e2a4f --- /dev/null +++ b/projects/SelfTest/IntrospectiveTests/ToString.tests.cpp @@ -0,0 +1,42 @@ +#include "catch.hpp" + +#include "internal/catch_enum_values_registry.h" + +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<std::string>{} ) ); + + SECTION( "One enum value" ) { + CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ), + Equals(std::vector<std::string>{"Value1"} ) ); + CHECK_THAT( parseEnums( "Value1" ), + Equals( std::vector<std::string>{"Value1"} ) ); + CHECK_THAT( parseEnums( "EnumName::Value1" ), + Equals(std::vector<std::string>{"Value1"} ) ); + } + + SECTION( "Multiple enum values" ) { + CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ), + Equals( std::vector<std::string>{"Value1", "Value2"} ) ); + CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ), + Equals( std::vector<std::string>{"Value1", "Value2", "Value3"} ) ); + CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ), + Equals( std::vector<std::string>{"Value1", "Value2", "Value3"} ) ); + } +} + +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 **}" ); +} |