#!/usr/bin/env python3
"""
测试包含连字符的数字货号格式：156540-100
"""

import sys
import os

# 添加项目根目录到路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))

from app.utils.text_parser import ProductCodeExtractor

def test_hyphen_number_code():
    """测试包含连字符的数字货号格式"""
    extractor = ProductCodeExtractor()
    
    test_case = {
        'name': "Tory Burch 女款 白色 大浮雕logo 板鞋156540-100代购11.2MC",
        'expected': "156540-100",
        'format': "数字-数字格式"
    }
    
    print("=== 连字符数字货号格式测试 ===")
    print(f"商品名称: {test_case['name']}")
    print(f"期望货号: {test_case['expected']}")
    
    product_code = extractor.extract_product_code(test_case['name'])
    print(f"实际货号: {product_code}")
    
    if product_code == test_case['expected']:
        print("✅ 匹配成功")
    else:
        print("❌ 不匹配！")
        
        # 详细调试
        print("\n=== 详细调试 ===")
        import re
        
        # 测试不同的连字符数字模式
        patterns_to_test = [
            r'\d+[-]\d+',              # 基本数字-数字模式
            r'\d{3,}[-]\d{3,}',        # 至少3位数字-至少3位数字
            r'\d{6}[-]\d{3}',          # 6位数字-3位数字
            r'156540-100',             # 精确匹配
        ]
        
        clean_name = test_case['name']
        for i, pattern in enumerate(patterns_to_test, 1):
            matches = re.findall(pattern, clean_name)
            print(f"模式 {i} ({pattern}): {matches}")

if __name__ == "__main__":
    test_hyphen_number_code()