hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3b095c26ab8f8437e9013b08de27535b8e9ea9da
parent fd269b13cae1b1a972877b8ca48ef351aaa63bed
Author: Sebastian <sebastian@sebsite.pw>
Date:   Mon, 27 Nov 2023 01:18:17 -0500

bytes: improve tests style and add test

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mbytes/contains.ha | 44++++++++++++--------------------------------
Mbytes/trim.ha | 2+-
2 files changed, 13 insertions(+), 33 deletions(-)

diff --git a/bytes/contains.ha b/bytes/contains.ha @@ -23,22 +23,12 @@ export fn hasprefix(in: []u8, prefix: []u8) bool = { }; @test fn hasprefix() void = { - const cases: []([]u8, []u8, bool) = [ - ([], [], true), - ([0], [], true), - ([], [0], false), - ([1, 2, 3], [1, 2], true), - ([1, 2, 3], [1, 1], false), - ([1, 2, 3], [1, 2, 3, 4], false), - ]; - - for (let i = 0z; i < len(cases); i += 1) { - let s = cases[i].0; - let prefix = cases[i].1; - let expected = cases[i].2; - let actual = hasprefix(s, prefix); - assert(actual == expected); - }; + assert(hasprefix([], [])); + assert(hasprefix([0], [])); + assert(!hasprefix([], [0])); + assert(hasprefix([1, 2, 3], [1, 2])); + assert(!hasprefix([1, 2, 3], [1, 1])); + assert(!hasprefix([1, 2, 3], [1, 2, 3, 4])); }; // Returns true if "in" has the given suffix, false otherwise @@ -48,20 +38,10 @@ export fn hassuffix(in: []u8, suffix: []u8) bool = { }; @test fn hassuffix() void = { - const cases: []([]u8, []u8, bool) = [ - ([], [], true), - ([0], [], true), - ([], [0], false), - ([1, 2, 3], [2, 3], true), - ([1, 2, 3], [2, 2], false), - ([1, 2, 3, 4], [2, 3, 4], true), - ]; - - for (let i = 0z; i < len(cases); i += 1) { - let s = cases[i].0; - let prefix = cases[i].1; - let expected = cases[i].2; - let actual = hassuffix(s, prefix); - assert(actual == expected); - }; + assert(hassuffix([], [])); + assert(hassuffix([0], [])); + assert(!hassuffix([], [0])); + assert(hassuffix([1, 2, 3], [2, 3])); + assert(!hassuffix([1, 2, 3], [2, 2])); + assert(hassuffix([1, 2, 3, 4], [2, 3, 4])); }; diff --git a/bytes/trim.ha b/bytes/trim.ha @@ -26,5 +26,5 @@ export fn trim(in: []u8, trim: u8...) []u8 = ltrim(rtrim(in, trim...), trim...); assert(equal(trim([1, 2, 3, 5], 0), [1, 2, 3, 5])); assert(equal(trim([0, 0, 0], 0), [])); assert(equal(trim([0, 5, 0], 5), [0, 5, 0])); + assert(equal(trim([], 0), [])); }; -