fix(ui-migration): frameIndex 验证(拒绝非整数与 undefined/NaN)
问题:\`||\` 运算符接受任何 falsy 值(undefined/NaN/null)为帧 1, 违反「零兜底」原则。brief 仅明确规定 frameIndex=0 视同 1。 修法: - 将 \`frameIndex || 1\` 改为 \`frameIndex === 0 ? 1 : frameIndex\` - 在 frameRect 中加入 Number.isInteger 检查(拦截 NaN、undefined) - frameFileName 亦加验证,防止非法输入产出垃圾文件名 - 错误信息明确说明有效范围与 0→1 转换规则 新增 4 条测试用例覆盖 undefined 与 NaN,确保非整数被正确拒绝。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,16 @@ test('frameRect 越界抛 RangeError 且带图名', () => {
|
||||
assert.throws(() => frameRect(IMG_00014, 13), /00014\.png/);
|
||||
});
|
||||
|
||||
test('frameRect undefined 作为 frameIndex 抛 RangeError', () => {
|
||||
assert.throws(() => frameRect(IMG_00014, undefined), RangeError);
|
||||
assert.throws(() => frameRect(IMG_00014, undefined), /00014\.png/);
|
||||
});
|
||||
|
||||
test('frameRect NaN 作为 frameIndex 抛 RangeError', () => {
|
||||
assert.throws(() => frameRect(IMG_00014, NaN), RangeError);
|
||||
assert.throws(() => frameRect(IMG_00014, NaN), /00014\.png/);
|
||||
});
|
||||
|
||||
test('padWidth 按帧总数决定补零位数', () => {
|
||||
assert.equal(padWidth(9), 1);
|
||||
assert.equal(padWidth(12), 2);
|
||||
@@ -61,6 +71,14 @@ test('frameFileName 单帧图原样返回', () => {
|
||||
assert.equal(frameFileName('00001.png', 1, 1), '00001.png');
|
||||
});
|
||||
|
||||
test('frameFileName undefined 作为 frameIndex 抛 RangeError', () => {
|
||||
assert.throws(() => frameFileName('00014.png', undefined, 12), RangeError);
|
||||
});
|
||||
|
||||
test('frameFileName NaN 作为 frameIndex 抛 RangeError', () => {
|
||||
assert.throws(() => frameFileName('00014.png', NaN, 12), RangeError);
|
||||
});
|
||||
|
||||
test('frameNames 返回全部帧,下标 0 对应帧 1', () => {
|
||||
const names = frameNames(IMG_00014);
|
||||
assert.equal(names.length, 12);
|
||||
|
||||
Reference in New Issue
Block a user