Goal: Fix empty <rPr> elements to achieve 270-272/274 tests
Current: 266/274 (97.1%)
Target: 270-272/274 (98.5-99.3%)
Duration: 1.5-2 hours
Priority: 🔴 CRITICAL
Fix the root cause of ~80% of glossary test failures: <rPr> elements serializing as empty instead of with child elements (fonts, size, etc.).
<w:r>
<w:rPr/> <!-- Empty! Should have child elements -->
<w:t>Some text</w:t>
</w:r><w:r>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:sz w:val="22"/>
<w:color w:val="000000"/>
</w:rPr>
<w:t>Some text</w:t>
</w:r>6 of 8 failing tests are primarily caused by this issue:
- Bibliographies.dotx (12 differences)
- Cover Pages.dotx (24 differences)
- Footers.dotx (191 differences - also has VML)
- Headers.dotx (227 differences - also has VML)
- Table of Contents.dotx (18 differences)
- Tables.dotx (125 differences)
Goal: Understand why <rPr> serializes empty
<read_file> lib/uniword/wordprocessingml/run_properties.rb </read_file>
Check:
- Are
fonts,size,colorattributes defined? ✅ (should be yes) - Are xml mappings correct for these attributes?
- Is
mixed_contentset? ✅ (should be yes) - Are
render_nil: falsesettings correct?
<read_file> lib/uniword/properties/run_fonts.rb </read_file>
Check:
- Are
ascii,h_ansi,cs,east_asiaattributes defined? - Are xml mappings using
map_attribute(notmap_element)? - Is element name
'rFonts'(not'run_fonts')?
<read_file> lib/uniword/properties/font_size.rb </read_file>
Check:
- Is
valueattribute defined? - Is xml mapping using
map_attribute 'val'? - Is element name
'sz'?
Extract glossary XML to see actual output:
cd /Users/mulgogi/src/mn/uniword
# Create test script
cat > /tmp/test_run_properties.rb << 'EOF'
require './lib/uniword'
# Create RunProperties with fonts and size
props = Uniword::Wordprocessingml::RunProperties.new
props.fonts = Uniword::Properties::RunFonts.new(
ascii: 'Calibri',
h_ansi: 'Calibri'
)
props.size = Uniword::Properties::FontSize.new(value: 22)
# Serialize
puts "XML Output:"
puts props.to_xml(pretty: true)
EOF
# Run test
ruby /tmp/test_run_properties.rbExpected Output:
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:sz w:val="22"/>
</w:rPr>If Output Shows Empty <w:rPr/>: Problem confirmed in serialization
Based on investigation, likely issues:
Hypothesis: fonts attribute not properly initialized or mapped
Check 1: Ensure Pattern 0 compliance
# lib/uniword/wordprocessingml/run_properties.rb
class RunProperties < Lutaml::Model::Serializable
# ✅ ATTRIBUTES MUST COME FIRST (Pattern 0)
attribute :fonts, Properties::RunFonts
attribute :size, Properties::FontSize
attribute :color, Properties::ColorValue
# ... other attributes
# ✅ XML MAPPINGS COME AFTER
xml do
element 'rPr'
namespace Uniword::Ooxml::Namespaces::WordProcessingML
mixed_content
# Check these mappings
map_element 'rFonts', to: :fonts, render_nil: false
map_element 'sz', to: :size, render_nil: false
map_element 'color', to: :color, render_nil: false
end
endCheck 2: Verify initialization doesn't override parsed values
def initialize(attrs = {})
super
# ❌ WRONG: @fonts = nil # This would override parsed value!
# ✅ CORRECT: @fonts ||= nil # Only set if not already set
endFix if Needed:
<edit_file> <target_file>lib/uniword/wordprocessingml/run_properties.rb</target_file> Fix RunProperties to ensure fonts, size, and color serialize correctly. Ensure Pattern 0 compliance and proper initialization. <code_edit>
def initialize(attrs = {}) super
@fonts ||= nil # Don't override if already set by parser @size ||= nil @color ||= nil
end