package main import ( "net/url" "strings" "testing" ) func TestWeaponTypeClause(t *testing.T) { cases := map[string][]string{ "heavy": {"object_class = 1", "'218103840')::int = 44"}, "light": {"object_class = 1", "= 45"}, "finesse": {"object_class = 1", "= 46"}, "two_handed": {"object_class = 1", "= 41"}, "missile": {"object_class = 9", "'218103840')::int = 47"}, "bow": {"object_class = 9", "'218103840')::int = 47", "'353')::int = 8"}, "crossbow": {"object_class = 9", "'353')::int = 9"}, "thrown": {"object_class = 9", "'353')::int = 10"}, "war": {"object_class = 31", "'159')::int = 34"}, "void": {"object_class = 31", "'159')::int = 43"}, "caster": {"object_class = 31"}, } for wt, subs := range cases { got := weaponTypeClause(wt) for _, s := range subs { if !strings.Contains(got, s) { t.Errorf("weaponTypeClause(%q) = %q, missing %q", wt, got, s) } } } if got := weaponTypeClause("nonsense"); !strings.Contains(got, "object_class IN (1, 9, 31)") { t.Errorf("unknown type = %q, want all-weapons fallback", got) } } func TestWeaponOnlyClause(t *testing.T) { // No types → all weapons. if got := weaponOnlyClause(url.Values{}); !strings.Contains(got, "object_class IN (1, 9, 31)") { t.Errorf("empty = %q, want all weapons", got) } // Single type via weapon_types. got := weaponOnlyClause(url.Values{"weapon_types": {"heavy"}}) if !strings.Contains(got, "= 44") || strings.Contains(got, " OR ") { t.Errorf("single = %q, want just heavy, no OR", got) } // Multiple → parenthesized OR, one clause per type. got = weaponOnlyClause(url.Values{"weapon_types": {"heavy,two_handed,war"}}) if !strings.HasPrefix(got, "(") || !strings.HasSuffix(got, ")") || strings.Count(got, " OR ") != 2 || !strings.Contains(got, "= 44") || !strings.Contains(got, "= 41") || !strings.Contains(got, "= 34") { t.Errorf("multi = %q, want (heavy OR two_handed OR war)", got) } // Legacy weapon_type still honored, deduped against weapon_types. got = weaponOnlyClause(url.Values{"weapon_type": {"missile"}}) if !strings.Contains(got, "object_class = 9") { t.Errorf("legacy weapon_type = %q, want missile", got) } got = weaponOnlyClause(url.Values{"weapon_types": {"heavy"}, "weapon_type": {"heavy"}}) if strings.Contains(got, " OR ") { t.Errorf("dedup = %q, want single heavy clause", got) } }