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

// t_bool_test.go
package expr

import (
	"errors"
	"testing"
)

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" do not support operand '[]' [list]`)},
		/*   9 */ {`true and false`, false, nil},
		/*  10 */ {`true and []`, nil, errors.New(`[1:9] left operand 'true' [bool] and right operand '[]' [list] are not compatible with operator "AND"`)},
		/*  11 */ {`[] and false`, nil, errors.New(`got list as left operand type of 'AND' operator, it must be bool`)},
		/*  12 */ {`true or false`, true, nil},
		/*  13 */ {`true or []`, true, nil},
		/*  14 */ {`[] or false`, nil, errors.New(`got list as left operand type of 'OR' operator, it must be bool`)},
		/*  13 */ //{`true or []`, nil, errors.New(`[1:8] left operand 'true' [bool] and right operand '[]' [list] are not compatible with operator "OR"`)},
	}

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

	// runTestSuiteSpec(t, section, inputs, 1)
	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" do not support operand '[]' [list]`},
		/*   9 */ {`true and false`, false, nil},
		/*  10 */ {`true and []`, nil, `[1:9] left operand 'true' [bool] and right operand '[]' [list] are not compatible with operator "AND"`},
		/*  11 */ {`[] and false`, nil, `[1:7] left operand '[]' [list] 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 '[]' [list] are not compatible with operator "OR"`},
		/*  14 */ {`[] or false`, nil, `[1:6] left operand '[]' [list] and right operand 'false' [bool] are not compatible with operator "OR"`},
	}

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

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

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

	SetCtrl(ctx, ControlBoolShortcut, current)
}