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

// t_builtin-fmt.go
package expr

import (
	// "errors"
	"bytes"
	"fmt"
	"testing"

	"git.portale-stac.it/go-pkg/expr/kern"
)

func TestFuncFmt(t *testing.T) {
	section := "Builtin-Fmt"

	inputs := []inputType{
		/*   1 */ {`builtin "fmt"; print("ciao")`, int64(4), nil},
		/*   2 */ {`builtin "fmt"; println(" ciao")`, int64(6), nil},
	}

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

	// runTestSuiteSpec(t, section, inputs, 1)
	RunTestSuite(t, section, inputs)
}

func TestFmt(t *testing.T) {
	section := "Builtin-Fmt"

	text := "ciao mondo"
	inputs := []inputType{
		/*   1 */ {fmt.Sprintf(`builtin "fmt"; println("%s")`, text), int64(11), nil},
	}

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

	var b bytes.Buffer
	ctx := NewSimpleStore()
	currentStdout := kern.SetCtrl(ctx, kern.ControlStdout, &b)

	RunCtxTestSuite(t, ctx, section, inputs)

	kern.SetCtrl(ctx, kern.ControlStdout, currentStdout)
	if b.String() != text+"\n" {
		t.Errorf("println(): Got: %q, Want: %q", b.String(), text+"\n")
	}
}
