builtin-os-file: add function fileReadIterator() that creates an iterator over lines of a text file

This commit is contained in:
2026-04-23 19:01:07 +02:00
parent 0677180456
commit b6b09b2fb1
5 changed files with 163 additions and 4 deletions
+6 -2
View File
@@ -5,6 +5,7 @@
package expr
import (
"io"
"testing"
)
@@ -26,10 +27,13 @@ func TestFuncOs(t *testing.T) {
/* 13 */ {`builtin "os.file"; handle=fileClose(123)`, nil, `fileClose(): invalid file handle`},
/* 14 */ {`builtin "os.file"; handle=fileOpen("/tmp/dummy"); c=fileReadTextAll(handle); fileClose(handle); c`, "bye-bye", nil},
/* 15 */ {`builtin "os.file"; c=fileReadTextAll(123)`, nil, `fileReadTextAll(): invalid file handle 123 [int64]`},
/* 16 */ {`builtin "os.file"; it=fileReadIterator("test-file.txt"); it++`, "uno", nil},
/* 17 */ {`builtin "os.file"; it=fileReadIterator("test-file.txt"); it++;it++;it++`, nil, io.EOF.Error()},
/* 18 */ {`builtin "os.file"; it=fileReadIterator("test-file.txt"); it.clean`, nil, nil},
}
// t.Setenv("EXPR_PATH", ".")
//runTestSuiteSpec(t, section, inputs, 2)
runTestSuite(t, section, inputs)
runTestSuiteSpec(t, section, inputs, 18)
// runTestSuite(t, section, inputs)
}