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

// t_list_test.go
package expr

import (
	"testing"

	"git.portale-stac.it/go-pkg/expr/types/array"
	"git.portale-stac.it/go-pkg/expr/types/list"
)

func TestLinkedListParser(t *testing.T) {
	section := "Linked-List"

	inputs := []inputType{
		/*   1 */ {`[<1,2>]`, list.NewLinkedListA(1, 2), nil},
		/*   2 */ {`it=$([<1,2,3>]); it++`, int64(1), nil},
		/*   3 */ {`it=$([<1,2,3>]); #($$(it))`, int64(3), nil},
		/*   4 */ {`[<1,2,3>][0]`, int64(1), nil},
		/*   5 */ {`[<1,2,3>][0..2]`, list.NewLinkedListA(1, 2), nil},
		/*   6 */ {`[<1>] + [<2,3>]`, list.NewLinkedListA(1, 2, 3), nil},
		/*   7 */ {`L=[<1>] + [<2,3>]; L[0]=100; L`, list.NewLinkedListA(100, 2, 3), nil},
		/*   8 */ {`builtin "base"; L=[<1>]; isList(L)`, true, nil},
		/*   9 */ {`2 IN [<1,2,3>]`, true, nil},
		/*  10 */ {`2 AT [<1,2,3>]`, int64(1), nil},
		/*  11 */ {`4 AT [<1,2,3>]`, int64(-1), nil},
	}

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

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

func TestLinkedInsert(t *testing.T) {
	section := "LinkedList-Insert"
	inputs := []inputType{
		/*  1 */ {`[<>] << 1`, list.NewLinkedListA(1), nil},
		/*  2 */ {`[<>] << [1,2]`, list.NewLinkedListA(array.ArrayFromIntsA(1, 2)), nil},
		/*  3 */ {`[<>] << [<1,2>]`, list.NewLinkedListA(list.NewLinkedListA(1, 2)), nil},
		/*  4 */ {`1 >> [<>]`, list.NewLinkedListA(1), nil},
		/*  5 */ {`[1,2] >> [<>]`, list.NewLinkedListA(array.ArrayFromIntsA(1, 2)), nil},
		/*  6 */ {`[<1,2>] >> [<>]`, list.NewLinkedListA(list.NewLinkedListA(1, 2)), nil},
		/*  7 */ {`$([1,2]) >> [<>]`, list.NewLinkedListA(1, 2), nil},
		/*  8 */ {`$([<1,2>]) >> [<>]`, list.NewLinkedListA(1, 2), nil},
	}

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