1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Make string to v3f parsing consistent, replace core.setting_get_pos() by core.settings:get_pos() (#15438)

Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
AFCMS 2024-12-04 18:19:46 +01:00 committed by GitHub
parent 18caf3a18d
commit e545e96d2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 162 additions and 45 deletions

View file

@ -42,6 +42,14 @@ const char *TestSettings::config_text_before =
"floaty_thing = 1.1\n"
"stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n"
"coord = (1, 2, 4.5)\n"
"coord_invalid = (1,2,3\n"
"coord_invalid_2 = 1, 2, 3 test\n"
"coord_invalid_3 = (test, something, stupid)\n"
"coord_invalid_4 = (1, test, 3)\n"
"coord_invalid_5 = ()\n"
"coord_invalid_6 = (1, 2)\n"
"coord_invalid_7 = (1)\n"
"coord_no_parenthesis = 1,2,3\n"
" # this is just a comment\n"
"this is an invalid line\n"
"asdf = {\n"
@ -94,7 +102,15 @@ const char *TestSettings::config_text_after =
" spread = (250,250,250)\n"
"}\n"
"zoop = true\n"
"coord2 = (1,2,3.3)\n"
"coord2 = (1,2,3.25)\n"
"coord_invalid = (1,2,3\n"
"coord_invalid_2 = 1, 2, 3 test\n"
"coord_invalid_3 = (test, something, stupid)\n"
"coord_invalid_4 = (1, test, 3)\n"
"coord_invalid_5 = ()\n"
"coord_invalid_6 = (1, 2)\n"
"coord_invalid_7 = (1)\n"
"coord_no_parenthesis = 1,2,3\n"
"floaty_thing_2 = 1.25\n"
"groupy_thing = {\n"
" animals = cute\n"
@ -140,18 +156,33 @@ void TestSettings::testAllSettings()
// Not sure if 1.1 is an exact value as a float, but doesn't matter
UASSERT(fabs(s.getFloat("floaty_thing") - 1.1) < 0.001);
UASSERT(s.get("stringy_thing") == u8"asd /( ¤%&(/\" BLÖÄRP");
UASSERT(fabs(s.getV3F("coord").X - 1.0) < 0.001);
UASSERT(fabs(s.getV3F("coord").Y - 2.0) < 0.001);
UASSERT(fabs(s.getV3F("coord").Z - 4.5) < 0.001);
UASSERT(s.getV3F("coord").value().X == 1.0);
UASSERT(s.getV3F("coord").value().Y == 2.0);
UASSERT(s.getV3F("coord").value().Z == 4.5);
// Test the setting of settings too
s.setFloat("floaty_thing_2", 1.25);
s.setV3F("coord2", v3f(1, 2, 3.3));
s.setV3F("coord2", v3f(1, 2, 3.25));
UASSERT(s.get("floaty_thing_2").substr(0,4) == "1.25");
UASSERT(fabs(s.getFloat("floaty_thing_2") - 1.25) < 0.001);
UASSERT(fabs(s.getV3F("coord2").X - 1.0) < 0.001);
UASSERT(fabs(s.getV3F("coord2").Y - 2.0) < 0.001);
UASSERT(fabs(s.getV3F("coord2").Z - 3.3) < 0.001);
UASSERT(s.getFloat("floaty_thing_2") == 1.25);
UASSERT(s.getV3F("coord2").value().X == 1.0);
UASSERT(s.getV3F("coord2").value().Y == 2.0);
UASSERT(s.getV3F("coord2").value().Z == 3.25);
std::optional<v3f> testNotExist;
UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist));
EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist"));
UASSERT(!s.getV3F("coord_invalid").has_value());
UASSERT(!s.getV3F("coord_invalid_2").has_value());
UASSERT(!s.getV3F("coord_invalid_3").has_value());
UASSERT(!s.getV3F("coord_invalid_4").has_value());
UASSERT(!s.getV3F("coord_invalid_5").has_value());
UASSERT(!s.getV3F("coord_invalid_6").has_value());
UASSERT(!s.getV3F("coord_invalid_7").has_value());
std::optional<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis");
UASSERT(testNoParenthesis.value() == v3f(1, 2, 3));
// Test settings groups
Settings *group = s.getGroup("asdf");