package ugh

import (
	"testing"
)

func TestKeyBytes(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
		key  Key
		want []byte
	}{
		{"Enter", Enter, []byte{'\r'}},
		{"Tab", Tab, []byte{'\t'}},
		{"ShiftTab", ShiftTab, []byte{0x1b, '[', 'Z'}},
		{"Up", Up, []byte{0x1b, '[', 'A'}},
		{"Down", Down, []byte{0x1b, '[', 'B'}},
		{"Right", Right, []byte{0x1b, '[', 'C'}},
		{"Left", Left, []byte{0x1b, '[', 'D'}},
		{"Space", Space, []byte{0x20}},
		{"Escape", Escape, []byte{0x1b}},
		{"Backspace", Backspace, []byte{0x7f}},
		{"CtrlC", CtrlC, []byte{0x03}},
		{"CtrlA", CtrlA, []byte{0x01}},
		{"CtrlE", CtrlE, []byte{0x05}},
		{"CtrlU", CtrlU, []byte{0x15}},
		{"CtrlK", CtrlK, []byte{0x0b}},
		{"CtrlW", CtrlW, []byte{0x17}},
		{"Home", Home, []byte{0x1b, '[', 'H'}},
		{"End", End, []byte{0x1b, '[', 'F'}},
		{"Delete", Delete, []byte{0x1b, '[', '3', '~'}},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()

			got := tt.key.Bytes()
			if len(got) != len(tt.want) {
				t.Fatalf("got %v, want %v", got, tt.want)
			}
			for i := range got {
				if got[i] != tt.want[i] {
					t.Fatalf("byte %d: got %x, want %x", i, got[i], tt.want[i])
				}
			}
		})
	}
}
