Skip to content

Commit

Permalink
fix windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Dec 6, 2023
1 parent 70cab25 commit 0b6a757
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class GenerateLuaTypes {
private final Deque<String> debugStack = new LinkedList<>();
private final Set<String> handled = new HashSet<>();
private final StringBuilder builder = new StringBuilder();
private static final String NEWLINE = System.lineSeparator();

GenerateLuaTypes() {
write("""
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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())));
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 0b6a757

Please sign in to comment.