Skip to content

Commit 106d7e4

Browse files
committed
fix: 修复 ESLint any 类型错误和属性测试生成器问题
- 添加 StepType 类型导入,移除 as any 类型断言 - 修复 arbitrarySingleLanguageMapping 生成器,确保 primaryLine 在 lines 数组中
1 parent d10a41b commit 106d7e4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/types/codeMapping.test.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { describe, it, expect } from 'vitest';
88
import * as fc from 'fast-check';
99
import type { Language } from './index';
10-
import type { StepId } from './animationStep';
10+
import type { StepId, StepType } from './animationStep';
1111
import {
1212
type MultiLanguageCodeLines,
1313
type SingleLanguageMapping,
@@ -29,13 +29,17 @@ const arbitraryCodeLines = fc.array(arbitraryLineNumber, { minLength: 1, maxLeng
2929
.map(lines => [...new Set(lines)].sort((a, b) => a - b));
3030

3131
// 生成器:单语言映射
32-
const arbitrarySingleLanguageMapping: fc.Arbitrary<SingleLanguageMapping> = fc.record({
33-
lines: arbitraryCodeLines,
34-
primaryLine: fc.option(arbitraryLineNumber, { nil: undefined }),
35-
}).map(({ lines, primaryLine }) => ({
36-
lines,
37-
primaryLine: primaryLine ?? lines[0],
38-
}));
32+
const arbitrarySingleLanguageMapping: fc.Arbitrary<SingleLanguageMapping> = arbitraryCodeLines
33+
.chain(lines =>
34+
fc.record({
35+
lines: fc.constant(lines),
36+
primaryLine: fc.option(fc.constantFrom(...lines), { nil: undefined }),
37+
})
38+
)
39+
.map(({ lines, primaryLine }) => ({
40+
lines,
41+
primaryLine: primaryLine ?? lines[0],
42+
}));
3943

4044
// 生成器:步骤 ID
4145
const arbitraryStepId: fc.Arbitrary<StepId> = fc.stringMatching(/^[a-z_]+_\d+(_[a-z_]+)?$/);
@@ -243,13 +247,13 @@ describe('Code Line Mapping Properties', () => {
243247
fc.assert(
244248
fc.property(
245249
arbitraryStepId,
246-
fc.constantFrom('init', 'compute_cell', 'complete'),
250+
fc.constantFrom<StepType>('init', 'compute_cell', 'complete'),
247251
fc.string({ minLength: 1, maxLength: 100 }),
248252
arbitraryMultiLanguageCodeLines,
249253
(stepId, stepType, description, codeLines) => {
250254
const mapping = createStepCodeMapping(
251255
stepId,
252-
stepType as any,
256+
stepType,
253257
description,
254258
codeLines
255259
);

0 commit comments

Comments
 (0)