#!/usr/bin/env python3
"""
测试Burberry货号格式不会误匹配结尾日期
"""

import sys
import os

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

from app.utils.text_parser import ProductCodeExtractor

def test_burberry_date_filter():
    """测试Burberry格式不会误匹配结尾日期"""
    extractor = ProductCodeExtractor()
    
    test_cases = [
        # 正确的货号格式，不应匹配结尾日期
        {
            'name': "Burberry 男款衬衫 8084328/8084329/8084330 代购8.16",
            'expected': "8084328/8084329/8084330",
            'should_exclude': ["8.16"],
            'description': "/分隔格式避免匹配结尾日期8.16"
        },
        {
            'name': "Burberry 女款手袋 81234567/81234568 代购8.18",
            'expected': "81234567/81234568",
            'should_exclude': ["8.18"],
            'description': "/分隔格式避免匹配结尾日期8.18"
        },
        {
            'name': "Burberry 经典风衣 90123456 90123457/90123458 代购8.19",
            'expected': "90123456 90123457/90123458",
            'should_exclude': ["8.19"],
            'description': "混合分隔格式避免匹配结尾日期8.19"
        },
        {
            'name': "Burberry 女款围巾 80776841 80776842 代购8.15",
            'expected': "80776841 80776842",
            'should_exclude': ["8.15"],
            'description': "空格分隔格式避免匹配结尾日期8.15"
        },
        # 单一货号也不应该匹配日期
        {
            'name': "Burberry 女款开衫 80776841 小王国代购7.30",
            'expected': "80776841",
            'should_exclude': ["7.30"],
            'description': "单一货号避免匹配结尾日期7.30"
        }
    ]
    
    print("=== Burberry货号日期过滤测试 ===")
    print("验证：提取正确货号但不匹配结尾日期格式")
    print()
    
    for i, case in enumerate(test_cases, 1):
        print(f"测试 {i}: {case['description']}")
        print(f"商品名称: {case['name']}")
        print(f"期望货号: {case['expected']}")
        
        product_code = extractor.extract_product_code(case['name'], "Burberry")
        print(f"实际货号: {product_code}")
        
        # 检查是否正确提取货号
        correct_extraction = product_code == case['expected']
        
        # 检查是否错误匹配了应该排除的日期
        date_excluded = True
        for excluded_date in case['should_exclude']:
            if product_code == excluded_date or (product_code and excluded_date in product_code):
                date_excluded = False
                break
        
        success = correct_extraction and date_excluded
        
        if success:
            print("✅ 测试通过：正确提取货号且避免日期")
        else:
            print("❌ 测试失败！")
            if not correct_extraction:
                print("  - 货号提取不正确")
            if not date_excluded:
                print(f"  - 错误匹配了日期: {case['should_exclude']}")
        print()

if __name__ == "__main__":
    test_burberry_date_filter()