From 3713972e8766d034bb476f5dc2b27780a2a47c8a Mon Sep 17 00:00:00 2001 From: Rachana Acharya Date: Sun, 2 Feb 2020 11:22:17 -0700 Subject: [PATCH 1/4] Add a test file to test GetKeys of the Scope class --- .../com/mitchellbosecke/pebble/ScopeTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java diff --git a/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java b/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java new file mode 100644 index 000000000..0ca9d67e6 --- /dev/null +++ b/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java @@ -0,0 +1,28 @@ +package com.mitchellbosecke.pebble; + +import com.mitchellbosecke.pebble.template.Scope; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class ScopeTest { + + @Test + void testGetKeys() { + Map map = new HashMap<>(); + map.putIfAbsent("key1", new String("value1")); + map.putIfAbsent("key2", new String("value2")); + + Scope scope = new Scope(map, false); + Set expected = new HashSet<>(); + expected.add("key1"); + expected.add("key2"); + + assertEquals(expected, scope.GetKeys()); + } +} From 78ebb6f48fed8752e25b4964af92b6e7e3817b7c Mon Sep 17 00:00:00 2001 From: Rachana Acharya Date: Sun, 2 Feb 2020 11:22:58 -0700 Subject: [PATCH 2/4] Add a GetKeys method --- .../com/mitchellbosecke/pebble/template/Scope.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java b/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java index 8b09a5d99..039e01987 100644 --- a/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java +++ b/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java @@ -9,6 +9,7 @@ package com.mitchellbosecke.pebble.template; import java.util.HashMap; +import java.util.Set; import java.util.Map; /** @@ -96,4 +97,13 @@ public boolean containsKey(String key) { public boolean isLocal() { return this.local; } + + /** + * Returns keys of all the variables at this scope. + * + * @return A set of keys + */ + public Set GetKeys(){ + return backingMap.keySet(); + } } From 207f53c9fb28c3abf664b66e4603c4694d1c2da7 Mon Sep 17 00:00:00 2001 From: Rachana Acharya Date: Sun, 2 Feb 2020 11:47:59 -0700 Subject: [PATCH 3/4] Change method name to camelCase --- .../main/java/com/mitchellbosecke/pebble/template/Scope.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java b/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java index 039e01987..b16001753 100644 --- a/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java +++ b/pebble/src/main/java/com/mitchellbosecke/pebble/template/Scope.java @@ -103,7 +103,7 @@ public boolean isLocal() { * * @return A set of keys */ - public Set GetKeys(){ + public Set getKeys(){ return backingMap.keySet(); } } From 4607e1e3dc42106a294906fced26bcc61f3c998e Mon Sep 17 00:00:00 2001 From: Rachana Acharya Date: Sun, 2 Feb 2020 11:51:41 -0700 Subject: [PATCH 4/4] Fix test --- pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java b/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java index 0ca9d67e6..8ef59acb9 100644 --- a/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java +++ b/pebble/src/test/java/com/mitchellbosecke/pebble/ScopeTest.java @@ -23,6 +23,6 @@ void testGetKeys() { expected.add("key1"); expected.add("key2"); - assertEquals(expected, scope.GetKeys()); + assertEquals(expected, scope.getKeys()); } }