package pinyinsearch

import (
	"testing"
)

func TestVariants(t *testing.T) {
	cases := []struct {
		name     string
		input    string
		wantFull string
		wantInit string
	}{
		{"chinese only", "张三", "zhangsan", "zs"},
		{"three chars", "张三丰", "zhangsanfeng", "zsf"},
		{"ascii passthrough", "alice", "alice", "a"},
		{"ascii uppercase", "Alice", "alice", "a"},
		{"mixed ascii and han", "Alice 张", "alicezhang", "az"},
		{"han with digits", "李四123", "lisi123", "ls1"},
		{"spaces dropped", "张 三", "zhangsan", "zs"},
		{"punctuation dropped", "张.三", "zhangsan", "zs"},
		{"emoji dropped", "张😀三", "zhangsan", "zs"},
		{"japanese kana dropped", "田中", "tianzhong", "tz"},
		{"empty", "", "", ""},
		{"ascii only punct", "....", ".", "."},
		{"only emoji", "😀😀", ".", "."},
		{"only whitespace", "   ", ".", "."},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			gotFull, gotInit := Variants(tc.input)
			if gotFull != tc.wantFull {
				t.Errorf("full: got %q want %q", gotFull, tc.wantFull)
			}
			if gotInit != tc.wantInit {
				t.Errorf("initials: got %q want %q", gotInit, tc.wantInit)
			}
		})
	}
}

func TestNormalizeQuery(t *testing.T) {
	cases := []struct {
		name  string
		input string
		want  string
	}{
		{"ascii lowercase", "ZS", "zs"},
		{"ascii passthrough", "zhangsan", "zhangsan"},
		{"mixed whitespace", "  z s ", "zs"},
		{"mixed punct", "z,s", "zs"},
		{"drops cjk", "张z", "z"},
		{"drops emoji", "😀alice", "alice"},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			if got := NormalizeQuery(tc.input); got != tc.want {
				t.Errorf("got %q want %q", got, tc.want)
			}
		})
	}
}
