package fuzzy
import "testing"
func TestMatch(t *testing.T) {
if !Match("rbd", "rainbond-dashboard") {
t.Fatal("expected fuzzy match")
}
if Match("zzz", "rainbond-dashboard") {
t.Fatal("did not expect unrelated fuzzy match")
}
}
func TestMatchFold(t *testing.T) {
if !MatchFold("rbd", "RainBondDashboard") {
t.Fatal("expected case-insensitive fuzzy match")
}
if MatchFold("zzz", "RainBondDashboard") {
t.Fatal("did not expect unrelated fuzzy match")
}
}
func TestRankMatch(t *testing.T) {
if got := RankMatch("abc", "a-b-c"); got <= 0 {
t.Fatalf("expected positive distance for fuzzy gap, got %d", got)
}
if got := RankMatch("abc", "xyz"); got != -1 {
t.Fatalf("expected -1 for non-match, got %d", got)
}
}
func TestFind(t *testing.T) {
got := Find("api", []string{"api-service", "dashboard", "service-api"})
if len(got) != 2 || got[0] != "api-service" || got[1] != "service-api" {
t.Fatalf("unexpected matches: %#v", got)
}
}
func TestFindFold(t *testing.T) {
got := FindFold("rbd", []string{"RainBondDashboard", "demo", "RBD-API"})
if len(got) != 2 || got[0] != "RainBondDashboard" || got[1] != "RBD-API" {
t.Fatalf("unexpected fold matches: %#v", got)
}
}
func TestRankFind(t *testing.T) {
got := RankFind("api", []string{"api", "service-api", "dashboard"})
if len(got) != 2 {
t.Fatalf("unexpected rank results: %#v", got)
}
if got[0].Distance > got[1].Distance {
t.Fatalf("expected ascending distance ordering, got %#v", got)
}
}
func TestRankFindFold(t *testing.T) {
got := RankFindFold("api", []string{"RBD-API", "Application", "demo"})
if len(got) != 2 {
t.Fatalf("unexpected rank results: %#v", got)
}
if got[0].Distance > got[1].Distance {
t.Fatalf("expected ascending distance ordering, got %#v", got)
}
}