The settings the game saves itself, the quiz settings and now fullscreen, move to settings.cfg (settings_debug.cfg in debug mode). config.ini in the same folder is edited by hand: the server to start with, the API password and debug mode. The game writes it with everything commented out when it is missing and never changes it after that. IniFile reads it: plain key = value lines, whole-line # or ; comments and optional quotes.
75 lines
2.6 KiB
GDScript
75 lines
2.6 KiB
GDScript
extends GdUnitTestSuite
|
|
## The small INI reader used for the hand-edited config file.
|
|
|
|
|
|
func test_reads_sections_and_settings() -> void:
|
|
var ini: IniFile = IniFile.parse("[server]\nurl = http://a:8080\n[game]\ndebug=true\n")
|
|
|
|
assert_str(ini.get_string("server", "url")).is_equal("http://a:8080")
|
|
assert_bool(ini.get_bool("game", "debug", false)).is_true()
|
|
assert_array(ini.get_sections()).contains_exactly(["server", "game"])
|
|
|
|
|
|
func test_comment_lines_are_skipped() -> void:
|
|
var ini: IniFile = IniFile.parse("; one\n# two\n[server]\n;url = a\n # url = b\n")
|
|
|
|
assert_bool(ini.has_value("server", "url")).is_false()
|
|
assert_array(ini.get_sections()).is_empty()
|
|
|
|
|
|
func test_values_keep_comment_characters() -> void:
|
|
var ini: IniFile = IniFile.parse("[server]\npassword = a;b#c=d\n")
|
|
|
|
assert_str(ini.get_string("server", "password")).is_equal("a;b#c=d")
|
|
|
|
|
|
func test_quotes_around_a_value_are_removed() -> void:
|
|
var ini: IniFile = IniFile.parse("[a]\none = \"x y\"\ntwo = 'z'\nthree = \"half\n")
|
|
|
|
assert_str(ini.get_string("a", "one")).is_equal("x y")
|
|
assert_str(ini.get_string("a", "two")).is_equal("z")
|
|
assert_str(ini.get_string("a", "three")).is_equal("\"half")
|
|
|
|
|
|
func test_names_are_not_case_sensitive() -> void:
|
|
var ini: IniFile = IniFile.parse("[Server]\nURL = http://a\n")
|
|
|
|
assert_str(ini.get_string("server", "url")).is_equal("http://a")
|
|
|
|
|
|
func test_empty_value_is_an_empty_string() -> void:
|
|
var ini: IniFile = IniFile.parse("[server]\npassword =\n")
|
|
|
|
assert_bool(ini.has_value("server", "password")).is_true()
|
|
assert_str(ini.get_string("server", "password", "default")).is_empty()
|
|
|
|
|
|
func test_missing_setting_gives_the_default() -> void:
|
|
var ini: IniFile = IniFile.parse("")
|
|
|
|
assert_str(ini.get_string("server", "url", "fallback")).is_equal("fallback")
|
|
assert_bool(ini.get_bool("game", "debug", true)).is_true()
|
|
|
|
|
|
func test_bool_words() -> void:
|
|
var ini: IniFile = IniFile.parse("[a]\nb = Yes\nc = off\nd = 1\ne = maybe\n")
|
|
|
|
assert_bool(ini.get_bool("a", "b", false)).is_true()
|
|
assert_bool(ini.get_bool("a", "c", true)).is_false()
|
|
assert_bool(ini.get_bool("a", "d", false)).is_true()
|
|
assert_bool(ini.get_bool("a", "e", false)).is_false()
|
|
assert_bool(ini.get_bool("a", "e", true)).is_true()
|
|
|
|
|
|
func test_windows_line_endings() -> void:
|
|
var ini: IniFile = IniFile.parse("[server]\r\nurl = http://a\r\n")
|
|
|
|
assert_str(ini.get_string("server", "url")).is_equal("http://a")
|
|
|
|
|
|
func test_lines_that_are_not_settings_are_skipped() -> void:
|
|
var ini: IniFile = IniFile.parse("[a]\njust words\n= no key\nkey = value\n")
|
|
|
|
assert_str(ini.get_string("a", "key")).is_equal("value")
|
|
assert_bool(ini.has_value("a", "just words")).is_false()
|