Skip to content

Commit

Permalink
Merge pull request #1153 from HubSpot/sorted-map-pprint
Browse files Browse the repository at this point in the history
Make output of map sorted by key in pprint.
  • Loading branch information
hs-lsong authored Feb 7, 2024
2 parents 6003ef0 + 9ac4f6e commit ea37bb6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Empty file added .build-jdk17
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.hubspot.jinjava.objects.date.PyishDate;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;

@JinjavaDoc(
value = "Pretty print a variable. Useful for debugging.",
Expand Down Expand Up @@ -45,10 +46,12 @@ public Object filter(Object var, JinjavaInterpreter interpreter, String... args)
var instanceof String ||
var instanceof Number ||
var instanceof PyishDate ||
var instanceof Iterable ||
var instanceof Map
var instanceof Iterable
) {
varStr = Objects.toString(var);
} else if (var instanceof Map) {
TreeMap map = new TreeMap((Map) var);
varStr = Objects.toString(map);
} else {
try {
varStr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void ppPyDate() {

@Test
public void ppMap() {
assertThat(f.filter(ImmutableMap.of("a", "foo", "b", "bar"), null))
.isEqualTo("{% raw %}(RegularImmutableMap: {a=foo, b=bar}){% endraw %}");
assertThat(f.filter(ImmutableMap.of("b", "foo", "a", "bar"), null))
.isEqualTo("{% raw %}(RegularImmutableMap: {a=bar, b=foo}){% endraw %}");
}

@Test
Expand Down

0 comments on commit ea37bb6

Please sign in to comment.