"""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()