diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 14cbfffcf..e3b260986 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.14.4", + "version": "2.14.5", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/testlib.ts b/packages/hydrojudge/src/testlib.ts index ee6d3a281..6e6f6f59d 100644 --- a/packages/hydrojudge/src/testlib.ts +++ b/packages/hydrojudge/src/testlib.ts @@ -1,21 +1,28 @@ import { STATUS } from '@hydrooj/utils/lib/status'; +const operation = /^(status|score)\((\d+)\) *(.*)$/; + export function parse(output: string, fullscore: number) { let status = STATUS.STATUS_WRONG_ANSWER; let score = 0; - let message = output.substr(0, 1024); + let builder = (msg: string) => msg; + let message = output.substring(0, 1024); if (output.startsWith('ok ')) { status = STATUS.STATUS_ACCEPTED; score = fullscore; } else if (output.startsWith('wrong answer ')) { message = output.split('wrong answer ')[1] || ''; } else if (output.startsWith('wrong output format ')) { - message = `PE ${output.split('wrong output format ')[1] || ''}`; + message = output.split('wrong output format ')[1] || ''; + builder = (msg) => `PE ${msg}`; } else if (output.startsWith('partially correct ')) { - message = `PC ${output.split('partially correct ')[1] || ''}`; let p = +output.split('partially correct (')[1].split(')')[0] || 0; if (p > 1) p /= 100; score = Math.floor(fullscore * p); + const res = message.split(')'); + res.shift(); + message = res.join(')').trim(); + builder = (msg) => `PC ${msg}`; } else if (output.startsWith('points ')) { let p = +output.split('points ')[1].split(' ')[0] || 0; if (p > 1) p /= 100; @@ -23,8 +30,18 @@ export function parse(output: string, fullscore: number) { status = STATUS.STATUS_ACCEPTED; score = fullscore; const base = output.split('points ')[1] || ''; - message = base.substr(base.indexOf(' '), 1024); + message = base.substring(base.indexOf(' '), 1024); } else score = Math.floor(fullscore * p); } - return { status, score, message }; + while (operation.test(message)) { + const [, op, val, rest] = message.match(operation); + if (op === 'status') { + status = +val; + message = rest; + } else if (op === 'score') { + score = +val; + message = rest; + } + } + return { status, score, message: builder(message) }; }