#!/usr/bin/env python3 """ Simple verification script to demonstrate that the line splitting bug is fixed. """ from unittest.mock import patch, Mock from pyWebLayout.concrete.text import Line from pyWebLayout.style import Font def test_fix(): """Test that the line splitting fix works correctly""" print("Testing line splitting fix...") font = Font(font_path=None, font_size=12, colour=(0, 0, 0)) # Test case 1: Multi-part hyphenation print("\n1. Testing multi-part hyphenation overflow:") with patch('pyWebLayout.abstract.inline.pyphen') as mock_pyphen_module: mock_dic = Mock() mock_pyphen_module.Pyphen.return_value = mock_dic mock_dic.inserted.return_value = "super-cali-fragi-listic-expiali-docious" line = Line((5, 10), (0, 0), (100, 20), font) overflow = line.add_word("supercalifragilisticexpialidocious") first_part = line.renderable_words[0].word.text if line.renderable_words else "None" print(f" Original word: 'supercalifragilisticexpialidocious'") print(f" Hyphenated to: 'super-cali-fragi-listic-expiali-docious'") print(f" First part added to line: '{first_part}'") print(f" Overflow returned: '{overflow}'") # Verify the fix if overflow == "cali-": print(" ✓ FIXED: Overflow returns only next part") else: print(" ✗ BROKEN: Overflow returns multiple parts joined") return False # Test case 2: Simple two-part hyphenation print("\n2. Testing simple two-part hyphenation:") with patch('pyWebLayout.abstract.inline.pyphen') as mock_pyphen_module: mock_dic = Mock() mock_pyphen_module.Pyphen.return_value = mock_dic mock_dic.inserted.return_value = "very-long" line = Line((5, 10), (0, 0), (40, 20), font) overflow = line.add_word("verylong") first_part = line.renderable_words[0].word.text if line.renderable_words else "None" print(f" Original word: 'verylong'") print(f" Hyphenated to: 'very-long'") print(f" First part added to line: '{first_part}'") print(f" Overflow returned: '{overflow}'") # Verify the fix if overflow == "long": print(" ✓ FIXED: Overflow returns only next part") else: print(" ✗ BROKEN: Overflow behavior incorrect") return False # Test case 3: No overflow case print("\n3. Testing word that fits completely:") line = Line((5, 10), (0, 0), (200, 20), font) overflow = line.add_word("short") first_part = line.renderable_words[0].word.text if line.renderable_words else "None" print(f" Word: 'short'") print(f" Added to line: '{first_part}'") print(f" Overflow: {overflow}") if overflow is None: print(" ✓ CORRECT: No overflow for word that fits") else: print(" ✗ BROKEN: Unexpected overflow") return False print("\n" + "="*50) print("ALL TESTS PASSED - LINE SPLITTING BUG IS FIXED!") print("="*50) return True if __name__ == "__main__": test_fix()