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

// t_builtin-fmt.go
package expr

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

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(`println("%s")`, text), int64(11), nil},
	}

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

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

	runCtxTestSuite(t, ctx, section, inputs)

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