diff --git a/src/apktool/ApktoolDecodeOutput.test.ts b/src/apktool/ApktoolDecodeOutput.test.ts
index a45048e4838..d25c34e9a22 100644
--- a/src/apktool/ApktoolDecodeOutput.test.ts
+++ b/src/apktool/ApktoolDecodeOutput.test.ts
@@ -4,6 +4,7 @@ import { ok } from "../domain/result.js";
import {
parseApktoolYml,
parseDecodedStrings,
+ type DecodedStringEntry,
parseManifestPackage,
} from "./ApktoolDecodeOutput.js";
@@ -298,6 +299,14 @@ describe("parseManifestPackage", () => {
});
});
+const expectDecodedStrings = (
+ xml: string,
+ entries: readonly DecodedStringEntry[],
+ unparsedCount: number,
+): void => {
+ expect(parseDecodedStrings(xml)).toEqual(ok({ entries, unparsedCount }));
+};
+
describe("parseDecodedStrings", () => {
it("projects entries from a real decoded strings.xml", () => {
const stringsXml = [
@@ -309,61 +318,47 @@ describe("parseDecodedStrings", () => {
"",
"",
].join("\n");
- expect(parseDecodedStrings(stringsXml)).toEqual(
- ok({
- entries: [
- { name: "api_endpoint", value: "https://api.example.com/v1" },
- { name: "app_name", value: "ApktoolProbe" },
- { name: "debug_flag", value: "true" },
- ],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ stringsXml,
+ [
+ { name: "api_endpoint", value: "https://api.example.com/v1" },
+ { name: "app_name", value: "ApktoolProbe" },
+ { name: "debug_flag", value: "true" },
+ ],
+ 0,
);
});
it("counts entries with nested markup instead of flattening them", () => {
const stringsXml =
'Hello worldok';
- expect(parseDecodedStrings(stringsXml)).toEqual(
- ok({
- entries: [{ name: "plain", value: "ok" }],
- unparsedCount: 1,
- }),
- );
+ expectDecodedStrings(stringsXml, [{ name: "plain", value: "ok" }], 1);
});
it("preserves escaped entities verbatim", () => {
const stringsXml =
'a & b <c>';
- expect(parseDecodedStrings(stringsXml)).toEqual(
- ok({
- entries: [{ name: "escaped", value: "a & b <c>" }],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ stringsXml,
+ [{ name: "escaped", value: "a & b <c>" }],
+ 0,
);
});
it("ignores foreign namespace string elements", () => {
const xml =
'decoyone';
- expect(parseDecodedStrings(xml)).toEqual(
- ok({ entries: [{ name: "local", value: "one" }], unparsedCount: 0 }),
- );
+ expectDecodedStrings(xml, [{ name: "local", value: "one" }], 0);
});
it("preserves literal U+FFFD and unaffected sibling strings", () => {
- expect(
- parseDecodedStrings(
- 'Hello\uFFFD',
- ),
- ).toEqual(
- ok({
- entries: [
- { name: "good", value: "Hello" },
- { name: "edge", value: "\uFFFD" },
- ],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ 'Hello\uFFFD',
+ [
+ { name: "good", value: "Hello" },
+ { name: "edge", value: "\uFFFD" },
+ ],
+ 0,
);
});
@@ -382,71 +377,46 @@ describe("parseDecodedStrings", () => {
});
it("keeps empty, self-closing, and reordered string attributes", () => {
- expect(
- parseDecodedStrings(
- '',
- ),
- ).toEqual(
- ok({
- entries: [
- { name: "empty", value: "" },
- { name: "paired", value: "" },
- ],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ '',
+ [
+ { name: "empty", value: "" },
+ { name: "paired", value: "" },
+ ],
+ 0,
);
});
it("ignores comments without mistaking them for nested markup", () => {
- expect(
- parseDecodedStrings(
- 'beforeafter',
- ),
- ).toEqual(
- ok({
- entries: [{ name: "real", value: "beforeafter" }],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ 'beforeafter',
+ [{ name: "real", value: "beforeafter" }],
+ 0,
);
});
it("does not include a trailing document comment in the last string", () => {
- expect(
- parseDecodedStrings(
- 'one',
- ),
- ).toEqual(
- ok({
- entries: [{ name: "a", value: "one" }],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ 'one',
+ [{ name: "a", value: "one" }],
+ 0,
);
});
it("preserves source whitespace and entity spelling", () => {
- expect(
- parseDecodedStrings(
- ' a & b ',
- ),
- ).toEqual(
- ok({
- entries: [{ name: "raw", value: " a & b " }],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ ' a & b ',
+ [{ name: "raw", value: " a & b " }],
+ 0,
);
});
it("keeps source slices aligned across CRLF and CR line endings", () => {
for (const newline of ["\r\n", "\r"]) {
- expect(
- parseDecodedStrings(
- `${newline} x & y${newline}`,
- ),
- ).toEqual(
- ok({
- entries: [{ name: "raw", value: "x & y" }],
- unparsedCount: 0,
- }),
+ expectDecodedStrings(
+ `${newline} x & y${newline}`,
+ [{ name: "raw", value: "x & y" }],
+ 0,
);
}
});
@@ -454,9 +424,11 @@ describe("parseDecodedStrings", () => {
describe("string document validity and omission counts", () => {
it("counts a string with no name as unsupported instead of emitting an empty name", () => {
- expect(
- parseDecodedStrings("value"),
- ).toEqual(ok({ entries: [], unparsedCount: 1 }));
+ expectDecodedStrings(
+ "value",
+ [],
+ 1,
+ );
});
it("distinguishes malformed XML from counted unsupported string markup", () => {
@@ -470,11 +442,11 @@ describe("string document validity and omission counts", () => {
failure: { format: "xml" },
},
});
- expect(
- parseDecodedStrings(
- 'Hello world',
- ),
- ).toEqual(ok({ entries: [], unparsedCount: 1 }));
+ expectDecodedStrings(
+ 'Hello world',
+ [],
+ 1,
+ );
});
});