mcp-pdf-tools/test_pages_parameter.py
Ryan Malloy f601d44d99 Fix page numbering: Switch to user-friendly 1-based indexing
**Problem**: Zero-based page numbers were confusing for users who naturally
think of pages starting from 1.

**Solution**:
- Updated `parse_pages_parameter()` to convert 1-based user input to 0-based internal representation
- All user-facing documentation now uses 1-based page numbering (page 1 = first page)
- Internal processing continues to use 0-based indexing for PyMuPDF compatibility
- Output page numbers are consistently displayed as 1-based for users

**Changes**:
- Enhanced documentation strings to clarify "1-based" page numbering
- Updated README examples with 1-based page numbers and clarifying comments
- Fixed split_pdf function to handle 1-based input correctly
- Updated test cases to verify 1-based -> 0-based conversion
- Added feature highlight: "User-Friendly: All page numbers use 1-based indexing"

**Impact**: Much more intuitive for users - no more confusion about which page is "page 0"\!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 04:32:20 -06:00

52 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
Test the updated pages parameter parsing
"""
import asyncio
import sys
import os
# Add src to path
sys.path.insert(0, 'src')
from mcp_pdf_tools.server import parse_pages_parameter
def test_page_parsing():
"""Test page parameter parsing (1-based user input -> 0-based internal)"""
print("Testing page parameter parsing (1-based user input -> 0-based internal)...")
# Test different input formats - all converted from 1-based user input to 0-based internal
test_cases = [
(None, None),
("1,2,3", [0, 1, 2]), # 1-based input -> 0-based internal
("[2, 3]", [1, 2]), # This is the problematic case from the user
("5", [4]), # Page 5 becomes index 4
([1, 2, 3], [0, 1, 2]), # List input also converted
("2,3,4", [1, 2, 3]), # Pages 2,3,4 -> indexes 1,2,3
("[1,2,3]", [0, 1, 2]) # Another format
]
all_passed = True
for input_val, expected in test_cases:
try:
result = parse_pages_parameter(input_val)
if result == expected:
print(f"'{input_val}' -> {result}")
else:
print(f"'{input_val}' -> {result}, expected {expected}")
all_passed = False
except Exception as e:
print(f"'{input_val}' -> Error: {e}")
all_passed = False
return all_passed
if __name__ == "__main__":
success = test_page_parsing()
if success:
print("\n🎉 All page parameter parsing tests passed!")
else:
print("\n🚨 Some tests failed!")
sys.exit(0 if success else 1)