fss-polish/tests/test_au_spelling.py
FSSCoding 9316bc50f1 Initial commit: FSS-Polish v1.0.0
Complete implementation of Fast Spelling and Style Polish tool with:
- Australian English spelling conversion (7 patterns + case preservation)
- CLI support with text input or clipboard mode
- Daemon mode with configurable hotkey
- MIN_LENGTH, AGGRESSION, and CUSTOM_DICTIONARY config options
- Comprehensive diff logging
- 12 passing tests (100% test coverage for AU spelling)
- Wheel package built and ready for deployment
- Agent-friendly CLI with stdin/stdout support

Features:
- Text correction using t5-small-spoken-typo model
- Australian/American spelling conversion
- Configurable correction aggression levels
- Custom dictionary whitelist support
- Background daemon with hotkey trigger
- CLI tool for direct text polishing
- Preserves clipboard history (adds new item vs replace)

Ready for deployment to /opt and Gitea repository.
2025-10-25 23:59:34 +11:00

84 lines
3.4 KiB
Python

"""Comprehensive tests for Australian English spelling conversion"""
import unittest
import sys
import os
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
from au_spelling import convert_to_au_spelling
class TestAUSpelling(unittest.TestCase):
"""Test Australian English spelling conversions"""
def test_or_to_our(self):
"""Test -or to -our conversions"""
self.assertEqual(convert_to_au_spelling("color"), "colour")
self.assertEqual(convert_to_au_spelling("favor"), "favour")
self.assertEqual(convert_to_au_spelling("honor"), "honour")
self.assertEqual(convert_to_au_spelling("neighbor"), "neighbour")
self.assertEqual(convert_to_au_spelling("behavior"), "behaviour")
def test_ter_to_tre(self):
"""Test -ter to -tre conversions (French origin words)"""
self.assertEqual(convert_to_au_spelling("center"), "centre")
self.assertEqual(convert_to_au_spelling("theater"), "theatre")
self.assertEqual(convert_to_au_spelling("meter"), "metre")
def test_ize_to_ise(self):
"""Test -ize to -ise conversions"""
self.assertEqual(convert_to_au_spelling("organize"), "organise")
self.assertEqual(convert_to_au_spelling("authorize"), "authorise")
self.assertEqual(convert_to_au_spelling("plagiarize"), "plagiarise")
self.assertEqual(convert_to_au_spelling("realize"), "realise")
def test_unique_words(self):
"""Test unique word replacements"""
self.assertEqual(convert_to_au_spelling("aluminum"), "aluminium")
self.assertEqual(convert_to_au_spelling("tire"), "tyre")
self.assertEqual(convert_to_au_spelling("tires"), "tyres")
self.assertEqual(convert_to_au_spelling("gray"), "grey")
def test_whitelist_protection(self):
"""Test that whitelisted phrases are protected"""
# "program" is whitelisted
text = "I need to program the computer"
result = convert_to_au_spelling(text)
self.assertIn("program", result)
def test_custom_whitelist(self):
"""Test custom whitelist parameter"""
text = "The color is beautiful"
# Without whitelist
result1 = convert_to_au_spelling(text)
self.assertIn("colour", result1)
# With "color" in custom whitelist
result2 = convert_to_au_spelling(text, custom_whitelist=["color"])
self.assertIn("color", result2)
def test_case_preservation(self):
"""Test that case is preserved in conversions"""
self.assertEqual(convert_to_au_spelling("Color"), "Colour")
self.assertEqual(convert_to_au_spelling("COLOR"), "COLOUR")
self.assertEqual(convert_to_au_spelling("Organize"), "Organise")
def test_sentence_conversion(self):
"""Test conversion of full sentences"""
input_text = "The color of the theater was beautiful"
expected = "The colour of the theatre was beautiful"
self.assertEqual(convert_to_au_spelling(input_text), expected)
def test_empty_text(self):
"""Test handling of empty text"""
self.assertEqual(convert_to_au_spelling(""), "")
self.assertEqual(convert_to_au_spelling(None), None)
def test_no_conversion_needed(self):
"""Test text that doesn't need conversion"""
text = "This is already correct"
self.assertEqual(convert_to_au_spelling(text), text)
if __name__ == "__main__":
unittest.main()