test(native): distinguish plist validation from conversion

This commit is contained in:
morluto
2026-10-24 11:16:16 +08:00
parent 8736fe3226
commit dd198d037f
2 changed files with 37 additions and 14 deletions
@@ -66,14 +66,14 @@ it.for<TextSourceCase>([
},
{
name: "unknown XML scalar",
bytes: Buffer.from("<plist><integer> 42 </integer></plist>"),
bytes: Buffer.from("<plist><real>1e999</real></plist>"),
description: "XML 1.0 document text",
format: "xml",
value: {
$plist_type: "unknown",
element: "integer",
literal: " 42 ",
reason: "invalid-literal",
element: "real",
literal: "1e999",
reason: "unrepresentable",
},
limitations: [
expect.stringContaining("1 XML scalar value(s) could not be established"),
@@ -164,7 +164,14 @@ it.for<TextSourceCase>([
const conversion = fixture.conversions[conversionIndex++];
if (conversion === undefined)
throw new Error("Unexpected conversion of directly supported source");
expect(args[1]).toBe(conversion.format);
expect(args).toEqual([
"-convert",
conversion.format,
"-o",
"-",
"--",
path,
]);
return ok({
...result.value,
stdout: conversion.output,
@@ -27,6 +27,7 @@ const DATA = { $plist_type: "data", base64: "3q2+7w==" };
class PlistSourceRunner extends NativeFixtureRunner {
constructor(
private readonly path: string,
description: string,
private readonly xmlFallback: boolean,
private readonly convertedXml: string = XML,
@@ -36,8 +37,23 @@ class PlistSourceRunner extends NativeFixtureRunner {
override async run(tool: string, arguments_: readonly string[]) {
const result = await super.run(tool, arguments_);
if (!result.ok || tool !== "plutil" || !this.xmlFallback) return result;
const json = arguments_.includes("json");
if (!result.ok || tool !== "plutil") return result;
if (arguments_[0] === "-lint") {
expect(arguments_).toEqual(["-lint", "--", this.path]);
return ok({ ...result.value, stdout: "", stdoutBytes: 0 });
}
const format = arguments_[1];
expect(["json", "xml1"]).toContain(format);
expect(arguments_).toEqual([
"-convert",
format,
"-o",
"-",
"--",
this.path,
]);
if (!this.xmlFallback) return result;
const json = format === "json";
const stdout = json ? "" : this.convertedXml;
return ok({
...result.value,
@@ -87,7 +103,7 @@ it.for<PlistSourceCase>([
contents: ` \n${XML}`,
expected: "xml",
xmlFallback: true,
expectedTools: ["file"],
expectedTools: ["file", "plutil"],
expectedLimitations: [],
},
{
@@ -95,7 +111,7 @@ it.for<PlistSourceCase>([
contents: `<!-- source plist -->\n${XML}`,
expected: "xml",
xmlFallback: true,
expectedTools: ["file"],
expectedTools: ["file", "plutil"],
expectedLimitations: [],
},
...[false, true].map((bigEndian) => ({
@@ -105,7 +121,7 @@ it.for<PlistSourceCase>([
: Buffer.from(`\uFEFF${XML}`, "utf16le"),
expected: "xml",
xmlFallback: true,
expectedTools: ["file"],
expectedTools: ["file", "plutil"],
expectedLimitations: [],
})),
{ description: "ASCII text\n", expected: "unknown", xmlFallback: true },
@@ -120,7 +136,7 @@ it.for<PlistSourceCase>([
expected: "xml",
xmlFallback: false,
expectedValue: { ...VALUE, Blob: DATA },
expectedTools: ["file"],
expectedTools: ["file", "plutil"],
},
{
description:
@@ -128,7 +144,7 @@ it.for<PlistSourceCase>([
contents: Buffer.from("\uFEFF" + XML, "utf16le").swap16(),
expected: "xml",
xmlFallback: true,
expectedTools: ["file"],
expectedTools: ["file", "plutil"],
expectedLimitations: [],
},
{
@@ -162,7 +178,7 @@ it.for<PlistSourceCase>([
xmlFallback: true,
convertedXml:
"<plist><dict><key>nel</key><string>a\u0085b</string><key>ls</key><string>a\u2028b</string><key>ps</key><string>a\u2029b</string><key>lf</key><string>a\nb</string><key>payload</key><data>AA==</data></dict></plist>",
expectedTools: ["file"],
expectedTools: ["file", "plutil"],
expectedLimitations: [],
expectedValue: {
nel: "a\u0085b",
@@ -192,7 +208,7 @@ it.for<PlistSourceCase>([
await writeFile(path, contents);
const client = new NativeMacOSProvider(
{},
new PlistSourceRunner(description, xmlFallback, convertedXml),
new PlistSourceRunner(path, description, xmlFallback, convertedXml),
"darwin",
).createClient(nativeMachoTarget(join(root, "target")));
onTestFinished(async () => {