package graph_test

import (
	"testing"

	"github.com/iliadenisov/alphabet"
	dawg "github.com/iliadenisov/dafsa"

	"gitea.iliadenisov.ru/developer/scrabble-solver/internal/graph"
)

// TestSpellSmoke also exercises the go.mod replace => ../dafsa wiring and the new
// dafsa traversal API end-to-end from the solver module.
func TestSpellSmoke(t *testing.T) {
	d := dawg.New(alphabet.Latin())
	for _, w := range []string{"cat", "cats", "dog"} {
		if err := d.Add(w); err != nil {
			t.Fatalf("Add(%q): %v", w, err)
		}
	}
	c, err := dawg.NewCursor(d.Finish())
	if err != nil {
		t.Fatal(err)
	}

	enc := func(s string) []byte {
		b, err := alphabet.Latin().Encode(s)
		if err != nil {
			t.Fatalf("Encode(%q): %v", s, err)
		}
		return b
	}

	if _, final, ok := graph.Spell(c, enc("cat")); !ok || !final {
		t.Errorf("Spell(cat): ok=%v final=%v, want both true", ok, final)
	}
	if _, final, ok := graph.Spell(c, enc("ca")); !ok || final {
		t.Errorf("Spell(ca): ok=%v final=%v, want ok=true final=false", ok, final)
	}
	if _, _, ok := graph.Spell(c, enc("xyz")); ok {
		t.Errorf("Spell(xyz): ok=true, want false")
	}
}
