import { describe, expect, test } from "bun:test";

import { checkExitCode } from "../../../../../src/server/checker/runner/cmd/expect";

describe("checkExitCode", () => {
  test("exitCode 在允许列表中匹配成功", () => {
    const r = checkExitCode(0, [0]);
    expect(r.matched).toBe(true);
    expect(r.failure).toBeNull();
  });

  test("exitCode 不在允许列表中匹配失败", () => {
    const r = checkExitCode(1, [0]);
    expect(r.matched).toBe(false);
    expect(r.failure!.phase).toBe("exitCode");
    expect(r.failure!.kind).toBe("mismatch");
    expect(r.failure!.expected).toEqual([0]);
    expect(r.failure!.actual).toBe(1);
  });

  test("多个允许退出码", () => {
    expect(checkExitCode(0, [0, 1]).matched).toBe(true);
    expect(checkExitCode(1, [0, 1]).matched).toBe(true);
    expect(checkExitCode(2, [0, 1]).matched).toBe(false);
  });
});
