From beacc083963eb2da09349cf5db9238085fad40bf Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 11 Nov 2024 09:58:30 -0800 Subject: [PATCH] Explicitly test that reformatting after formatting and string wrapping is idempotent There's some indirect coverage of this from line ending tests, but they don't exercise string wrapping. PiperOrigin-RevId: 695382884 --- .../java/FormatterIntegrationTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java index 3e4e175e6..ef6bef087 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java @@ -144,6 +144,19 @@ public void format() { } } + @Test + public void idempotent() { + try { + Formatter formatter = new Formatter(); + String formatted = formatter.formatSource(input); + formatted = StringWrapper.wrap(formatted, formatter); + String reformatted = formatter.formatSource(formatted); + assertEquals("bad output for " + name, formatted, reformatted); + } catch (FormatterException e) { + fail(String.format("Formatter crashed on %s: %s", name, e.getMessage())); + } + } + @Test public void idempotentLF() { try {