package search import ( "testing" "github.com/stretchr/testify/require" ) func TestDetectClassifiesByScript(t *testing.T) { cases := []struct { name string text string want Lang ok bool }{ {"english prose", "The approved revision is the one a bot reads.", LangEN, true}, {"russian prose", "Одобренная ревизия — это та, которую читает бот.", LangRU, true}, { "russian prose with latin identifiers", "Ревизия хранится в ветке approved, а черновик — в proposals/.", LangRU, true, }, { "english prose with one russian word", "The reviewer approves the merge, sometimes annotated проверено, before it lands.", LangEN, true, }, {"too short to classify", "## API", "", false}, {"digits and punctuation only", "1234-5678 | --- | 9.0", "", false}, {"empty", "", "", false}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { got, ok := Detect(c.text) require.Equal(t, c.ok, ok) require.Equal(t, c.want, got) }) } } func TestDetectInFallsBackWhenUndecidable(t *testing.T) { require.Equal(t, LangRU, DetectIn("## API", LangRU)) require.Equal(t, LangEN, DetectIn("## API", LangEN)) // A decidable text ignores the fallback entirely. require.Equal(t, LangRU, DetectIn("Ревизия хранится в ветке approved.", LangEN)) } func TestRouteSplitsAMixedDocumentByLine(t *testing.T) { text := "Одобренная ревизия — это та, которую читает бот.\n" + "## API\n" + "The approved revision is the one a bot reads and pins.\n" + "Черновики живут в отдельной ветке предложений.\n" ru, en := route(text, LangRU) require.Contains(t, ru, "Одобренная ревизия") require.Contains(t, ru, "Черновики живут") require.NotContains(t, ru, "approved revision is the one") require.Contains(t, en, "The approved revision is the one a bot reads") require.NotContains(t, en, "Одобренная") // The undecidable heading follows the document's language. require.Contains(t, ru, "## API") require.NotContains(t, en, "## API") } func TestRouteLeavesASingleLanguageDocumentWhole(t *testing.T) { text := "The approved revision is the one a bot reads.\nProposals live on their own branch.\n" ru, en := route(text, LangEN) require.Empty(t, ru) require.Equal(t, "The approved revision is the one a bot reads.\nProposals live on their own branch.", en) }