import { promises } from "node:fs";
import { json2map } from "./utils/index.js";
const readFile = promises.readFile;
export class AssertResult {
    fail = 0;
    total = 0;
    failed_info = new Map();
    async merge(result, expectInfoFilePath) {
        this.fail += result.fail;
        this.total += result.total;
        if (result.fail > 0) {
            let expectInfo;
            try {
                const expectContent = await readFile(expectInfoFilePath, { encoding: "utf8" });
                expectInfo = json2map(JSON.parse(expectContent));
                for (const [key, value] of json2map(result.failed_info)) {
                    const errorMsgs = [];
                    for (const msg of value) {
                        const [index, actualValue, expectValue] = msg;
                        const debugLocation = expectInfo.get(index);
                        let errorMsg = `${debugLocation ?? ""}\tvalue: ${actualValue}\texpect: ${expectValue}`;
                        if (errorMsg.length > 160) {
                            errorMsg = `${debugLocation ?? ""}\nvalue: \n\t${actualValue}\nexpect: \n\t${expectValue}`;
                        }
                        errorMsgs.push(errorMsg);
                    }
                    this.failed_info.set(key, errorMsgs);
                }
            }
            catch (error) {
                if (error instanceof Error) {
                    console.error(error.stack);
                }
                throw new Error(`maybe forget call "endTest()" at the end of "*.test.ts" or Job abort before output`);
            }
        }
    }
}
//# sourceMappingURL=assertResult.js.map