Core: Remove skip_cr argument from String
This commit is contained in:
@ -82,29 +82,57 @@ TEST_CASE("[FileAccess] CSV read") {
|
||||
}
|
||||
|
||||
TEST_CASE("[FileAccess] Get as UTF-8 String") {
|
||||
Ref<FileAccess> f_lf = FileAccess::open(TestUtils::get_data_path("line_endings_lf.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_lf.is_valid());
|
||||
String s_lf = f_lf->get_as_utf8_string();
|
||||
f_lf->seek(0);
|
||||
String s_lf_nocr = f_lf->get_as_utf8_string(true);
|
||||
CHECK(s_lf == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
CHECK(s_lf_nocr == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
SUBCASE("Newline == \\n (Unix)") {
|
||||
Ref<FileAccess> f_lf = FileAccess::open(TestUtils::get_data_path("line_endings_lf.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_lf.is_valid());
|
||||
String s_lf = f_lf->get_as_utf8_string();
|
||||
CHECK(s_lf == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
f_lf->seek(0);
|
||||
CHECK(f_lf->get_line() == "Hello darkness");
|
||||
CHECK(f_lf->get_line() == "My old friend");
|
||||
CHECK(f_lf->get_line() == "I've come to talk");
|
||||
CHECK(f_lf->get_line() == "With you again");
|
||||
CHECK(f_lf->get_error() == Error::OK);
|
||||
}
|
||||
|
||||
Ref<FileAccess> f_crlf = FileAccess::open(TestUtils::get_data_path("line_endings_crlf.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_crlf.is_valid());
|
||||
String s_crlf = f_crlf->get_as_utf8_string();
|
||||
f_crlf->seek(0);
|
||||
String s_crlf_nocr = f_crlf->get_as_utf8_string(true);
|
||||
CHECK(s_crlf == "Hello darkness\r\nMy old friend\r\nI've come to talk\r\nWith you again\r\n");
|
||||
CHECK(s_crlf_nocr == "Hello darkness\nMy old friend\nI've come to talk\nWith you again\n");
|
||||
SUBCASE("Newline == \\r\\n (Windows)") {
|
||||
Ref<FileAccess> f_crlf = FileAccess::open(TestUtils::get_data_path("line_endings_crlf.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_crlf.is_valid());
|
||||
String s_crlf = f_crlf->get_as_utf8_string();
|
||||
CHECK(s_crlf == "Hello darkness\r\nMy old friend\r\nI've come to talk\r\nWith you again\r\n");
|
||||
f_crlf->seek(0);
|
||||
CHECK(f_crlf->get_line() == "Hello darkness");
|
||||
CHECK(f_crlf->get_line() == "My old friend");
|
||||
CHECK(f_crlf->get_line() == "I've come to talk");
|
||||
CHECK(f_crlf->get_line() == "With you again");
|
||||
CHECK(f_crlf->get_error() == Error::OK);
|
||||
}
|
||||
|
||||
Ref<FileAccess> f_cr = FileAccess::open(TestUtils::get_data_path("line_endings_cr.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_cr.is_valid());
|
||||
String s_cr = f_cr->get_as_utf8_string();
|
||||
f_cr->seek(0);
|
||||
String s_cr_nocr = f_cr->get_as_utf8_string(true);
|
||||
CHECK(s_cr == "Hello darkness\rMy old friend\rI've come to talk\rWith you again\r");
|
||||
CHECK(s_cr_nocr == "Hello darknessMy old friendI've come to talkWith you again");
|
||||
SUBCASE("Newline == \\r (Legacy macOS)") {
|
||||
Ref<FileAccess> f_cr = FileAccess::open(TestUtils::get_data_path("line_endings_cr.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_cr.is_valid());
|
||||
String s_cr = f_cr->get_as_utf8_string();
|
||||
CHECK(s_cr == "Hello darkness\rMy old friend\rI've come to talk\rWith you again\r");
|
||||
f_cr->seek(0);
|
||||
CHECK(f_cr->get_line() == "Hello darkness");
|
||||
CHECK(f_cr->get_line() == "My old friend");
|
||||
CHECK(f_cr->get_line() == "I've come to talk");
|
||||
CHECK(f_cr->get_line() == "With you again");
|
||||
CHECK(f_cr->get_error() == Error::OK);
|
||||
}
|
||||
|
||||
SUBCASE("Newline == Mixed") {
|
||||
Ref<FileAccess> f_mix = FileAccess::open(TestUtils::get_data_path("line_endings_mixed.test.txt"), FileAccess::READ);
|
||||
REQUIRE(f_mix.is_valid());
|
||||
String s_mix = f_mix->get_as_utf8_string();
|
||||
CHECK(s_mix == "Hello darkness\nMy old friend\r\nI've come to talk\rWith you again");
|
||||
f_mix->seek(0);
|
||||
CHECK(f_mix->get_line() == "Hello darkness");
|
||||
CHECK(f_mix->get_line() == "My old friend");
|
||||
CHECK(f_mix->get_line() == "I've come to talk");
|
||||
CHECK(f_mix->get_line() == "With you again");
|
||||
CHECK(f_mix->get_error() == Error::ERR_FILE_EOF); // Not a bug; the file lacks a final newline.
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[FileAccess] Get/Store floating point values") {
|
||||
|
||||
@ -156,20 +156,6 @@ TEST_CASE("[String] UTF16 with BOM") {
|
||||
CHECK(String::utf16(cs) == s);
|
||||
}
|
||||
|
||||
TEST_CASE("[String] UTF8 with CR") {
|
||||
const String base = U"Hello darkness\r\nMy old friend\nI've come to talk\rWith you again";
|
||||
|
||||
String keep_cr;
|
||||
Error err = keep_cr.append_utf8(base.utf8().get_data());
|
||||
CHECK(err == OK);
|
||||
CHECK(keep_cr == base);
|
||||
|
||||
String no_cr;
|
||||
err = no_cr.append_utf8(base.utf8().get_data(), -1, true); // Skip CR.
|
||||
CHECK(err == OK);
|
||||
CHECK(no_cr == base.replace("\r", ""));
|
||||
}
|
||||
|
||||
TEST_CASE("[String] Invalid UTF8 (non shortest form sequence)") {
|
||||
ERR_PRINT_OFF
|
||||
// Examples from the unicode standard : 3.9 Unicode Encoding Forms - Table 3.8.
|
||||
|
||||
3
tests/data/line_endings_mixed.test.txt
Normal file
3
tests/data/line_endings_mixed.test.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Hello darkness
|
||||
My old friend
|
||||
I've come to talk
|
||||
Reference in New Issue
Block a user