// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.

// t_builtin-os-file_test.go
package expr

import (
	"testing"
)

// const (
// 	builtinOsFile_dummyFile = "/tmp/.go-test_dummy.txt"
// )

func TestFuncOs(t *testing.T) {
	section := "Builtin-OS-File"
	inputs := []inputType{
		/*   1 */ {`builtin "os.file"`, int64(1), nil},
		/*   2 */ {`builtin "os.file"; handle=fileOpen("/etc/hosts"); fileClose(handle)`, true, nil},
		/*   3 */ {`builtin "os.file"; handle=fileOpen("/etc/hostsX")`, nil, `open /etc/hostsX: no such file or directory`},
		/*   4 */ {`builtin "os.file"; handle=fileCreate("/tmp/dummy"); fileClose(handle)`, true, nil},
		/*   5 */ {`builtin "os.file"; handle=fileAppend("/tmp/dummy"); fileWriteText(handle, "bye-bye"); fileClose(handle)`, true, nil},
		/*   6 */ {`builtin "os.file"; handle=fileOpen("/tmp/dummy"); word=fileReadText(handle, "-"); fileClose(handle);word`, "bye", nil},
		/*   7 */ {`builtin "os.file"; word=fileReadText(nil, "-")`, nil, `fileReadText(): invalid file handle`},
		/*   8 */ {`builtin "os.file"; fileWriteText(nil, "bye")`, nil, `fileWriteText(): invalid file handle`},
		/*   9 */ {`builtin "os.file"; handle=fileOpen()`, nil, `fileOpen(): too few params -- expected 1, got 0`},
		/*  10 */ {`builtin "os.file"; handle=fileOpen(123)`, nil, `fileOpen(): missing or invalid file path`},
		/*  11 */ {`builtin "os.file"; handle=fileCreate(123)`, nil, `fileCreate(): missing or invalid file path`},
		/*  12 */ {`builtin "os.file"; handle=fileAppend(123)`, nil, `fileAppend(): missing or invalid file path`},
		/*  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"; handle=fileOpen("/etc/hosts"); fileClose(handle); string(handle)`, `reader`, nil},
		/*  17 */ {`builtin "os.file"; handle=fileCreate("/tmp/dummy"); fileClose(handle); string(handle)`, `writer`, nil},
	}

	// t.Setenv("EXPR_PATH", ".")

	// RunTestSuiteSpec(t, section, inputs, 17)
	RunTestSuite(t, section, inputs)
}

// func setupBuiltinOsFile() (err error) {
// 	var fh *os.File
// 	// Create test file
// 	if fh, err = os.Create(builtinOsFile_dummyFile); err == nil {
// 		defer fh.Close()
// 		fmt.Fprintln(fh, "uno")
// 		fmt.Fprintln(fh, "due")
// 	}
// 	return
// }

// func cleanupBuiltinOsFile() {
// 	if fileExists(builtinOsFile_dummyFile) {
// 		os.Remove(builtinOsFile_dummyFile)
// 	}
// }
