Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ env/
plan/ # Planning notes and drafts
claude.md # AI assistant instructions
.env # Environment variables (secrets)
output/ # Output directory for parsed files

# Testing
.pytest_cache/
Expand All @@ -52,7 +53,7 @@ htmlcov/
.hypothesis/

# Code quality tools
.ruffcache/
.ruff_cache/

# Logs
*.log
Expand Down
2 changes: 1 addition & 1 deletion pdfparser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
_WHITESPACE_PATTERN: Pattern = re.compile(r"\s+")
_NUMERIC_LINE_PATTERN: Pattern = re.compile(r"^[\d,.]+\s*$")
_NUMERIC_ONLY_PATTERN: Pattern = re.compile(r"^[\d,.]*$")
_AMOUNT_PATTERN: Pattern = re.compile(r"^[\d,]+\.\d{2}$")
_AMOUNT_PATTERN: Pattern = re.compile(r"^[\d,.]+[.,]\d{2}$")
_USER_ID_PATTERN: Pattern = re.compile(r"^\d{6,8}$")

# Summary section label patterns (compiled for extract_summary_totals)
Expand Down
74 changes: 74 additions & 0 deletions tests/test_indonesian_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

import pytest
from pdfparser.utils import extract_transactions

class TestIndonesianFormat:
"""Tests for Indonesian number format extraction."""

def test_extract_indonesian_format_transactions(self):
"""Verify extraction of transactions with Indonesian number format."""
text = """
01/01/23 10:00:00
Transfer
User123
10.000,00
0,00
1.000.000,00
"""
transactions = extract_transactions(text)

assert len(transactions) == 1
txn = transactions[0]

# In this specific text layout, User123 is treated as description because
# it is not on the same line as amount and doesn't match User ID pattern.
# But crucially, '10.000,00' should be identified as DEBIT amount,
# not mistakenly as User ID.

assert txn["debit"] == "10.000,00"
assert txn["credit"] == "0,00"
assert txn["balance"] == "1.000.000,00"

# Ensure it wasn't misclassified as User
# (If misclassified, user would be "10.000,00" and debit would be empty)
assert txn["user"] != "10.000,00"

def test_extract_indonesian_format_no_user_id(self):
"""Verify extraction when User ID is missing and amounts are Indonesian format."""
text = """
01/01/23 10:00:00
Transfer
10.000,00
0,00
1.000.000,00
"""
transactions = extract_transactions(text)

assert len(transactions) == 1
txn = transactions[0]

assert txn["debit"] == "10.000,00"
assert txn["credit"] == "0,00"
assert txn["balance"] == "1.000.000,00"

# Verify it wasn't misclassified as User
assert txn["user"] == ""

def test_extract_us_format_transactions(self):
"""Verify extraction of transactions with US number format (sanity check)."""
text = """
01/01/23 10:00:00
Transfer
User123
10000.00
0.00
1000000.00
"""
transactions = extract_transactions(text)

assert len(transactions) == 1
txn = transactions[0]

assert txn["debit"] == "10000.00"
assert txn["credit"] == "0.00"
assert txn["balance"] == "1000000.00"