Skip to content

[TESTS] Add comprehensive tests for parse_update_entry function #94

@Firstp1ck

Description

@Firstp1ck

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions