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

// t_symbol_test.go
package expr

import (
	"testing"

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

func TestOperatorEnding(t *testing.T) {
	section := "Symbol"
	inputs := []inputType{
		/*   1 */ {`a++`, false, nil},
		/*   2 */ {`a;`, true, nil},
		/*   3 */ {`a +`, true, nil},
		/*   4 */ {`a + 1`, false, nil},
		/*   5 */ {`a - `, true, nil},
		/*   6 */ {`a( `, true, nil},
		/*   7 */ {`a) `, false, nil},
		/*   8 */ {`++a `, false, nil},
	}

	// testStringArrayEndingWithOperatorSpec(t, section, inputs, 6)
	testStringArrayEndingWithOperator(t, section, inputs)
}

func testStringEndingWithOperator(source string) bool {
	return scan.StringEndsWithOperator(source)
}

// func testStringArrayEndingWithOperatorSpec(t *testing.T, section string, inputs []inputType, spec ...int) {
// 	for i := range spec {
// 		if spec[i] < 1 || spec[i] > len(inputs) {
// 			t.Errorf("Invalid test spec index: %d (must be between 1 and %d)", spec[i], len(inputs))
// 			continue
// 		}
// 		doEndingTest(t, section, inputs[spec[i]-1], spec[i]-1)
// 	}
// }

func testStringArrayEndingWithOperator(t *testing.T, section string, inputs []inputType) {
	for i, input := range inputs {
		doEndingTest(t, section, input, i)
	}
}

func doEndingTest(t *testing.T, section string, input inputType, i int) {
	wantErr := getWantedError(&input)
	logTest(t, i+1, section, input.source, input.wantResult, wantErr)
	gotResult := testStringEndingWithOperator(input.source)
	t.Logf("Is %s op ending? %v", input.source, gotResult)
	if gotResult != input.wantResult.(bool) {
		t.Errorf("%d: `%s` -> result = %v [%s], want = %v [%s]", i+1, input.source, gotResult, kern.TypeName(gotResult), input.wantResult, kern.TypeName(input.wantResult))
	}
}
