From a43d3bdca525d24e307f339c06e325d25b4dec20 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 21 Oct 2024 16:51:27 -0400 Subject: [PATCH] format::desktop_entry: Test most value parsing functions --- format/desktop_entry/value_test.ha | 115 +++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/format/desktop_entry/value_test.ha b/format/desktop_entry/value_test.ha index e69de29..4cec217 100644 --- a/format/desktop_entry/value_test.ha +++ b/format/desktop_entry/value_test.ha @@ -0,0 +1,115 @@ +use fmt; +use math; + +@test fn parse_string() void = { + assert(parse_string("hello")! == "hello"); + assert(parse_string("hel\\s\\n\\t\\r\\\\\\;lo")! == "hel \n\t\r\\;lo"); + assert(parse_string("hello☠") is invalid_ascii); + assert(parse_string("hello;world") is expected_single); +}; + +@test fn parse_localestring() void = { + assert(parse_localestring("hello")! == "hello"); + assert(parse_localestring("hel\\s\\n\\t\\r\\\\\\;lo")! == "hel \n\t\r\\;lo"); + assert(parse_localestring("hello☠")! == "hello☠"); + assert(parse_localestring("hello;world") is expected_single); +}; + +@test fn parse_iconstring() void = { + assert(parse_iconstring("hello")! == "hello"); + assert(parse_iconstring("hel\\s\\n\\t\\r\\\\\\;lo")! == "hel \n\t\r\\;lo"); + assert(parse_iconstring("hello☠")! == "hello☠"); + assert(parse_iconstring("hello;world") is expected_single); +}; + +@test fn parse_boolean() void = { + assert(parse_boolean("true")! == true); + assert(parse_boolean("false")! == false); + assert(parse_boolean("hello") is invalid_boolean); + assert(parse_boolean("ttrue") is invalid_boolean); + assert(parse_boolean("falsee") is invalid_boolean); + assert(parse_boolean("") is invalid_boolean); + assert(parse_boolean("1") is invalid_boolean); + assert(parse_boolean("0") is invalid_boolean); + assert(parse_boolean("true;false") is expected_single); +}; + +@test fn parse_numeric() void = { + assert(parse_numeric("9")! == 9.0); + assert(parse_numeric("9.0")! == 9.0); + assert(parse_numeric("34.93")! == 34.93); + assert(parse_numeric("-100.895")! == -100.895); + assert(math::isnan(parse_numeric("NaN")!)); + assert(parse_numeric("Infinity")! == math::INF); + assert(parse_numeric("hello") is invalid_numeric); + assert(parse_numeric("--") is invalid_numeric); + assert(parse_numeric("....") is invalid_numeric); + assert(parse_numeric("234;7.4") is expected_single); +}; + +// TODO + +@test fn string_escaper_next_a() void = { + let escaper = escape_string("bird;water;;river;"); + let correct: []str = [ + "bird", + "water", + "", + "river", + ]; + for (let correct .. correct) { + let got = string_escaper_next(&escaper) as str; + fmt::printf("[{}]\t[{}]\n", correct, got)!; + assert(correct == got); + }; + assert(string_escaper_next(&escaper) is done, "not done"); +}; + +@test fn string_escaper_next_b() void = { + let escaper = escape_string("b\\r\\tird;wa\\;ter;;riv\\ner;nuh uh"); + let correct: []str = [ + "b\r\tird", + "wa;ter", + "", + "riv\ner", + "nuh uh", + ]; + for (let correct .. correct) { + let got = string_escaper_next(&escaper) as str; + fmt::printf("[{}]\t[{}]\n", correct, got)!; + assert(correct == got); + }; + assert(string_escaper_next(&escaper) is done, "not done"); +}; + +@test fn splitter_next_a() void = { + let splitte = split("bird;water;;river;"); + let correct: []str = [ + "bird", + "water", + "", + "river", + ]; + for (let correct .. correct) { + let got = splitter_next(&splitte) as str; + fmt::printf("[{}]\t[{}]\n", correct, got)!; + assert(correct == got); + }; + assert(splitter_next(&splitte) is done, "not done"); +}; + +@test fn splitter_next_b() void = { + let splitte = split("bird;water;;river"); + let correct: []str = [ + "bird", + "water", + "", + "river", + ]; + for (let correct .. correct) { + let got = splitter_next(&splitte) as str; + fmt::printf("[{}]\t[{}]\n", correct, got)!; + assert(correct == got); + }; + assert(splitter_next(&splitte) is done, "not done"); +};