private static boolean test(String name, String file, boolean inputCr, boolean outputCr) throws Exception {
int extIdx=file.lastIndexOf('.');
boolean isJson=extIdx>=0 && file.substring(extIdx).equals(".json");
boolean shouldFail=name.startsWith("fail");
JsonValue.setEol(outputCr?"\r\n":"\n");
String text=load(file, inputCr);
try {
HjsonOptions opt=new HjsonOptions();
opt.setParseLegacyRoot(false);
JsonValue data=JsonValue.readHjson(text, opt);
String data1=data.toString(Stringify.FORMATTED);
String hjson1=data.toString(Stringify.HJSON);
if (!shouldFail) {
JsonValue result=JsonValue.readJSON(load(name+"_result.json", inputCr));
String data2=result.toString(Stringify.FORMATTED);
String hjson2=load(name+"_result.hjson", outputCr);
if (!data1.equals(data2)) return failErr(name, "parse", data1, data2);
if (!hjson1.equals(hjson2)) return failErr(name, "stringify", hjson1, hjson2);
if (isJson) {
String json1=data.toString(), json2=JsonValue.readHjson(text, opt).toString();
if (!json1.equals(json2)) return failErr(name, "json chk", json1, json2);
}
}
else return failErr(name, "should fail", null, null);
}
catch (Exception e) {
if (!shouldFail) return failErr(name, "exception", e.toString(), "");
}
return true;
}