From fc533dbeea89cdbd2c1694c62662497db14befb3 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 21 Oct 2024 17:41:31 -0400 Subject: [PATCH] format::desktop_entry: Test integer parsing functions --- format/desktop_entry/value_test.ha | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/format/desktop_entry/value_test.ha b/format/desktop_entry/value_test.ha index 0eda815..92c259d 100644 --- a/format/desktop_entry/value_test.ha +++ b/format/desktop_entry/value_test.ha @@ -51,6 +51,14 @@ use strings; assert(parse_numeric("234;7.4") is expected_single); }; +@test fn parse_integer() void = { + assert(parse_integer("9")! == 9); + assert(parse_integer("2348")! == 2348); + assert(parse_integer("-324")! == -324); + assert(parse_integer("324.9") is invalid_integer); + assert(parse_integer("324.0") is invalid_integer); +}; + @test fn parse_strings() void = { let correct: []str = [ "b\r\tird", @@ -134,6 +142,28 @@ use strings; assert(parse_numerics(";5;") is invalid_numeric); }; +@test fn parse_integers() void = { + let correct: []int = [ + 5, + 34, + -29, + 32498, + ]; + let got = parse_integers("5;34;-29;32498")!; + defer free(got); + for (let index = 0z; index < len(correct); index += 1) { + assert(index < len(got), "ran out"); + let correct = correct[index]; + let got = got[index]; + fmt::printf("[{}]\t[{}]\n", correct, got)!; + assert(correct == got); + }; + assert(len(got) == len(correct), "not done"); + assert(parse_integers("hello;world") is invalid_integer); + assert(parse_integers("5;;") is invalid_integer); + assert(parse_integers(";5;") is invalid_integer); +}; + @test fn string_escaper_next_a() void = { let escaper = escape_string("bird;water;;river;"); let correct: []str = [