// 调试:验证 free_show_local_agent.js 的 extractPrice 价格提取逻辑
// 用法:node dev_test_scripts/debug/debug_price_extract.js
'use strict'
const fs = require('fs')
const path = require('path')
const src = fs.readFileSync(path.join(__dirname, '..', '..', 'public', 'tools', 'free_show', 'free_show_local_agent.js'), 'utf-8')
const m = src.match(/function extractPrice[\s\S]*?\n}/)
if (!m) { console.log('FAIL: 未找到 extractPrice'); process.exit(1) }
const extractPrice = new Function('return ' + m[0])()
const cases = [
['
130-2620元
', 130, '130-2620元'],
['... 380.0元 起 ...', 380, '380.0元'],
['¥130起', 130, '¥130'],
['2026.08.03-08.30 上海', null, null], // 日期不应误判为价格
['价格待定', null, null]
]
let fail = 0
for (const [input, wantPrice, wantText] of cases) {
const got = extractPrice(input)
const okPrice = wantPrice === null ? got === null : got && got.price === wantPrice
const okText = wantText === null ? got === null : got && got.priceText === wantText
if (okPrice && okText) console.log(`PASS: ${JSON.stringify(input)} => ${JSON.stringify(got)}`)
else { fail++; console.log(`FAIL: ${JSON.stringify(input)} => ${JSON.stringify(got)} (want ${wantPrice}/${wantText})`) }
}
process.exit(fail ? 1 : 0)