package oci

import "testing"

func TestFilterLimitsByName(t *testing.T) {
	values := []LimitValue{
		{Name: "standard-a1-core-count"},
		{Name: "standard-e2-core-count"},
		{Name: "standard-a1-memory-count"},
		{Name: "vm-standard2-1-count"},
	}
	tests := []struct {
		name      string
		filter    string
		wantNames []string
	}{
		{
			name:      "空过滤返回全部",
			filter:    "",
			wantNames: []string{"standard-a1-core-count", "standard-e2-core-count", "standard-a1-memory-count", "vm-standard2-1-count"},
		},
		{
			name:      "模糊匹配 core-count",
			filter:    "core-count",
			wantNames: []string{"standard-a1-core-count", "standard-e2-core-count"},
		},
		{
			name:      "大小写不敏感",
			filter:    "CORE-Count",
			wantNames: []string{"standard-a1-core-count", "standard-e2-core-count"},
		},
		{
			name:      "前后空白被忽略",
			filter:    " a1 ",
			wantNames: []string{"standard-a1-core-count", "standard-a1-memory-count"},
		},
		{
			name:      "精确名仍可命中",
			filter:    "standard-a1-core-count",
			wantNames: []string{"standard-a1-core-count"},
		},
		{
			name:      "无匹配返回空",
			filter:    "gpu",
			wantNames: []string{},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := filterLimitsByName(values, tt.filter)
			gotNames := make([]string, 0, len(got))
			for _, v := range got {
				gotNames = append(gotNames, v.Name)
			}
			if len(gotNames) != len(tt.wantNames) {
				t.Fatalf("filterLimitsByName(%q) = %v, want %v", tt.filter, gotNames, tt.wantNames)
			}
			for i := range gotNames {
				if gotNames[i] != tt.wantNames[i] {
					t.Errorf("filterLimitsByName(%q)[%d] = %q, want %q", tt.filter, i, gotNames[i], tt.wantNames[i])
				}
			}
		})
	}
}
