package wordlist

import (
	"testing"

	"github.com/iliadenisov/alphabet"
)

func TestFoldYo(t *testing.T) {
	if got := FoldYo("ёлка"); got != "елка" {
		t.Errorf("FoldYo(ёлка) = %q, want елка", got)
	}
	if got := FoldYo("Ёжик"); got != "Ежик" {
		t.Errorf("FoldYo(Ёжик) = %q, want Ежик", got)
	}
}

func TestEncodeFilterSortDedupe(t *testing.T) {
	got := Encode([]string{
		"cat", "CATS", "ab", "b", "abcdefghi", "cat", " do ", "qu1rk",
	}, alphabet.Latin(), 2, 8)

	want := [][]byte{
		{0, 1},         // ab
		{2, 0, 19},     // cat
		{2, 0, 19, 18}, // cats (from CATS, case-folded)
		{3, 14},        // do (trimmed)
	}
	if len(got) != len(want) {
		t.Fatalf("got %d words %v, want %d", len(got), got, len(want))
	}
	for i := range want {
		if string(got[i]) != string(want[i]) {
			t.Errorf("word %d = %v, want %v", i, got[i], want[i])
		}
	}
}
