#!/usr/bin/env node "use strict";var g=Object.create;var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var F=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of E(t))!D.call(i,s)&&s!==e&&h(i,s,{get:()=>t[s],enumerable:!(r=y(t,s))||r.enumerable});return i};var u=(i,t,e)=>(e=i!=null?g(x(i)):{},F(t||!i||!i.__esModule?h(e,"default",{value:i,enumerable:!0}):e,i));var w=require("clipanion");var c=require("clipanion"),f=require("child_process"),d=require("fs"),n=u(require("fs/promises")),a=u(require("path")),v=require("util");var p=i=>{if(i instanceof Error)return i.message;if(typeof i=="string")return i;try{return Object.prototype.toString.call(i)}catch{return"Unknown error"}};var P=(0,v.promisify)(f.exec),l=class extends c.Command{dirname=c.Option.String();resolvedDirname="";jsFile="";inoutPair=[];async execute(){await this.validate(),await this.run()}async run(){for(let t=0;t> ${p(s)} `)}this.context.stdout.write(` `)}}async validate(){await this.validateResolvedDirname(),await this.validateOnlyOneJsFile(),await this.filterInputFiles()}async validateResolvedDirname(){let t=a.default.isAbsolute(this.dirname)?this.dirname:a.default.resolve(process.env.INIT_CWD,this.dirname);try{await n.default.access(t,d.constants.R_OK)}catch{t=a.default.resolve(process.cwd(),this.dirname),await n.default.access(t,d.constants.R_OK)}this.resolvedDirname=t}async validateOnlyOneJsFile(){let e=(await n.default.readdir(this.resolvedDirname)).filter(r=>r.endsWith(".js"));if(e.length===0)throw new Error(`Directory ${this.resolvedDirname} must have only one js file: it doesn't have any js file.`);if(e.length>1)throw new Error(`Directory ${this.resolvedDirname} must have only one js file: ${e.join(", ")}`);this.jsFile=this.pathResolve(e[0])}async filterInputFiles(){let t=await n.default.readdir(this.resolvedDirname),e=t.filter(s=>s.endsWith(".in")),r=[];for(let s of e){let m=`${s.replace(/\.in$/,"")}.out`;t.includes(m)&&r.push([s,m])}this.inoutPair=r.map(([s,o])=>[this.pathResolve(s),this.pathResolve(o)])}pathResolve(t){return a.default.resolve(this.resolvedDirname,t)}async runTestCase(t,e){let r=await n.default.readFile(e,"utf-8"),{stdout:s,stderr:o}=await P(`node ${this.jsFile} < ${t}`);if(o)throw new Error(o);if(!this.isSame(s,r))throw new Error(`Expected: ${r.trimEnd()} Actual: ${s.trimEnd()} Input: ${t.replace(new RegExp("^"+this.resolvedDirname+"/"),"")}`)}isSame(t,e){return t.trimEnd()===e.trimEnd()}};(0,w.runExit)(l);