From 0b6a7578116d8a73956bc07b65542bd6ff067901 Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Wed, 6 Dec 2023 05:55:43 -0500 Subject: [PATCH] fix windows tests --- .../experimental/lua/GenerateLuaTypes.java | 7 +++--- .../lua/GenerateLuaTypesTest.java | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypes.java b/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypes.java index 93f1ee22b7..1e9bd0037e 100644 --- a/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypes.java +++ b/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypes.java @@ -88,6 +88,7 @@ public class GenerateLuaTypes { private final Deque debugStack = new LinkedList<>(); private final Set handled = new HashSet<>(); private final StringBuilder builder = new StringBuilder(); + private static final String NEWLINE = System.lineSeparator(); GenerateLuaTypes() { write(""" @@ -151,7 +152,7 @@ private static boolean isLowerCamelCase(String fieldName) { } private void write(String line) { - builder.append(line).append("\n"); + builder.append(line).append(NEWLINE); } GenerateLuaTypes generatePlanetiler() { @@ -487,7 +488,7 @@ void write(StringBuilder builder) { nameToUse += "__enum"; builder.append("---@alias %s%n".formatted(name)); builder.append("---|%s%n".formatted(nameToUse)); - builder.append("---|integer\n"); + builder.append("---|integer").append(NEWLINE); for (var constant : type.getRawType().getEnumConstants()) { builder.append("---|%s%n".formatted(Format.quote(constant.toString()))); } @@ -496,7 +497,7 @@ void write(StringBuilder builder) { if (!parents.isEmpty()) { builder.append(" : ").append(String.join(", ", parents)); } - builder.append("\n"); + builder.append(NEWLINE); for (var field : fields.values()) { field.write(builder); } diff --git a/planetiler-experimental/src/test/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypesTest.java b/planetiler-experimental/src/test/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypesTest.java index 047a461672..cf1aaf788c 100644 --- a/planetiler-experimental/src/test/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypesTest.java +++ b/planetiler-experimental/src/test/java/com/onthegomap/planetiler/experimental/lua/GenerateLuaTypesTest.java @@ -362,9 +362,7 @@ public static int staticMethod(int arg) { @Test void testStaticLuaInstanceWithConsructors() { - var g = new GenerateLuaTypes(); - var actual = g.getStaticTypeDefinition(StaticClass.class).trim(); - assertEquals( + assertGeneratedStatic( """ ---@class (exact) com_onthegomap_planetiler_experimental_lua_GenerateLuaTypesTest_StaticClass__class ---@field CONSTANT integer @@ -380,7 +378,7 @@ void testStaticLuaInstanceWithConsructors() { function types.com_onthegomap_planetiler_experimental_lua_GenerateLuaTypesTest_StaticClass__class:static_method(arg) end """ .trim(), - actual, "got:\n\n" + actual + "\n\n"); + StaticClass.class); } @Test @@ -479,8 +477,20 @@ void testGeneratedMetaFileCompiles() { } private static void assertGenerated(String expected, Class clazz) { + assertGenerated(expected, clazz, false); + } + + private static void assertGeneratedStatic(String expected, Class clazz) { + assertGenerated(expected, clazz, true); + } + + private static void assertGenerated(String expected, Class clazz, boolean staticType) { var g = new GenerateLuaTypes(); - var actual = g.getTypeDefinition(clazz).trim(); - assertEquals(expected.trim(), actual, "got:\n\n" + actual + "\n\n"); + var actual = (staticType ? g.getStaticTypeDefinition(clazz) : g.getTypeDefinition(clazz)).trim(); + assertEquals(fixNewlines(expected.trim()), fixNewlines(actual), "got:%n%n%s%n%n".formatted(actual)); + } + + private static String fixNewlines(String input) { + return input.replaceAll("[\n\r]]", System.lineSeparator()); } }