1
1
import { getDataStructure } from "./parseStructure.js" ;
2
2
import { removeDomTags } from "../functions/removeDomTags.js" ;
3
+ import { DefaultLang } from "#common/constants/question.const.js" ;
3
4
4
5
/**
5
6
* test case 需要从两个地方拿到内容
@@ -23,16 +24,19 @@ export function getTestCase(question) {
23
24
?. map ( ( str ) => `[${ removeDomTags ( str ?. replace ( inputStartReg , '' ) ?. replace ( endReg , '' ) ?. replace ( '\n' , '' ) . replace ( / [ a - z A - Z ] + = / g, "" ) ) } ]` ) ;
24
25
const expires = detail . match ( outputReg )
25
26
?. map ( ( str ) => removeDomTags ( str ?. replace ( outputStartReg , '' ) ?. replace ( endReg , '' ) ?. replace ( '\n' , '' ) . replace ( / [ a - z A - Z ] + = / g, "" ) ) ) ;
26
- const functionName = question . jsCode ?. match ( / ( v a r | l e t | c o n s t ) .+ = / g) ?. [ 0 ] ?. replace ( / ( ( v a r | l e t | c o n s t ) | = ) \s ? / gm, '' ) . trim ( ) ;
27
- return `showLogs(
28
- ${ functionName } ,
29
- {
30
- data: [${ cases } ],
31
- structure: ${ JSON . stringify ( getDataStructure ( question . jsCode ) ) } ,
32
- },
33
- {
34
- data: [${ expires } ],
35
- structure: ${ JSON . stringify ( getDataStructure ( question . jsCode , 'return' ) ) }
27
+ if ( question . lang === DefaultLang ) {
28
+ const functionName = question . code ?. match ( / ( v a r | l e t | c o n s t ) .+ = / g) ?. [ 0 ] ?. replace ( / ( ( v a r | l e t | c o n s t ) | = ) \s ? / gm, '' ) . trim ( ) ;
29
+ return `showLogs(\n${ functionName } ,\n{\ndata: [${ cases } ],\nstructure: ${ JSON . stringify ( getDataStructure ( question . code ) ) } ,\n},\n{\ndata: [${ expires } ],\nstructure: ${ JSON . stringify ( getDataStructure ( question . code , 'return' ) ) } \n}\n)` ;
30
+ } else {
31
+ // 其他语言无法支持测试 只能提供测试数据
32
+ console . log ( cases , expires ) ;
33
+ let showText = `\/* 暂无法支持除JS外的语言测试,提取的一些入参和返回值供自行测试,每一个case中的第一行为入参,第二行为返回值\n` ;
34
+ for ( let i = 0 ; i < Math . max ( cases . length , expires . length ) ; i ++ ) {
35
+ showText += `case ${ i + 1 } :\n` ;
36
+ showText += `${ cases ?. [ i ] } \n` ?? '[参数获取错误]\n' ;
37
+ showText += `${ expires ?. [ i ] } \n` ?? '[返回值获取错误]\n' ;
38
+ }
39
+ showText += `\n*\/`
40
+ return showText ;
36
41
}
37
- )` ;
38
42
}
0 commit comments