Skip to content

Commit

Permalink
#266 make mixed template generation order independant
Browse files Browse the repository at this point in the history
  • Loading branch information
casid committed Aug 31, 2023
1 parent f432fcd commit b4c5e28
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 2 additions & 5 deletions jte-kotlin/src/test/java/gg/jte/kotlin/DummyCodeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import gg.jte.CodeResolver;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class DummyCodeResolver implements CodeResolver {
private final Map<String, String> codeLookup = new HashMap<>();
private final Map<String, String> codeLookup = new TreeMap<>();

@Override
public String resolve(String name) {
Expand Down
10 changes: 10 additions & 0 deletions jte-kotlin/src/test/java/gg/jte/kotlin/TemplateEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,16 @@ void mixedTemplates_callJteFromKte_withParams() {
thenOutputIs("Hello, Java says 42, foo!");
}

@Test
void mixedTemplates_callJteFromKte_generateAll() {
dummyCodeResolver.givenCode("a.jte", "Java!"); // Hack: named 'a' to be generated first
dummyCodeResolver.givenCode(templateName = "b.kte", "Hello @template.a()");

List<String> generated = templateEngine.generateAll();

assertThat(generated).hasSize(2);
}

@Test
void nestedKotlinStringTemplates() {
givenRawTemplate("@import java.time.format.DateTimeFormatter\n" +
Expand Down
7 changes: 5 additions & 2 deletions jte/src/main/java/gg/jte/compiler/ClassDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ public boolean equals(Object o) {

ClassDefinition that = (ClassDefinition) o;

return name.equals(that.name);
if (!name.equals(that.name)) return false;
return extension.equals(that.extension);
}

@Override
public int hashCode() {
return name.hashCode();
int result = name.hashCode();
result = 31 * result + extension.hashCode();
return result;
}

public String getSourceFileName() {
Expand Down

0 comments on commit b4c5e28

Please sign in to comment.