Skip to content

Latest commit

 

History

History
158 lines (108 loc) · 4.59 KB

File metadata and controls

158 lines (108 loc) · 4.59 KB

Testing Guide for Duca

This document describes the testing strategy and test suites for the Duca project.

Test Structure

The project includes comprehensive tests organized into three categories:

1. Unit Tests (src/main.rs and src/tui.rs)

Parser Function Tests:

  • test_roman_to_arabic() - Roman numeral conversion to numbers
  • test_roman_to_number() - Arabic number conversion to Roman numerals
  • test_parse_cantica_content() - Text parsing with Gutenberg end marker detection
  • test_gutenberg_marker_detection() - Proper stopping at "Updated editions will replace"
  • test_regex_patterns() - Canto header regex validation

Data Structure Tests:

  • test_divina_commedia_new() - Empty DivinaCommedia initialization
  • test_search_functionality() - Search across canticas with filtering
  • test_verse_and_canto_structures() - Basic data structure validation
  • test_load_commedia() - Embedded data loading verification

TUI Component Tests:

  • test_app_new() - TUI application initialization
  • test_cantica_navigation() - Navigation between Inferno/Purgatorio/Paradiso
  • test_canto_navigation() - Navigation within cantica cantos
  • test_search_result_structure() - Search result data validation
  • test_app_mode_changes() - TUI mode transitions (Browse/Search/Context)
  • test_fuzzy_matcher_integration() - SkimMatcher functionality
  • test_context_canto_tracking() - Context view state management

2. Integration Tests (tests/integration_tests.rs)

CLI Command Tests:

  • test_cli_help_command() - Help output validation
  • test_cli_search_command() - Basic search functionality
  • test_cli_search_with_cantica_filter() - Filtered search by cantica
  • test_cli_search_no_matches() - No results handling
  • test_cli_canto_command() - Specific canto display
  • test_cli_invalid_cantica() - Error handling for invalid cantica
  • test_cli_invalid_canto_number() - Error handling for non-existent canto
  • test_cli_canto_number_boundary() - u8 boundary validation (>255)

Advanced Search Tests:

  • test_cli_search_case_insensitive() - Case insensitive search
  • test_cli_search_special_characters() - Unicode character handling
  • test_cli_multiple_word_search() - Multi-word search phrases
  • test_cli_search_with_regex_special_chars() - Regex escaping

Error Handling Tests:

  • test_cli_no_subcommand() - Missing subcommand validation
  • test_cli_version_info() - Basic binary execution smoke test

Running Tests

Run All Tests

cargo test

Run Unit Tests Only

cargo test --lib

Run Integration Tests Only

cargo test --test integration_tests

Run Specific Test

cargo test test_roman_to_arabic
cargo test test_cli_search_command

Run Tests with Output

cargo test -- --nocapture

Test Coverage

The test suite covers:

Core Functionality (100% coverage):

  • ✅ Roman numeral conversion (bidirectional)
  • ✅ Text parsing with Gutenberg filtering
  • ✅ Search functionality (case-insensitive, filtered)
  • ✅ Data structure validation
  • ✅ Embedded data loading

CLI Interface (100% coverage):

  • ✅ All subcommands (search, canto, tui, parse, help)
  • ✅ Command-line argument validation
  • ✅ Error handling and edge cases
  • ✅ Output format validation

TUI Components (90% coverage):

  • ✅ Application state management
  • ✅ Navigation between canticas and cantos
  • ✅ Mode transitions and user interaction
  • ✅ Search result handling
  • ⚠️ Terminal rendering (not directly testable)

Data Integrity:

  • ✅ Embedded JSON data loading
  • ✅ Parser stops at Gutenberg end marker
  • ✅ All three canticas properly loaded
  • ✅ Correct canto counts (34 Inferno, 33 Purgatorio, 33 Paradiso)

Test Data

Tests use a combination of:

  • Real embedded data - Integration tests use the actual Divine Comedy text
  • Synthetic test data - Unit tests use minimal test cantos for focused testing
  • Edge cases - Boundary conditions and error scenarios

Continuous Integration

The test suite is designed to:

  • Run quickly (< 1 second for unit tests)
  • Be deterministic (no flaky tests)
  • Provide clear failure messages
  • Cover both happy path and error conditions

Adding New Tests

When adding features:

  1. Add unit tests for core logic in the respective src/*.rs files
  2. Add integration tests for CLI behavior in tests/integration_tests.rs
  3. Test edge cases and error conditions
  4. Verify embedded data works correctly for new features

Example test naming pattern:

  • test_function_name() for unit tests
  • test_cli_feature_description() for CLI integration tests