package door

import (
	"reflect"
	"testing"
)

func TestBoxUnicode(t *testing.T) {
	// verify that the BOXES_CP437 matches BOXES_UNICODE
	for idx, bs := range BOXES_CP437 {

		fields := reflect.VisibleFields(reflect.TypeOf(bs))
		bs_value := reflect.ValueOf(bs)
		u_value := reflect.ValueOf(BOXES_UNICODE[idx])

		for _, sf := range fields {
			name := sf.Name
			// cp437 := reflect.ValueOf(bs).FieldByName(name).String()
			cp437 := bs_value.FieldByName(name).String()
			convert := CP437_to_Unicode(cp437)
			// unicode := reflect.ValueOf(BOXES_UNICODE[idx]).FieldByName(name).String()
			unicode := u_value.FieldByName(name).String()
			if convert != unicode {
				t.Errorf("BOXES %s [%d]: %#v != %#v\n", name, idx, convert, unicode)
			}
			// t.Fatalf("Name: %s, v: %s\n", name, cp437)
		}
	}
}

func TestBoxes(t *testing.T) {
	// Normally done in door.init.
	Unicode = true
	BOXES = BOXES_UNICODE

	box := Box{5, 0}
	got := box.Top()
	expected := "\u250c\u2500\u2500\u2500\u2500\u2500\u2510"
	if got != expected {
		t.Errorf("Boxes Top (0): Expected %#v, got %#v", got, expected)
	}

	got = box.Middle()
	expected = "\u251c\u2500\u2500\u2500\u2500\u2500\u2524"
	if got != expected {
		t.Errorf("Boxes Middle (0): Expected %#v, got %#v", got, expected)
	}

	got = box.Bottom()
	expected = "\u2514\u2500\u2500\u2500\u2500\u2500\u2518"
	if got != expected {
		t.Errorf("Boxes Bottom (0): Expected %#v, got %#v", got, expected)
	}

	got = box.Row("12345")
	expected = "\u250212345\u2502"
	if got != expected {
		t.Errorf("Boxes Row (0): Expected %#v, got %#v", got, expected)
	}

	alert := AlertBox("ALERT", 1)
	lines := []string{"\u2554\u2550\u2550\u2550\u2550\u2550\u2557", "\u2551ALERT\u2551", "\u255a\u2550\u2550\u2550\u2550\u2550\u255d"}
	for idx, line := range alert {
		if line != lines[idx] {
			t.Errorf("AlertBox (%d): Expected %#v, got %#v", idx, line, lines[idx])
		}
	}
}