diff options
author | Edwin van Leeuwen <edwinvanl@tuta.io> | 2022-06-18 12:41:40 +0100 |
---|---|---|
committer | Edwin van Leeuwen <edwinvanl@tuta.io> | 2022-06-18 12:41:40 +0100 |
commit | c5b87af882a6e8ecff61d97882c73c94adb114d3 (patch) | |
tree | 9194e4ccb1e35f6559fe7584c13b64722d20eab3 /test/catch_text.cpp | |
parent | 21b9d2a9a35551229af05e43bd6895a3441094ed (diff) | |
parent | 69cca38f7e467fff8df9ab79da249acac49c56b2 (diff) |
Merge branch 'release/1.0.0'v1.0.0
Diffstat (limited to 'test/catch_text.cpp')
-rw-r--r-- | test/catch_text.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/catch_text.cpp b/test/catch_text.cpp new file mode 100644 index 0000000..aa75066 --- /dev/null +++ b/test/catch_text.cpp @@ -0,0 +1,65 @@ +#define CATCH_CONFIG_MAIN + +#include <algorithm> + +#include "catch2/catch.hpp" + +#include "rttt/text.hpp" + +SCENARIO("We can split a string correctly") { + // Test split + auto v = rttt::text::split("/r/front", "/"); + REQUIRE(v.size() == 2); + REQUIRE(v[0] == "r"); + REQUIRE(v[1] == "front"); +} + +SCENARIO("Line wrapping works") { + using namespace rttt::text; + std::string str = + "Lorem Ipsum is simply dummy text of the printing and typesetting " + "industry. Lorem Ipsum has been the industry's standard dummy text " + "ever since the 1500s, when an unknown printer took a galley of type " + "and scrambled it to make a type specimen book. 😁"; + + auto wrapped = wrap(str, 50); + REQUIRE(wrapped.size() == 6); + for (auto &s : wrapped) { + REQUIRE(s.size() <= 50); + //std::cout << s << std::endl; + } + + // Deal with new lines + str = + "Lorem Ipsum is simply dummy text of the\nprinting and typesetting " + "industry. Lorem Ipsum has been the industry's standard dummy text " + "ever since the 1500s, when an unknown printer took a galley of type " + "and scrambled it to make a type specimen book. 😁"; + + wrapped = wrap(str, 50); + REQUIRE(wrapped.size() == 6); + for (auto &s : wrapped) { + REQUIRE(s.size() <= 50); + //std::cout << s << std::endl; + } + + str = + "Lorem Ipsum is simply dummy text of the printingandtypesetting " + "industry. Lorem Ipsum has been the industry's standard dummy text " + "ever since the 1500s, when an unknown printer took a galley of type " + "and scrambled it to make a type specimen book. 😁"; + + wrapped = wrap(str, 50); + REQUIRE(wrapped.size() == 6); + for (auto &s : wrapped) { + REQUIRE(s.size() <= 50); + //std::cout << s << std::endl; + } + + wrapped = wrap(str, 40); + REQUIRE(wrapped.size() == 7); + for (auto &s : wrapped) { + REQUIRE(s.size() <= 40); + //std::cout << s << std::endl; + } +} |