package main

import "testing"

func TestHasCyrillic(t *testing.T) {
	for _, s := range []string{"что такое фотосинтез", "кто такой Elon Musk", "фотосинтез"} {
		if !hasCyrillic(s) {
			t.Errorf("hasCyrillic(%q) = false; it is a Russian question", s)
		}
	}
	for _, s := range []string{"what is photosynthesis", "", "3:2"} {
		if hasCyrillic(s) {
			t.Errorf("hasCyrillic(%q) = true; there is no Cyrillic in it", s)
		}
	}
}

// The book choice and the rewrite decision are the same decision: a Russian
// book reads his question as he asked it, an English one needs it translated
// into keywords first (V-508).
func TestKiwixBookChoice(t *testing.T) {
	for _, tc := range []struct {
		name      string
		wiring    kiwixWiring
		utterance string
		wantBook  string
		wantVerb  bool
	}{
		{"a russian question reads the russian book verbatim",
			kiwixWiring{book: "en", bookRU: "ru"}, "что такое фотосинтез", "ru", true},
		{"an english question reads the english book",
			kiwixWiring{book: "en", bookRU: "ru"}, "what is photosynthesis", "en", false},
		{"no russian book configured leaves every question on the english one",
			kiwixWiring{book: "en"}, "что такое фотосинтез", "en", false},
	} {
		book, verbatim := tc.wiring.book, false
		if tc.wiring.bookRU != "" && hasCyrillic(tc.utterance) {
			book, verbatim = tc.wiring.bookRU, true
		}
		if book != tc.wantBook || verbatim != tc.wantVerb {
			t.Errorf("%s: book=%q verbatim=%v, want %q/%v", tc.name, book, verbatim, tc.wantBook, tc.wantVerb)
		}
	}
}
