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

// t_bool_test.go
package expr

import (
	"errors"
	"testing"

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

func TestBool(t *testing.T) {
	section := "Bool"
	inputs := []inputType{
		/*   1 */ {`true`, true, nil},
		/*   2 */ {`false`, false, nil},
		/*   3 */ {`not false`, true, nil},
		/*   4 */ {`not 1`, false, nil},
		/*   5 */ {`not "true"`, false, nil},
		/*   6 */ {`not "false"`, false, nil},
		/*   7 */ {`not ""`, true, nil},
		/*   8 */ {`not []`, nil, errors.New(`[1:4] prefix/postfix operator "NOT" does not support operand '[]' [array]`)},
		/*   9 */ {`true and false`, false, nil},
		/*  10 */ {`true and []`, nil, errors.New(`[1:9] left operand 'true' [bool] and right operand '[]' [array] are not compatible with operator "AND"`)},
		/*  11 */ {`[] and false`, nil, errors.New(`[1:7] operator "AND" does not support operand '[]' [array] on its left side`)},
		/*  12 */ {`true or false`, true, nil},
		/*  13 */ {`true or []`, true, nil},
		/*  14 */ {`[] or false`, nil, errors.New(`got array as left operand type of 'OR' operator, it must be bool`)},
		/*  15 */ {`!true`, false, nil},
		/*  13 */ //{`true or []`, nil, errors.New(`[1:8] left operand 'true' [bool] and right operand '[]' [array] are not compatible with operator "OR"`)},
	}

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

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

func TestBoolNoShortcut(t *testing.T) {
	section := "Bool-NoShortcut"
	inputs := []inputType{
		/*   1 */ {`true`, true, nil},
		/*   2 */ {`false`, false, nil},
		/*   3 */ {`not false`, true, nil},
		/*   4 */ {`not 1`, false, nil},
		/*   5 */ {`not "true"`, false, nil},
		/*   6 */ {`not "false"`, false, nil},
		/*   7 */ {`not ""`, true, nil},
		/*   8 */ {`not []`, nil, `[1:4] prefix/postfix operator "NOT" does not support operand '[]' [array]`},
		/*   9 */ {`true and false`, false, nil},
		/*  10 */ {`true and []`, nil, `[1:9] left operand 'true' [bool] and right operand '[]' [array] are not compatible with operator "AND"`},
		/*  11 */ {`[] and false`, nil, `[1:7] left operand '[]' [array] and right operand 'false' [bool] are not compatible with operator "AND"`},
		/*  12 */ {`true or false`, true, nil},
		/*  13 */ {`true or []`, nil, `[1:8] left operand 'true' [bool] and right operand '[]' [array] are not compatible with operator "OR"`},
		/*  14 */ {`[] or false`, nil, `[1:6] left operand '[]' [array] and right operand 'false' [bool] are not compatible with operator "OR"`},
	}

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

	ctx := NewSimpleStore()
	current := kern.SetCtrl(ctx, kern.ControlBoolShortcut, false)

	// runCtxTestSuiteSpec(t, ctx, section, inputs, 1)
	RunCtxTestSuite(t, ctx, section, inputs)

	kern.SetCtrl(ctx, kern.ControlBoolShortcut, current)
}
