import { expect, test, describe } from '@jest/globals'; import { validSpecification } from './validate.js'; const callValidator = (value) => { let err = null; validSpecification(null, value, (e) => { err = e; }); return !err; }; describe('validSpecification - 规格校验', () => { describe('正常情况', () => { test('1.50*1000', () => { expect(callValidator('1.50*1000')).toBe(true); }); test('0.35*1250.5', () => { expect(callValidator('0.35*1250.5')).toBe(true); }); test('2.385*1500', () => { expect(callValidator('2.385*1500')).toBe(true); }); test('10.00*500', () => { expect(callValidator('10.00*500')).toBe(true); }); test('0.25*2000', () => { expect(callValidator('0.25*2000')).toBe(true); }); }); describe('异常情况 - 厚度小数不足两位', () => { test('1.5*1000 只有一位小数', () => { expect(callValidator('1.5*1000')).toBe(false); }); test('10*1000 没有小数', () => { expect(callValidator('10*1000')).toBe(false); }); test('5.*1000 0位小数', () => { expect(callValidator('5.*1000')).toBe(false); }); }); describe('异常情况 - 缺少星号分隔符', () => { test('1.501000 无星号', () => { expect(callValidator('1.501000')).toBe(false); }); test('1.50 只有厚度', () => { expect(callValidator('1.50')).toBe(false); }); }); describe('异常情况 - 缺少厚度或宽度', () => { test('*1000 缺厚度', () => { expect(callValidator('*1000')).toBe(false); }); test('1.50* 缺宽度', () => { expect(callValidator('1.50*')).toBe(false); }); }); describe('异常情况 - 非数字输入', () => { test('abc*1000 厚度为字母', () => { expect(callValidator('abc*1000')).toBe(false); }); test('1.50*abc 宽度为字母', () => { expect(callValidator('1.50*abc')).toBe(false); }); test('一点五*一千 纯中文', () => { expect(callValidator('一点五*一千')).toBe(false); }); }); describe('异常情况 - 格式错误', () => { test('1.50*1000*extra 多星号', () => { expect(callValidator('1.50*1000*extra')).toBe(false); }); test('空字符串通过必填之外校验', () => { expect(callValidator('')).toBe(true); }); test('星号在前', () => { expect(callValidator('*1.50*1000')).toBe(false); }); test('含空格', () => { expect(callValidator(' 1.50*1000 ')).toBe(false); }); test('中文×分隔符', () => { expect(callValidator('1.50×1000')).toBe(false); }); }); });