From f712a49a8c09ce51eed39e446c8fd9c9bff43c4f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 30 Dec 2025 01:02:20 +0900 Subject: [PATCH] added a test case for getline and getbline --- README.md | 7 +++---- lib/utl-sort.c | 4 ++-- t/h-004.hawk | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2a5dbe65..da04ce9a 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ The C++ classes are inferior to the C equivalents in that they don't allow creat ## What Hawk Is -Hawk is an embeddable awk interpreter with extensions. It can run awk scripts from the CLI or from C/C++ and provides modules like `str::`, `sys::`, `ffi::`, `mysql::`, and `sqlite::`. +Hawk is an embeddable awk interpreter with extensions. It can run hawk/awk scripts from the CLI or from C/C++ and provides modules like `str::`, `sys::`, `ffi::`, `mysql::`, and `sqlite::`. ## Running Hawk @@ -282,7 +282,6 @@ $ hawk -f script.hawk one two entry: one two ``` - ## Values and Types Hawk is dynamically typed: @@ -305,8 +304,9 @@ BEGIN { c = 'X' bc = @b'x' bs = @b"\x00\x01" - m = @{"k": 1} + m = @{"k": 1, "j": "hello"} arr = @["x", "y"] + print hawk::typename(a), hawk::typename(b), hawk::typename(s), hawk::typename(c), hawk::typename(bc), hawk::typename(bs), hawk::typename(m), hawk::typename(arr) } ``` @@ -409,7 +409,6 @@ BEGIN { } ``` - ## Functions Define functions with `function name(...) { ... }`. diff --git a/lib/utl-sort.c b/lib/utl-sort.c index e45fdfdd..7a66abc1 100644 --- a/lib/utl-sort.c +++ b/lib/utl-sort.c @@ -136,7 +136,7 @@ static HAWK_INLINE hawk_oob_t* med3x (hawk_oob_t* a, hawk_oob_t* b, hawk_oob_t* } } -void hawk_qsort(void* base, hawk_oow_t nmemb, hawk_oow_t size, hawk_sort_comper_t comper, void* ctx) +void hawk_qsort (void* base, hawk_oow_t nmemb, hawk_oow_t size, hawk_sort_comper_t comper, void* ctx) { hawk_oob_t* pa, * pb, * pc, * pd, * pl, * pm, * pn; int swaptype, swap_cnt; @@ -388,7 +388,7 @@ loop: #define REF(x,i) (&((x)[(i)*size])) -void hawk_qsort(void* base, hawk_oow_t nmemb, hawk_oow_t size, void* arg, +void hawk_qsort (void* base, hawk_oow_t nmemb, hawk_oow_t size, void* arg, int (*compar)(const void*, const void*, void*)) { hawk_oow_t pivot, start, end; diff --git a/t/h-004.hawk b/t/h-004.hawk index 39f05edf..e0ce6631 100644 --- a/t/h-004.hawk +++ b/t/h-004.hawk @@ -3,6 +3,22 @@ @include "tap.inc"; +function run_getline_test() +{ + @local x, b; + + b = "stale ..."; + + ## getlbine must return -1 if the file is not found and reset the variable blank. + x = (getbline b < "/non-existent-dir/non-existent-file.dat"); + tap_ensure(x, -1, @SCRIPTNAME, @SCRIPTLINE); + tap_ensure(b, "", @SCRIPTNAME, @SCRIPTLINE); + + ## getline must return -1 if the file is not found and reset the variable blank. + x = (getline b < "/non-existent-dir/non-existent-file.dat"); + tap_ensure(x, -1, @SCRIPTNAME, @SCRIPTLINE); + tap_ensure(b, "", @SCRIPTNAME, @SCRIPTLINE); +} function run_gc_test () { @@ -31,6 +47,7 @@ function run_gc_test () function main() { + run_getline_test(); run_gc_test(); tap_end (); }