Add tests for StringRef::numberOfCharacters

This commit is contained in:
Martin Hořeňovský 2018-02-08 13:10:12 +01:00
parent 1b2fa601c6
commit 3b6fda3c1b

View File

@ -36,7 +36,7 @@ namespace Catch {
} }
} // namespace Catch } // namespace Catch
TEST_CASE( "StringRef", "[Strings]" ) { TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
using Catch::StringRef; using Catch::StringRef;
@ -164,9 +164,21 @@ TEST_CASE( "StringRef", "[Strings]" ) {
REQUIRE( stdStr.size() == sr.size() ); REQUIRE( stdStr.size() == sr.size() );
} }
} }
SECTION( "Counting utf-8 codepoints" ) {
StringRef ascii = "just a plain old boring ascii string...";
REQUIRE(ascii.numberOfCharacters() == ascii.size());
StringRef simpleu8 = u8"Trocha češtiny nikoho nezabila";
REQUIRE(simpleu8.numberOfCharacters() == 30);
StringRef emojis = u8"Here be 👾";
REQUIRE(emojis.numberOfCharacters() == 9);
}
} }
TEST_CASE( "replaceInPlace" ) { TEST_CASE( "replaceInPlace", "[Strings][StringManip]" ) {
std::string letters = "abcdefcg"; std::string letters = "abcdefcg";
SECTION( "replace single char" ) { SECTION( "replace single char" ) {
CHECK( Catch::replaceInPlace( letters, "b", "z" ) ); CHECK( Catch::replaceInPlace( letters, "b", "z" ) );