diff options
| author | Martin Hořeňovský | 2020-02-13 15:01:03 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-13 15:01:03 +0100 |
| commit | 2945b80f61b8ad5b7e05c36fadcac8a35b0e3a8f (patch) | |
| tree | f077b74334a42d08fa775a9f54ceef6cf7ddb837 /tests/SelfTest/IntrospectiveTests/String.tests.cpp | |
| parent | 63b7d6f98ea5a86c0cc14e094bb66f704eaddfd1 (diff) | |
| download | catch3-2945b80f61b8ad5b7e05c36fadcac8a35b0e3a8f.tar.gz | |
Add more constexpr to StringRef
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/String.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/String.tests.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp index 6b94cdc8..b7f4a2dd 100644 --- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp @@ -72,7 +72,9 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { ss = s.substr(6, 123); REQUIRE(std::strcmp(ss.c_str(), "world!") == 0); } - // TODO: substring into string + size is longer than end + SECTION("substring start after the end is empty") { + REQUIRE(s.substr(1'000'000, 1).empty()); + } } SECTION( "Comparisons are deep" ) { @@ -124,15 +126,32 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { } TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") { + //TODO: + // * substr using Catch::StringRef; SECTION("Simple constructors") { - STATIC_REQUIRE(StringRef{}.size() == 0); - - STATIC_REQUIRE(StringRef{ "abc", 3 }.size() == 3); - STATIC_REQUIRE(StringRef{ "abc", 3 }.isNullTerminated()); - - STATIC_REQUIRE(StringRef{ "abc", 2 }.size() == 2); - STATIC_REQUIRE_FALSE(StringRef{ "abc", 2 }.isNullTerminated()); + constexpr StringRef empty; + STATIC_REQUIRE(empty.size() == 0); + STATIC_REQUIRE(empty.begin() == empty.end()); + + constexpr char const* const abc = "abc"; + + constexpr StringRef stringref(abc, 3); + STATIC_REQUIRE(stringref.size() == 3); + STATIC_REQUIRE(stringref.isNullTerminated()); + STATIC_REQUIRE(stringref.data() == abc); + STATIC_REQUIRE(stringref.begin() == abc); + STATIC_REQUIRE(stringref.begin() != stringref.end()); + STATIC_REQUIRE(stringref.substr(10, 0).empty()); + STATIC_REQUIRE(stringref.substr(2, 1).data() == abc + 2); + + + constexpr StringRef shortened(abc, 2); + STATIC_REQUIRE(shortened.size() == 2); + STATIC_REQUIRE(shortened.data() == abc); + STATIC_REQUIRE(shortened.begin() != shortened.end()); + STATIC_REQUIRE_FALSE(shortened.isNullTerminated()); + STATIC_REQUIRE_FALSE(shortened.substr(1, 3).isNullTerminated()); } SECTION("UDL construction") { constexpr auto sr1 = "abc"_catch_sr; |