package main

import (
	"reflect"
	"testing"
)

func TestShort_Unit(t *testing.T) {
	t.Parallel()
	t.Log("✓ Fast Short unit test")

	tests := []struct {
		name     string
		input    string
		maxLen   int
		expected string
	}{
		{
			name:     "short_string",
			input:    "abc",
			maxLen:   5,
			expected: "abc",
		},
		{
			name:     "exact_length",
			input:    "abcde",
			maxLen:   5,
			expected: "abcde",
		},
		{
			name:     "truncate_long",
			input:    "this is a very long string that needs truncation",
			maxLen:   10,
			expected: "this is a ",
		},
		{
			name:     "truncate_unicode",
			input:    "こんにちは世界",
			maxLen:   5,
			expected: "こんにちは",
		},
		{
			name:     "zero_length",
			input:    "hello",
			maxLen:   0,
			expected: "",
		},
		{
			name:     "empty_string",
			input:    "",
			maxLen:   10,
			expected: "",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := Short(tt.input, tt.maxLen)
			if result != tt.expected {
				t.Errorf("Short(%q, %d) = %q, want %q", tt.input, tt.maxLen, result, tt.expected)
			}
		})
	}
}

func TestQuit_Unit(t *testing.T) {
	t.Parallel()
	t.Log("✓ Fast Quit unit test")

	// Can't meaningfully test os.Exit(0) in unit tests as it terminates the process
	// This serves as a marker that the function exists and is pure side-effect
	t.Run("exists", func(t *testing.T) {
		// Verify function exists (compile-time check via reflect)
		if reflect.ValueOf(Quit).IsNil() {
			t.Error("Quit function is nil")
		}
	})
}

func TestRadioMenu_Unit(t *testing.T) {
	t.Parallel()
	t.Log("✓ Fast RadioMenu unit test")

	tests := []struct {
		name     string
		stations []stationRecord
		wantMenu bool
	}{
		{
			name:     "empty_stations",
			stations: []stationRecord{},
			wantMenu: true,
		},
		{
			name: "single_station",
			stations: []stationRecord{
				{Name: "Test Station", Codec: "MP3", Bitrate: "128", Url: "http://test.com"},
			},
			wantMenu: true,
		},
		{
			name: "multiple_stations",
			stations: []stationRecord{
				{Name: "Station One Very Long Name That Will Be Truncated", Codec: "AAC", Bitrate: "256", Url: "http://one.com"},
				{Name: "Station Two", Codec: "MP3", Bitrate: "128", Url: "http://two.com"},
			},
			wantMenu: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			menu := RadioMenu(tt.stations)
			if menu == nil {
				if tt.wantMenu {
					t.Errorf("RadioMenu(%v) returned nil, want non-nil menu", tt.stations)
				}
				return
			}
			if !tt.wantMenu {
				t.Errorf("RadioMenu(%v) returned non-nil menu, want nil", tt.stations)
			}
		})
	}
}
