package form

import (
	"testing"
)

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

	validate := notEmpty("thing")

	tests := []struct {
		name    string
		input   string
		wantErr bool
	}{
		{name: "empty string", input: "", wantErr: true},
		{name: "non-empty string", input: "hello", wantErr: false},
		{name: "whitespace only", input: "  ", wantErr: true},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			err := validate(tt.input)
			if (err != nil) != tt.wantErr {
				t.Errorf("notEmpty(%q): got err=%v, wantErr=%v", tt.input, err, tt.wantErr)
			}
		})
	}
}

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

	tests := []struct {
		name  string
		input string
		want  []string
	}{
		{name: "empty", input: "", want: nil},
		{name: "single path", input: "/home/user", want: []string{"/home/user"}},
		{name: "two paths", input: "/home/user /etc", want: []string{"/home/user", "/etc"}},
		{name: "leading whitespace", input: "  /home", want: []string{"/home"}},
		{name: "trailing whitespace", input: "/home  ", want: []string{"/home"}},
		{name: "tabs", input: "/a\t/b", want: []string{"/a", "/b"}},
		{name: "multiple spaces", input: "/a   /b   /c", want: []string{"/a", "/b", "/c"}},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			got := splitFields(tt.input)
			if len(got) != len(tt.want) {
				t.Fatalf("splitFields(%q): got %v, want %v", tt.input, got, tt.want)
			}
			for i := range got {
				if got[i] != tt.want[i] {
					t.Errorf("splitFields(%q)[%d]: got %q, want %q", tt.input, i, got[i], tt.want[i])
				}
			}
		})
	}
}
