| 18 | #include "test.h" |
| 19 | |
| 20 | FL_TEST_FILE(FL_FILEPATH) { |
| 21 | |
| 22 | using namespace fl; |
| 23 | |
| 24 | |
| 25 | //============================================================================= |
| 26 | // SECTION: Tests from str.cpp |
| 27 | //============================================================================= |
| 28 | |
| 29 | FL_TEST_CASE("Str basic operations") { |
| 30 | FL_SUBCASE("Construction and assignment") { |
| 31 | fl::string s1; |
| 32 | FL_CHECK(s1.size() == 0); |
| 33 | FL_CHECK(s1.c_str()[0] == '\0'); |
| 34 | |
| 35 | fl::string s2("hello"); |
| 36 | FL_CHECK(s2.size() == 5); |
| 37 | FL_CHECK(fl::strcmp(s2.c_str(), "hello") == 0); |
| 38 | |
| 39 | fl::string s3 = s2; |
| 40 | FL_CHECK(s3.size() == 5); |
| 41 | FL_CHECK(fl::strcmp(s3.c_str(), "hello") == 0); |
| 42 | |
| 43 | s1 = "world"; |
| 44 | FL_CHECK(s1.size() == 5); |
| 45 | FL_CHECK(fl::strcmp(s1.c_str(), "world") == 0); |
| 46 | } |
| 47 | |
| 48 | FL_SUBCASE("Comparison operators") { |
| 49 | fl::string s1("hello"); |
| 50 | fl::string s2("hello"); |
| 51 | fl::string s3("world"); |
| 52 | |
| 53 | FL_CHECK(s1 == s2); |
| 54 | FL_CHECK(s1 != s3); |
| 55 | } |
| 56 | |
| 57 | FL_SUBCASE("Indexing") { |
| 58 | fl::string s("hello"); |
| 59 | FL_CHECK(s[0] == 'h'); |
| 60 | FL_CHECK(s[4] == 'o'); |
| 61 | FL_CHECK(s[5] == '\0'); // Null terminator |
| 62 | } |
| 63 | |
| 64 | FL_SUBCASE("Append") { |
| 65 | fl::string s("hello"); |
| 66 | s.append(" world"); |
| 67 | FL_CHECK(s.size() == 11); |
| 68 | FL_CHECK(fl::strcmp(s.c_str(), "hello world") == 0); |
| 69 | } |
| 70 | |
| 71 | FL_SUBCASE("CRGB to Str") { |
| 72 | CRGB c(255, 0, 0); |
| 73 | fl::string s = c.toString(); |
| 74 | FL_CHECK_EQ(s, "CRGB(255,0,0)"); |
| 75 | } |
| 76 | |
| 77 | FL_SUBCASE("Copy-on-write behavior") { |
nothing calls this directly
no test coverage detected