77import { describe , it , expect } from 'vitest' ;
88import * as fc from 'fast-check' ;
99import type { Language } from './index' ;
10- import type { StepId } from './animationStep' ;
10+ import type { StepId , StepType } from './animationStep' ;
1111import {
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
4145const 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