Firstp1ck/Pacsea

[TESTS] Add comprehensive tests for parse_update_entry function

オープン

#94 opened on 2025/12/12

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (9 件のフォーク)auto 404
enhancementgood first issuehelp wanted

Repository metrics

Stars
 (284 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Summary

The parse_update_entry function in src/util/mod.rs parses update lines but could benefit from more comprehensive tests covering edge cases. Add tests for malformed input, package names with dashes, empty/whitespace input, and Unicode characters.

Files to modify

  • src/util/mod.rs (add test cases in the #[cfg(test)] module)

Expected behavior

The test suite should cover:

  1. Valid inputs: Standard pacman update format parsing
  2. Malformed inputs: Missing arrows, malformed versions, incomplete entries
  3. Edge cases: Package names with dashes, empty/whitespace input, Unicode characters
  4. Error handling: Proper None returns for invalid formats

Implementation approach

Add a new test function util_parse_update_entry with comprehensive test cases:

Testing

  • cargo check passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • cargo test -- --test-threads=1 passes
  • Test valid parsing of standard pacman update format
  • Test malformed inputs return None
  • Test package names containing dashes are handled correctly
  • Test empty and whitespace-only inputs return None
  • Test Unicode characters in package names
  • Test version numbers with various formats (numbers, letters, dashes)
  • Test edge cases with extra whitespace around separators

Additional context

The parse_update_entry function parses lines in the format:

"name - old_version -> name - new_version"

Key parsing logic:

  • Uses find(" -> ") to locate the arrow separator
  • Uses rfind(" - ") to find the last dash before the arrow (handles package names with dashes)
  • Returns None for any malformed input

Test cases should cover real-world pacman output scenarios and ensure the function is robust against various input formats and edge cases that might occur in practice.

コントリビューターガイド