| 7 | #include "fl/stl/int.h" |
| 8 | |
| 9 | FL_TEST_FILE(FL_FILEPATH) { |
| 10 | |
| 11 | using namespace fl; |
| 12 | |
| 13 | FL_TEST_CASE("string_view - construction") { |
| 14 | // Default constructor |
| 15 | string_view empty; |
| 16 | FL_CHECK(empty.empty()); |
| 17 | FL_CHECK(empty.size() == 0); |
| 18 | |
| 19 | // From C string |
| 20 | string_view from_cstr("hello"); |
| 21 | FL_CHECK(from_cstr.size() == 5); |
| 22 | FL_CHECK_FALSE(from_cstr.empty()); |
| 23 | FL_CHECK(from_cstr[0] == 'h'); |
| 24 | FL_CHECK(from_cstr[4] == 'o'); |
| 25 | |
| 26 | // From pointer and length |
| 27 | const char* data = "world"; |
| 28 | string_view from_ptr(data, 3); |
| 29 | FL_CHECK(from_ptr.size() == 3); |
| 30 | FL_CHECK(from_ptr[0] == 'w'); |
| 31 | FL_CHECK(from_ptr[2] == 'r'); |
| 32 | |
| 33 | // From C array |
| 34 | const char arr[] = "test"; |
| 35 | string_view from_arr(arr); |
| 36 | FL_CHECK(from_arr.size() == 4); |
| 37 | |
| 38 | // From fl::string |
| 39 | fl::string str("fastled"); |
| 40 | string_view from_str(str); |
| 41 | FL_CHECK(from_str.size() == 7); |
| 42 | FL_CHECK(from_str[0] == 'f'); |
| 43 | } |
| 44 | |
| 45 | FL_TEST_CASE("string_view - element access") { |
| 46 | string_view sv("hello"); |
| 47 | |
| 48 | // operator[] |
| 49 | FL_CHECK(sv[0] == 'h'); |
| 50 | FL_CHECK(sv[4] == 'o'); |
| 51 | |
| 52 | // at() |
| 53 | FL_CHECK(sv.at(0) == 'h'); |
| 54 | FL_CHECK(sv.at(4) == 'o'); |
| 55 | |
| 56 | // front() / back() |
| 57 | FL_CHECK(sv.front() == 'h'); |
| 58 | FL_CHECK(sv.back() == 'o'); |
| 59 | |
| 60 | // data() |
| 61 | FL_CHECK(sv.data() != nullptr); |
| 62 | FL_CHECK(sv.data()[0] == 'h'); |
| 63 | } |
| 64 | |
| 65 | FL_TEST_CASE("string_view - iterators") { |
| 66 | string_view sv("abc"); |
nothing calls this directly
no test coverage detected