package country

import "testing"

func TestDetectCountry(t *testing.T) {
	cases := map[string]string{
		"香港 01 | IEPL":       "HK",
		"🇺🇸美国洛杉矶":           "US",
		"日本东京专线":              "JP",
		"Singapore-01":       "SG",
		"KR首尔":               "KR",
		"台湾节点":                "TW",
		"DE法兰克福":              "DE",
		"HK 01":                "HK",
		"墨西哥城 01":             "MX",
		"Mexico City":        "MX",
		"南非 约翰内斯堡":            "ZA",
		"South Africa JNB":   "ZA",
		"新西兰 奥克兰":             "NZ",
		"New Zealand Auckland": "NZ",
		"尼日利亚 拉各斯":            "NG",
		"Nigeria Lagos":      "NG",
		"冰岛 雷克雅未克":            "IS",
		"Iceland Reykjavik":  "IS",
		"random node":        "",
	}
	for name, want := range cases {
		if got := Detect(name); got != want {
			t.Fatalf("%q: want %q got %q", name, want, got)
		}
	}
}

func TestTargetAlias(t *testing.T) {
	code, ok := ParseTargetAlias("country:hk")
	if !ok || code != "HK" {
		t.Fatalf("parse failed: %v %q", ok, code)
	}
	if GroupRuntime("HK") != "country_HK" {
		t.Fatal("group runtime name")
	}
}

func TestCatalogCoverage(t *testing.T) {
	if len(catalog) < 150 {
		t.Fatalf("expected comprehensive catalog, got %d entries", len(catalog))
	}
	for _, e := range catalog {
		if e.Code == "" || e.Name == "" || len(e.Keywords) == 0 {
			t.Fatalf("invalid entry: %+v", e)
		}
		if Name(e.Code) != e.Name {
			t.Fatalf("name mismatch for %s", e.Code)
		}
	}
}
