string.cpp (1553B)
1 #include "helper.hpp" 2 3 #include <string.hpp> 4 5 static const char *M = "[string]"; 6 7 TEST_CASE("string format", M) { 8 const std::string &formatted = String::format("%d%% Hello %s!", 100, "World"); 9 CHECK(formatted.size() == 17); 10 REQUIRE(formatted == "100% Hello World!"); 11 } 12 13 TEST_CASE("indent string", M) { 14 std::string actual; 15 16 SECTION("simple") 17 actual = String::indent("line1\nline2"); 18 19 SECTION("already indented") 20 actual = String::indent(" line1\n line2"); 21 22 REQUIRE(actual == " line1\r\n line2"); 23 } 24 25 TEST_CASE("pretty-print numbers", M) { 26 REQUIRE(String::number(42'000'000) == "42,000,000"); 27 } 28 29 TEST_CASE("strip RTF header", M) { 30 REQUIRE("Hello World" == String::stripRtf(R"( 31 {\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard 32 Hello World 33 } 34 )")); 35 } 36 37 TEST_CASE("strip RTF color header", M) { 38 REQUIRE("Hello World" == String::stripRtf(R"( 39 {\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}} 40 {\colortbl;\red255\green0\blue0;\red0\green0\blue255;} 41 \widowctrl\hyphauto 42 Hello World 43 } 44 )")); 45 } 46 47 TEST_CASE("strip RTF paragraphs", M) { 48 REQUIRE("foo\n\nbar\n\nbaz" == String::stripRtf(R"( 49 {\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 foo\par} 50 {\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 bar\par} 51 {\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 baz\par} 52 )")); 53 } 54 55 TEST_CASE("strip RTF line breaks", M) { 56 REQUIRE("foo\nbar\nbaz" == String::stripRtf(R"(foo\line bar\line 57 baz\line)")); 58 } 59 60 TEST_CASE("strip RTF literal braces", M) { 61 REQUIRE("{ }" == String::stripRtf(R"(\{ \})")); 62 }