@@ -82,29 +82,57 @@ TEST_CASE("[FileAccess] CSV read") {
8282}
8383
8484TEST_CASE (" [FileAccess] Get as UTF-8 String" ) {
85- Ref<FileAccess> f_lf = FileAccess::open (TestUtils::get_data_path (" line_endings_lf.test.txt" ), FileAccess::READ);
86- REQUIRE (f_lf.is_valid ());
87- String s_lf = f_lf->get_as_utf8_string ();
88- f_lf->seek (0 );
89- String s_lf_nocr = f_lf->get_as_utf8_string (true );
90- CHECK (s_lf == " Hello darkness\n My old friend\n I've come to talk\n With you again\n " );
91- CHECK (s_lf_nocr == " Hello darkness\n My old friend\n I've come to talk\n With you again\n " );
92-
93- Ref<FileAccess> f_crlf = FileAccess::open (TestUtils::get_data_path (" line_endings_crlf.test.txt" ), FileAccess::READ);
94- REQUIRE (f_crlf.is_valid ());
95- String s_crlf = f_crlf->get_as_utf8_string ();
96- f_crlf->seek (0 );
97- String s_crlf_nocr = f_crlf->get_as_utf8_string (true );
98- CHECK (s_crlf == " Hello darkness\r\n My old friend\r\n I've come to talk\r\n With you again\r\n " );
99- CHECK (s_crlf_nocr == " Hello darkness\n My old friend\n I've come to talk\n With you again\n " );
100-
101- Ref<FileAccess> f_cr = FileAccess::open (TestUtils::get_data_path (" line_endings_cr.test.txt" ), FileAccess::READ);
102- REQUIRE (f_cr.is_valid ());
103- String s_cr = f_cr->get_as_utf8_string ();
104- f_cr->seek (0 );
105- String s_cr_nocr = f_cr->get_as_utf8_string (true );
106- CHECK (s_cr == " Hello darkness\r My old friend\r I've come to talk\r With you again\r " );
107- CHECK (s_cr_nocr == " Hello darknessMy old friendI've come to talkWith you again" );
85+ SUBCASE (" Newline == \\ n (Unix)" ) {
86+ Ref<FileAccess> f_lf = FileAccess::open (TestUtils::get_data_path (" line_endings_lf.test.txt" ), FileAccess::READ);
87+ REQUIRE (f_lf.is_valid ());
88+ String s_lf = f_lf->get_as_utf8_string ();
89+ CHECK (s_lf == " Hello darkness\n My old friend\n I've come to talk\n With you again\n " );
90+ f_lf->seek (0 );
91+ CHECK (f_lf->get_line () == " Hello darkness" );
92+ CHECK (f_lf->get_line () == " My old friend" );
93+ CHECK (f_lf->get_line () == " I've come to talk" );
94+ CHECK (f_lf->get_line () == " With you again" );
95+ CHECK (f_lf->get_error () == Error::OK);
96+ }
97+
98+ SUBCASE (" Newline == \\ r\\ n (Windows)" ) {
99+ Ref<FileAccess> f_crlf = FileAccess::open (TestUtils::get_data_path (" line_endings_crlf.test.txt" ), FileAccess::READ);
100+ REQUIRE (f_crlf.is_valid ());
101+ String s_crlf = f_crlf->get_as_utf8_string ();
102+ CHECK (s_crlf == " Hello darkness\r\n My old friend\r\n I've come to talk\r\n With you again\r\n " );
103+ f_crlf->seek (0 );
104+ CHECK (f_crlf->get_line () == " Hello darkness" );
105+ CHECK (f_crlf->get_line () == " My old friend" );
106+ CHECK (f_crlf->get_line () == " I've come to talk" );
107+ CHECK (f_crlf->get_line () == " With you again" );
108+ CHECK (f_crlf->get_error () == Error::OK);
109+ }
110+
111+ SUBCASE (" Newline == \\ r (Legacy macOS)" ) {
112+ Ref<FileAccess> f_cr = FileAccess::open (TestUtils::get_data_path (" line_endings_cr.test.txt" ), FileAccess::READ);
113+ REQUIRE (f_cr.is_valid ());
114+ String s_cr = f_cr->get_as_utf8_string ();
115+ CHECK (s_cr == " Hello darkness\r My old friend\r I've come to talk\r With you again\r " );
116+ f_cr->seek (0 );
117+ CHECK (f_cr->get_line () == " Hello darkness" );
118+ CHECK (f_cr->get_line () == " My old friend" );
119+ CHECK (f_cr->get_line () == " I've come to talk" );
120+ CHECK (f_cr->get_line () == " With you again" );
121+ CHECK (f_cr->get_error () == Error::OK);
122+ }
123+
124+ SUBCASE (" Newline == Mixed" ) {
125+ Ref<FileAccess> f_mix = FileAccess::open (TestUtils::get_data_path (" line_endings_mixed.test.txt" ), FileAccess::READ);
126+ REQUIRE (f_mix.is_valid ());
127+ String s_mix = f_mix->get_as_utf8_string ();
128+ CHECK (s_mix == " Hello darkness\n My old friend\r\n I've come to talk\r With you again" );
129+ f_mix->seek (0 );
130+ CHECK (f_mix->get_line () == " Hello darkness" );
131+ CHECK (f_mix->get_line () == " My old friend" );
132+ CHECK (f_mix->get_line () == " I've come to talk" );
133+ CHECK (f_mix->get_line () == " With you again" );
134+ CHECK (f_mix->get_error () == Error::ERR_FILE_EOF); // Not a bug; the file lacks a final newline.
135+ }
108136}
109137
110138TEST_CASE (" [FileAccess] Get/Store floating point values" ) {
0 commit comments