From c8649daecc1748f65c5d4437cef1dd345a03d5fd Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 4 Sep 2025 08:39:49 +0000 Subject: [PATCH] test: add comprehensive whitespace handling tests for XML parser - Add tests for spaces between XML tags - Add tests for newlines and mixed whitespace in nested XML - Add tests for multiple files with whitespace - Add tests for tabs and mixed whitespace scenarios - Verify that trimValues option correctly handles whitespace These tests confirm that the XML parser already handles whitespace correctly with trimValues: true, addressing issue #7664 --- src/utils/__tests__/xml.spec.ts | 109 ++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/src/utils/__tests__/xml.spec.ts b/src/utils/__tests__/xml.spec.ts index f7a282b0c0..7e4b3e291f 100644 --- a/src/utils/__tests__/xml.spec.ts +++ b/src/utils/__tests__/xml.spec.ts @@ -1,6 +1,115 @@ import { parseXml, parseXmlForDiff } from "../xml" describe("parseXml", () => { + describe("whitespace handling", () => { + it("should handle spaces between XML tags", () => { + const xml = ` + + ./test/file.ts + + ` + + const result = parseXml(xml) as any + + expect(result.read_file).toBeDefined() + expect(result.read_file.path).toBe("./test/file.ts") + }) + + it("should handle newlines and spaces in nested XML", () => { + const xml = ` + + + + ./src/main.ts + + + + ` + + const result = parseXml(xml) as any + + expect(result.args).toBeDefined() + expect(result.args.file).toBeDefined() + expect(result.args.file.path).toBe("./src/main.ts") + }) + + it("should handle multiple files with whitespace", () => { + const xml = ` + + + ./file1.ts + + + + ./file2.ts + + + + ` + + const result = parseXml(xml) as any + + expect(result.args).toBeDefined() + expect(Array.isArray(result.args.file)).toBe(true) + expect(result.args.file).toHaveLength(2) + expect(result.args.file[0].path).toBe("./file1.ts") + expect(result.args.file[1].path).toBe("./file2.ts") + }) + + it("should handle mixed content with whitespace", () => { + const xml = ` + + + ./output.txt + + + Some content here + + + ` + + const result = parseXml(xml) as any + + expect(result.write_to_file).toBeDefined() + expect(result.write_to_file.path).toBe("./output.txt") + expect(result.write_to_file.content).toBe("Some content here") + }) + + it("should handle empty tags with whitespace", () => { + const xml = ` + + + + + + + ` + + const result = parseXml(xml) as any + + expect(result.test).toBeDefined() + expect(result.test.empty).toBe("") + expect(result.test.another).toBe("") + }) + + it("should handle tabs and mixed whitespace", () => { + const xml = ` + + ./file.ts + + arg1 arg2 + + + ` + + const result = parseXml(xml) as any + + expect(result.command).toBeDefined() + expect(result.command.path).toBe("./file.ts") + expect(result.command.args).toBe("arg1 arg2") + }) + }) + describe("type conversion", () => { // Test the main change from the commit: no automatic type conversion it("should not convert string numbers to numbers", () => {