import pytest from pathlib import Path # Import the function to test - assuming it's in a module called 'maildir_analyzer' # Update this import to match your actual module structure from maildirclean.cli import parse_selections def test_single_number(): result = parse_selections("3", 5) assert result == {3} def test_comma_separated_list(): result = parse_selections("1,3,5", 5) assert result == {1, 3, 5} def test_range(): result = parse_selections("2-4", 5) assert result == {2, 3, 4} def test_range_with_spaces(): result = parse_selections("1 - 3", 5) assert result == {1, 2, 3} def test_combined_input(): result = parse_selections("1,3-5,7", 10) assert result == {1, 3, 4, 5, 7} def test_duplicate_numbers(): result = parse_selections("1,1,2,2-4,3", 5) assert result == {1, 2, 3, 4} # Set removes duplicates def test_invalid_format(): with pytest.raises(ValueError, match="Invalid input: abc"): parse_selections("abc", 5) def test_invalid_range_format(): with pytest.raises(ValueError, match="Invalid range format: 2-a"): parse_selections("2-a", 5) def test_inverted_range(): with pytest.raises(ValueError, match="Invalid range: 5-2"): parse_selections("5-2", 5) def test_out_of_range(): with pytest.raises(ValueError, match="Selection.*out of range"): parse_selections("3,6,8", 5) def test_mix_valid_and_invalid(): with pytest.raises(ValueError): parse_selections("1,abc,3", 5) def test_empty_input(): with pytest.raises(ValueError): parse_selections("", 5) def test_whitespace_only(): with pytest.raises(ValueError): parse_selections(" ", 5) def test_max_boundary(): # Test the boundary case result = parse_selections("5", 5) assert result == {5} def test_complex_input(): result = parse_selections("1-2, 4, 6-8", 10) assert result == {1, 2, 4, 6, 7, 8} def test_negative_numbers(): with pytest.raises(ValueError, match="Invalid range format:*"): parse_selections("-1,2", 5)