Skip to content

Commit e1bac10

Browse files
committed
add keys function to dictionary
1 parent 7ba2d6b commit e1bac10

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/com/hubspot/jinjava/objects/collections/PyMap.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public Set<java.util.Map.Entry<String, Object>> items() {
3838
return entrySet();
3939
}
4040

41+
public Set<String> keys() {
42+
return keySet();
43+
}
44+
4145
public void update(Map<? extends String, ? extends Object> m) {
4246
if (m == this) {
4347
throw new IllegalArgumentException("Can't update map object with itself");

src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public void itDoesItemsMethodCall() {
4444
.isInstanceOf(Set.class);
4545
}
4646

47+
@Test
48+
public void itDoesKeysMethodCall() {
49+
interpreter.getContext().put("foo", ImmutableMap.of(TestEnum.BAR, "test"));
50+
assertThat(interpreter.resolveELExpression("foo.keys()", -1)).isInstanceOf(Set.class);
51+
}
52+
4753
@Test
4854
public void itHandlesEmptyMaps() {
4955
interpreter.getContext().put("foo", ImmutableMap.of());

0 commit comments

Comments
 (0)