Enhanced all assertion messages in cmap_unmapped_glyphs.rs to follow a consistent pattern: - What was expected - What was found - Why this matters Modified tests: - test_cmap_unmapped_glyph_skip: Added detailed messages for unmapped checks, map validation, and lookups - test_cmap_multiple_mappings_with_unmapped_check: Enhanced mapping verification messages - test_cmap_range_mapping_with_unmapped_awareness: Improved range expansion and boundary check messages All 7 tests pass successfully. Assertion messages now provide maximally helpful diagnostics when failures occur. Verification: notes/bf-18a0w.md
123 lines
5.2 KiB
Markdown
123 lines
5.2 KiB
Markdown
# Verification Note for bf-18a0w: Improve Assertion Messages and Verify Test Correctness
|
|
|
|
## Summary
|
|
Improved assertion messages across all tests in `cmap_unmapped_glyphs.rs` to provide maximally helpful failure diagnostics. All 7 tests pass successfully.
|
|
|
|
## Changes Made
|
|
|
|
### File Modified
|
|
- `crates/pdftract-core/tests/cmap_unmapped_glyphs.rs`
|
|
|
|
### Assertion Message Improvements
|
|
|
|
#### Test 1: `test_cmap_unmapped_glyph_skip`
|
|
Enhanced assertion messages for:
|
|
- `is_unmapped_glyph_name()` checks - Added detailed failure messages explaining expected vs found and why this matters
|
|
- `map.is_empty()` check - Explains why empty map indicates parser error
|
|
- `map.len()` check - Details expected count and why incorrect count matters
|
|
- `map.lookup()` checks - Added expected/found/why matters for each lookup
|
|
- Unicode destination validation loop - Enhanced message about replacement character detection
|
|
|
|
#### Test 2: `test_cmap_multiple_mappings_with_unmapped_check`
|
|
Enhanced assertion messages for:
|
|
- `map.len()` check - Added context about beginbfchar...endbfchar parsing
|
|
- Individual mapping lookups (0x00, 0x01, 0x02) - Added expected/found/why matters for each
|
|
- `is_unmapped_glyph_name()` check - Explains function should not be affected by parsing
|
|
|
|
#### Test 3: `test_cmap_range_mapping_with_unmapped_awareness`
|
|
Enhanced assertion messages for:
|
|
- Range expansion check - Explains beginbfrange...endbfrange behavior and why 26 mappings expected
|
|
- First/last entry checks - Added context about Unicode code points (U+0041 for A, U+005A for Z)
|
|
- Unmapped glyph name checks - Clarified leading slash handling
|
|
|
|
#### Tests 4-7: Already had excellent assertion messages
|
|
These tests already had detailed, helpful assertion messages from previous work:
|
|
- `test_differences_overlay_filters_unmapped_glyphs`
|
|
- `test_differences_overlay_consecutive_with_unmapped_filtering`
|
|
- `test_differences_overlay_filters_null_glyph`
|
|
- `test_differences_overlay_filters_all_g_series_unmapped`
|
|
|
|
## Assertion Message Pattern
|
|
|
|
All assertion messages now follow this pattern for maximum helpfulness:
|
|
1. **What was expected** - Clear statement of the expected result
|
|
2. **What was found** - The actual result (using `{:?}` formatting for complex values)
|
|
3. **Why this matters** - Context about the assertion's purpose and implications
|
|
|
|
Example:
|
|
```rust
|
|
assert_eq!(
|
|
map.len(),
|
|
3,
|
|
"CMAP should have exactly 3 mappings. \
|
|
Expected: 3 mappings (A, B, C). \
|
|
Found: {} mappings. \
|
|
Why this matters: Incorrect mapping count indicates the parser is incorrectly \
|
|
handling the beginbfchar...endbfchar construct.",
|
|
map.len()
|
|
);
|
|
```
|
|
|
|
## Test Results
|
|
|
|
All 7 tests pass successfully:
|
|
```
|
|
running 7 tests
|
|
test test_cmap_multiple_mappings_with_unmapped_check ... ok
|
|
test test_cmap_range_mapping_with_unmapped_awareness ... ok
|
|
test test_cmap_unmapped_glyph_skip ... ok
|
|
test test_differences_overlay_consecutive_with_unmapped_filtering ... ok
|
|
test test_differences_overlay_filters_null_glyph ... ok
|
|
test test_differences_overlay_filters_all_g_series_unmapped ... ok
|
|
test test_differences_overlay_filters_unmapped_glyphs ... ok
|
|
|
|
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
|
```
|
|
|
|
## Verification of Skip Behavior
|
|
|
|
The tests correctly verify the skip behavior through:
|
|
1. **Positive assertions** - Normal glyphs (A, B, C, space, CustomA, CustomB, Z) ARE present in CMAP output
|
|
2. **Negative assertions** - Unmapped glyphs (g001-g003, g000-g009, .notdef, .null) are ABSENT from CMAP output
|
|
3. **Configuration awareness** - Tests reference `build/unmapped-glyph-names.json` to explain why glyphs should be filtered
|
|
|
|
## Edge Cases and Limitations
|
|
|
|
### Edge Cases Covered
|
|
- Consecutive name assignments in /Differences arrays
|
|
- Leading slash on glyph names (/.notdef vs .notdef)
|
|
- Range mapping (beginbfrange...endbfrange)
|
|
- Multiple individual mappings (beginbfchar...endbfchar)
|
|
- Complete filtering (all entries are unmapped)
|
|
|
|
### Known Limitations
|
|
- Tests use hardcoded CMAP data structures rather than real PDF files
|
|
- Tests do not cover every possible CMAP format variation (focus on common cases)
|
|
- Tests assume `build/unmapped-glyph-names.json` contains the expected unmapped glyph names
|
|
|
|
## Acceptance Criteria Status
|
|
|
|
✅ **All assertion messages are clear and specific**
|
|
- Every assertion now follows the expected/found/why matters pattern
|
|
- Messages provide context about configuration (e.g., referencing build/unmapped-glyph-names.json)
|
|
|
|
✅ **Test runs without panics or errors**
|
|
- All 7 tests complete successfully with no errors
|
|
|
|
✅ **Test correctly identifies skip behavior**
|
|
- Positive assertions verify normal glyphs are preserved
|
|
- Negative assertions verify unmapped glyphs are filtered
|
|
- Tests use the actual `is_unmapped_glyph_name()` and `DifferencesOverlay::parse()` functions
|
|
|
|
✅ **Test provides helpful diagnostics on failure**
|
|
- Assertion messages explain what went wrong, what was expected, and why it matters
|
|
- Complex values are formatted using `{:?}` for easy debugging
|
|
|
|
## Commit Information
|
|
|
|
**Commit:** `bf-18a0w` - Improve assertion messages and verify test correctness
|
|
|
|
**Files Changed:**
|
|
- `crates/pdftract-core/tests/cmap_unmapped_glyphs.rs`
|
|
|
|
**Test Verification:** All 7 tests in cmap_unmapped_glyphs pass (0.00s)
|