Skip to content

Commit 3d1fbc6

Browse files
committed
Add file settings unit tests
1 parent 0fe5ac9 commit 3d1fbc6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/xtd.core.unit_tests/src/xtd/configuration/tests/file_settings_tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,29 @@ namespace xtd::configuration::tests {
502502
assert::are_equal("value6", fs["section2"]["key2"], csf_);
503503
assert::are_equal(84, as<int>(fs["section2"]["key3"]), csf_);
504504
}
505+
506+
void test_method_(from_string_with_spaces_comments_and_escape_sequences) {
507+
auto content =
508+
"# Section 1\n"
509+
"[section 1]\n"
510+
" key\\ 1 = value\\ \\ 1 # Comment key 1 # hoo\n"
511+
" key 2 = value 2 \n"
512+
" key 3 = value 3 \n"
513+
" key 4 = value 4 \n"
514+
" key 5 = \"\tvalue 5 \"; Comment key 5;;;;\n"
515+
"\n"
516+
"; Section 2###\n"
517+
"[section 2]; Other comment for section 2\n"
518+
" key 1 = value 6\n"
519+
" key 2 = value 7\n"
520+
" key 3 = value 8\n"
521+
" key 4 = value 9\n"
522+
" key 5 = value 10\n";
523+
auto fs = file_settings {};
524+
fs.from_string(content);
525+
assert::are_equal(file_settings::string_map {{"key 1", "value 1"}, {"key 2", "value 2"}, {"key 3", "value 3"}, {"key 4", "value 4"}, {"key 5", "\tvalue 5 "}}, fs.key_values("section 1"), csf_);
526+
assert::are_equal(file_settings::string_map {{"key 1", "value 6"}, {"key 2", "value 7"}, {"key 3", "value 8"}, {"key 4", "value 9"}, {"key 5", "value 10"}}, fs.key_values("section 2"), csf_);
527+
fs.save_as("test.ini");
528+
}
505529
};
506530
}

0 commit comments

Comments
 (0)