| 14 | #include "test.h" |
| 15 | |
| 16 | FL_TEST_FILE(FL_FILEPATH) { |
| 17 | |
| 18 | FL_TEST_CASE("fl::readStringUntil basic") { |
| 19 | // Inject simple read handler that returns "hello\n" |
| 20 | const char* testData = "hello\n"; |
| 21 | size_t pos = 0; |
| 22 | |
| 23 | fl::inject_available_handler([&]() { |
| 24 | return (pos < fl::strlen(testData)) ? 1 : 0; |
| 25 | }); |
| 26 | |
| 27 | fl::inject_read_handler([&]() { |
| 28 | return (pos < fl::strlen(testData)) ? testData[pos++] : -1; |
| 29 | }); |
| 30 | |
| 31 | // Test readStringUntil directly to sstream |
| 32 | fl::sstream buffer; |
| 33 | bool success = fl::readStringUntil(buffer, '\n', '\r', fl::nullopt); |
| 34 | |
| 35 | FL_CHECK(success); |
| 36 | FL_CHECK_EQ(buffer.str(), "hello"); |
| 37 | |
| 38 | fl::clear_io_handlers(); |
| 39 | } |
| 40 | |
| 41 | FL_TEST_CASE("fl::readStringUntil with skipChar") { |
| 42 | // Inject handler that returns "hello\r\nworld\n" (Windows line ending) |
| 43 | const char* testData = "hello\r\nworld\n"; |
| 44 | size_t pos = 0; |
| 45 | |
| 46 | fl::inject_available_handler([&]() { |
| 47 | return (pos < fl::strlen(testData)) ? 1 : 0; |
| 48 | }); |
| 49 | |
| 50 | fl::inject_read_handler([&]() { |
| 51 | return (pos < fl::strlen(testData)) ? testData[pos++] : -1; |
| 52 | }); |
| 53 | |
| 54 | // Read first line - should skip '\r' and stop at first '\n' |
| 55 | fl::sstream buffer; |
| 56 | bool success = fl::readStringUntil(buffer, '\n', '\r', fl::nullopt); |
| 57 | |
| 58 | FL_CHECK(success); |
| 59 | FL_CHECK_EQ(buffer.str(), "hello"); // '\r' should be skipped |
| 60 | |
| 61 | // Read second line - pos should auto-advance from first read |
| 62 | buffer.clear(); |
| 63 | success = fl::readStringUntil(buffer, '\n', '\r', fl::nullopt); |
| 64 | |
| 65 | FL_CHECK(success); |
| 66 | FL_CHECK_EQ(buffer.str(), "world"); |
| 67 | |
| 68 | fl::clear_io_handlers(); |
| 69 | } |
| 70 | |
| 71 | FL_TEST_CASE("fl::readLine delegation") { |
| 72 | // Inject handler that returns "test data\n" |
| 73 | const char* testData = "test data\n"; |
nothing calls this directly
no test coverage detected