From 0f293fdbbc2b3677fd76c7e8cbda08fc7f463ded Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Mon, 11 May 2026 14:01:22 +0200 Subject: [PATCH] restructured some test files --- t_builtin-os-file_test.go | 21 ++++++++++++++++----- t_common_test.go | 12 +++++++++--- t_iter-iter_test.go | 10 +++++----- t_iterator_test.go | 2 +- t_operator_test.go | 4 ++-- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/t_builtin-os-file_test.go b/t_builtin-os-file_test.go index 357a9a1..7d9d9c2 100644 --- a/t_builtin-os-file_test.go +++ b/t_builtin-os-file_test.go @@ -33,13 +33,24 @@ func TestFuncOs(t *testing.T) { /* 19 */ {`builtin "os.file"; it=fileLineIterator("test-file.txt"); string(it)`, `$(fileLineIterator@"test-file.txt")`, nil}, /* 20 */ {`builtin "os.file"; handle=fileOpen("/etc/hosts"); fileClose(handle); string(handle)`, `reader`, nil}, /* 21 */ {`builtin "os.file"; handle=fileCreate("/tmp/dummy"); fileClose(handle); string(handle)`, `writer`, nil}, - /* 22 */ {`builtin "os.file"; it=fileByteIterator("test-file.txt"); string(it)`, `$(fileByteIterator@"test-file.txt")`, nil}, - /* 23 */ {`builtin ["os.file", "string"]; it=fileByteIterator("test-file.txt"); char(it++)`, `u`, nil}, - /* 24 */ {`builtin ["os.file", "string"]; it=fileByteIterator("test-file.txt"); it++; it.reset; char(it++)`, `u`, nil}, } // t.Setenv("EXPR_PATH", ".") - runTestSuiteSpec(t, section, inputs, 24) - // runTestSuite(t, section, inputs) + // runTestSuiteSpec(t, section, inputs, 24) + runTestSuite(t, section, inputs) +} + +func TestFuncOsByteIter(t *testing.T) { + section := "Builtin-OS-File-Byte-Iter" + inputs := []inputType{ + /* 1 */ {`builtin "os.file"; it=fileByteIterator("test-file.txt"); string(it)`, `$(fileByteIterator@"test-file.txt")`, nil}, + /* 2 */ {`builtin ["os.file", "string"]; it=fileByteIterator("test-file.txt"); char(it++)`, `u`, nil}, + /* 3 */ {`builtin ["os.file", "string"]; it=fileByteIterator("test-file.txt"); it++; it.reset; char(it++)`, `u`, nil}, + } + + // t.Setenv("EXPR_PATH", ".") + + // runTestSuiteSpec(t, section, inputs, 24) + runTestSuite(t, section, inputs) } diff --git a/t_common_test.go b/t_common_test.go index c7a6b6d..54db18d 100644 --- a/t_common_test.go +++ b/t_common_test.go @@ -23,11 +23,17 @@ func runCtxTestSuiteSpec(t *testing.T, ctx kern.ExprContext, section string, inp succeeded := 0 failed := 0 for _, count := range spec { - good := doTest(t, ctx, section, &inputs[count-1], count) + index := count - 1 + if index >= 0 && index < len(inputs) { + good := doTest(t, ctx, section, &inputs[index], count) - if good { - succeeded++ + if good { + succeeded++ + } else { + failed++ + } } else { + t.Errorf("%s -- test count: %d, invalid index", section, count) failed++ } } diff --git a/t_iter-iter_test.go b/t_iter-iter_test.go index ac4e88e..b8945e5 100644 --- a/t_iter-iter_test.go +++ b/t_iter-iter_test.go @@ -11,16 +11,16 @@ import ( ) func TestIterIterator(t *testing.T) { - section := "Iterator" + section := "Iter-Iter" inputs := []inputType{ - /* 1 */ {`it=$(4); $(it) filter ${_}==100`, kern.NewListA(), nil}, - /* 2 */ {`it=$(4); $(it, $_) filter ${_}==100`, kern.NewListA(), nil}, + /* 1 */ {`it=$(4); $$($(it) filter ${_}==100)`, kern.NewListA(), nil}, + /* 2 */ {`it=$(4); $$($(it, $_) filter ${_}==100)`, kern.NewListA(), nil}, /* 3 */ {`it=$(4); $(it, 10+$_, last-1) digest ${_}`, int64(12), nil}, /* 4 */ {`f=func(n){last-n}; it=$(4); $(it, 10+$_, f(-1)) digest ${_}`, int64(14), nil}, } - runTestSuiteSpec(t, section, inputs, 4) - // runTestSuite(t, section, inputs) + // runTestSuiteSpec(t, section, inputs, 4) + runTestSuite(t, section, inputs) } // func TestNewIterIterator(t *testing.T) { diff --git a/t_iterator_test.go b/t_iterator_test.go index af2bede..6a0a9ca 100644 --- a/t_iterator_test.go +++ b/t_iterator_test.go @@ -37,7 +37,7 @@ func TestIteratorParser(t *testing.T) { /* 22 */ {`it=$({1:"one",2:"two",3:"three"}, "asc", "item"); it++`, kern.NewList([]any{int64(1), "one"}), nil}, } - // runTestSuiteSpec(t, section, inputs, 10) + // runTestSuiteSpec(t, section, inputs, 1) runTestSuite(t, section, inputs) } diff --git a/t_operator_test.go b/t_operator_test.go index 1d169fd..2a44143 100644 --- a/t_operator_test.go +++ b/t_operator_test.go @@ -80,6 +80,6 @@ func TestOperatorGroupBy(t *testing.T) { nil}, } - runTestSuiteSpec(t, section, inputs, 3) - // runTestSuite(t, section, inputs) + // runTestSuiteSpec(t, section, inputs, 3) + runTestSuite(t, section, inputs) }