hare

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

commit 587a99423d7340d037fbeb2d40b3797b935c991b
parent 88ee0e0928dd7d4ea07b0c2051739e46e17fd345
Author: Vlad-Stefan Harbuz <vlad@vladh.net>
Date:   Tue, 17 May 2022 17:42:28 +0100

regex: release memory in tests

Fixes https://todo.sr.ht/~sircmpwn/hare/707

Signed-off-by: Vlad-Stefan Harbuz <vlad@vladh.net>

Diffstat:
Mregex/+test.ha | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/regex/+test.ha b/regex/+test.ha @@ -31,6 +31,7 @@ fn run_find_case( fmt::fatalf("Expected expression /{}/ to have error caught during compilation, but it did not", expr); }; + defer finish(&re); match (find(&re, string)) { case void => @@ -39,18 +40,19 @@ fn run_find_case( expr, string); }; - case let m: []capture => + case let captures: []capture => + defer free_captures(captures); if (expected == matchres::NOMATCH) { fmt::fatalf("Expected expression /{}/ to not match string \"{}\", but it did", expr, string); }; - if (start: size != m[0].start) { + if (start: size != captures[0].start) { fmt::fatalf("Expected start of main capture to be {} but it was {}", - start, m[0].start); + start, captures[0].start); }; - if (end: size != m[0].end) { + if (end: size != captures[0].end) { fmt::fatalf("Expected end of main capture to be {} but it was {}", - end, m[0].end); + end, captures[0].end); }; }; }; @@ -76,6 +78,7 @@ fn run_findall_case( }; return; }; + defer finish(&re); if (expected == matchres::ERROR) { fmt::fatalf("Expected expression /{}/ to have error caught during compilation, but it did not", @@ -89,14 +92,15 @@ fn run_findall_case( expr, string); }; - case let groupsets: [][]capture => + case let matches: [][]capture => + defer free_matches(matches); if (expected == matchres::NOMATCH) { fmt::fatalf("Expected expression /{}/ to not match string \"{}\", but it did", expr, string); }; - if (count: size != len(groupsets)) { + if (count: size != len(matches)) { fmt::fatalf("Expected to find {} matches but found {}", - count, len(groupsets)); + count, len(matches)); }; }; };