(cfg: ProblemConfigFile = {}, checkFile = (s: CompilableSource, errMsg: string) => s)
| 3 | |
| 4 | // eslint-disable-next-line ts/no-unused-vars |
| 5 | export async function readYamlCases(cfg: ProblemConfigFile = {}, checkFile = (s: CompilableSource, errMsg: string) => s) { |
| 6 | const config: any = { |
| 7 | checker_type: cfg.checker_type || 'default', |
| 8 | judge_extra_files: [], |
| 9 | user_extra_files: [], |
| 10 | }; |
| 11 | const checkFileWithLang = (s: CompilableSource, errMsg: string) => { |
| 12 | if (typeof s === 'string') return { lang: 'auto', file: checkFile(s, errMsg) }; |
| 13 | return { lang: s.lang, file: checkFile(s.file, errMsg) }; |
| 14 | }; |
| 15 | if (cfg.type === 'objective') { |
| 16 | if (cfg.checker || cfg.interactor || cfg.validator) { |
| 17 | throw new Error('You cannot use checker, interactor or validator for objective questions'); |
| 18 | } |
| 19 | } else { |
| 20 | if (cfg.checker) { |
| 21 | const [name, lang] = typeof cfg.checker === 'string' ? [cfg.checker, 'auto'] : [cfg.checker.file, cfg.checker.lang || 'auto']; |
| 22 | if (!name.includes('.')) { |
| 23 | config.checker = { |
| 24 | lang, |
| 25 | file: findFileSync(`@hydrooj/hydrojudge/vendor/testlib/checkers/${name}.cpp`, false), |
| 26 | }; |
| 27 | } |
| 28 | config.checker ||= checkFileWithLang(name, 'Cannot find checker {0}.'); |
| 29 | } |
| 30 | if (cfg.interactor) config.interactor = checkFileWithLang(cfg.interactor, 'Cannot find interactor {0}.'); |
| 31 | if (cfg.manager) config.manager = checkFileWithLang(cfg.manager, 'Cannot find Manager {0}.'); |
| 32 | if (cfg.validator) config.validator = checkFileWithLang(cfg.validator, 'Cannot find validator {0}.'); |
| 33 | for (const n of ['judge', 'user']) { |
| 34 | const conf = cfg[`${n}_extra_files`]; |
| 35 | if (!conf) continue; |
| 36 | if (conf instanceof Array) { |
| 37 | config[`${n}_extra_files`] = conf.map((file) => checkFile(file, `Cannot find ${n} extra file {0}.`)); |
| 38 | } else throw new Error(`Invalid ${n}_extra_files config.`); |
| 39 | } |
| 40 | } |
| 41 | if (cfg.cases?.length) { |
| 42 | config.subtasks = [{ |
| 43 | cases: cfg.cases, |
| 44 | type: 'sum', |
| 45 | }]; |
| 46 | } |
| 47 | if (cfg.time) config.time = parseTimeMS(cfg.time); |
| 48 | if (cfg.memory) config.memory = parseMemoryMB(cfg.memory); |
| 49 | return Object.assign(cfg, config); |
| 50 | } |
no test coverage detected