package dict

import (
	"reflect"
	"testing"
)

func TestNew(t *testing.T) {
	d := New()
	if d == nil {
		t.Error("New() should not return nil")
	}
	if len(d) != 0 {
		t.Errorf("New() should return an empty dict, got %v", d)
	}
}

func TestIsDict(t *testing.T) {
	d := Dict{
		"key1": "value1",
	}

	r := IsDict(d)
	if !r {
		t.Errorf("Expected true, got %v", r)
	}

	r = IsDict(12)
	if r {
		t.Errorf("Expected false, got %v", r)
	}

	r = IsDict("Cool!")
	if r {
		t.Errorf("Expected false, got %v", r)
	}

	var v1 interface{}
	r = IsDict(v1)
	if r {
		t.Errorf("Expected false, got %v", r)
	}

	var v2 []interface{}
	r = IsDict(v2)
	if r {
		t.Errorf("Expected false, got %v", r)
	}

	var v3 map[string]interface{}
	r = IsDict(v3)
	if r {
		t.Errorf("Expected false, got %v", r)
	}
}

func TestGetInheritedValue(t *testing.T) {
	testCases := []dictStrToDictTestCase{}
	loadYamlFile("test_data/getvalue_cases.yaml", &testCases)
	for _, testCase := range testCases {
		copy := make(Dict)
		copy.CopyFrom(testCase.Arg1)
		result := testCase.Arg1.GetInheritedValue(testCase.Arg2)
		if !reflect.DeepEqual(testCase.Result, result) {
			t.Errorf("Expected dict to be %v, got %v", testCase.Result, result)
		}
		if !reflect.DeepEqual(testCase.Arg1, copy) {
			t.Errorf("Expected dict to be %v, got %v", copy, testCase.Arg1)
		}
	}
}