22#include " defines.hpp"
33#include " util/utils.hpp"
44
5+ #include < sstream>
6+
57using namespace utils ;
68
79TEST_CASE (" Basic file input with safe get_line that is non line ending specific" , " " ) {
@@ -13,16 +15,62 @@ TEST_CASE("Basic file input with safe get_line that is non line ending specific"
1315 CHECK (TextFile.is_open ());
1416
1517 if (TextFile.is_open ()) {
16- SafeString ::get_line (TextFile, test);
18+ StreamHandler ::get_line (TextFile, test);
1719 REQUIRE (test == " This is a non dbc formatted file." );
18- SafeString ::get_line (TextFile, test);
20+ StreamHandler ::get_line (TextFile, test);
1921 REQUIRE (test == " " );
20- SafeString ::get_line (TextFile, test);
22+ StreamHandler ::get_line (TextFile, test);
2123 REQUIRE (test == " Make sure things pass with this" );
22- SafeString ::get_line (TextFile, test);
24+ StreamHandler ::get_line (TextFile, test);
2325 REQUIRE (test == " Who knows what might happen." );
2426
2527 TextFile.close ();
2628 }
2729 }
2830}
31+
32+ TEST_CASE (" Test line finding utility functions" , " " ) {
33+ std::string line;
34+ std::string test_string = \
35+ " hello\n \
36+ \n \
37+ \n \
38+ \n \
39+ this is not blank\n \
40+ maybe not this one either\n \
41+ \n \
42+ Someone wrote something....\n \
43+ b\n \
44+ end" ;
45+
46+ std::istringstream stream (test_string);
47+
48+ SECTION (" Test skipping empty lines" ) {
49+ StreamHandler::get_line (stream, line);
50+
51+ CHECK (line == " hello" );
52+
53+ StreamHandler::get_next_non_blank_line (stream, line);
54+ REQUIRE (line == " this is not blank" );
55+
56+ StreamHandler::skip_to_next_blank_line (stream, line);
57+ REQUIRE (line == " " );
58+
59+ StreamHandler::get_next_non_blank_line (stream, line);
60+ REQUIRE (line == " Someone wrote something...." );
61+
62+ StreamHandler::get_next_non_blank_line (stream, line);
63+ REQUIRE (line == " b" );
64+
65+ StreamHandler::get_next_non_blank_line (stream, line);
66+ REQUIRE (line == " end" );
67+
68+ SECTION (" Test end of the files" , " [edge case]" ) {
69+ StreamHandler::get_next_non_blank_line (stream, line);
70+ REQUIRE (line == " " );
71+
72+ StreamHandler::skip_to_next_blank_line (stream, line);
73+ REQUIRE (line == " " );
74+ }
75+ }
76+ }
0 commit comments