import unittest from src.lyricflow_core.api.analysis import analysis_service class TestSpellcheck(unittest.TestCase): def test_unknown_word_detection(self): self.assertFalse(analysis_service.is_known_word("gumguat")) def test_known_word_detection(self): self.assertTrue(analysis_service.is_known_word("combat")) def test_suggestions_for_typo(self): suggestions = analysis_service.spelling_suggestions("helo") self.assertIn("hello", suggestions) def test_suggestions_handle_transposition_typo(self): suggestions = analysis_service.spelling_suggestions("wrod") self.assertIn("word", suggestions) def test_suggestions_handle_common_suffix_typo(self): suggestions = analysis_service.spelling_suggestions("spelle") self.assertTrue("spell" in suggestions or "spelled" in suggestions) def test_autocorrect_candidate_for_typo(self): self.assertEqual("nothing", analysis_service.autocorrect_candidate("nothign")) def test_autocorrect_candidate_rejects_uncertain_word(self): self.assertIsNone(analysis_service.autocorrect_candidate("gumguat")) def test_spelling_issues_respect_lmd_syntax(self): text = "# helo\n[Voice: gumguat]\nhelo world" issues = analysis_service.spelling_issues(text) normalized = [item["normalized"] for item in issues] self.assertIn("helo", normalized) self.assertNotIn("gumguat", normalized) def test_spelling_issues_respect_unclosed_tag(self): text = "[Voice: gumguat\nhelo world" issues = analysis_service.spelling_issues(text) normalized = [item["normalized"] for item in issues] self.assertNotIn("gumguat", normalized) self.assertIn("helo", normalized) if __name__ == "__main__": unittest.main()