Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit ef8e7ee

Browse files
authored
Merge pull request #61 from praveenag/master
support for colon form of :param command.
2 parents 2e01e7b + 997e798 commit ef8e7ee

File tree

6 files changed

+24
-27
lines changed

6 files changed

+24
-27
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellIntegrationTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void commitScenario() throws CommandException {
162162
}
163163

164164
@Test
165-
public void setAndListVariables() throws CommandException {
165+
public void paramsAndListVariables() throws CommandException {
166166
assertTrue(shell.getAll().isEmpty());
167167

168168
long randomLong = System.currentTimeMillis();
@@ -178,8 +178,5 @@ public void setAndListVariables() throws CommandException {
178178
List<String> queryResult = captor.getAllValues();
179179
assertThat(queryResult.get(0), is("{ bob }\n" + randomLong));
180180
assertEquals(randomLong, shell.getAll().get("bob"));
181-
182-
shell.remove("bob");
183-
assertTrue(shell.getAll().isEmpty());
184181
}
185182
}

cypher-shell/src/main/java/org/neo4j/shell/CypherShell.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ public Map<String, Object> getAll() {
173173
return queryParams;
174174
}
175175

176-
@Override
177-
@Nonnull
178-
public Optional remove(@Nonnull String name) {
179-
return Optional.ofNullable(queryParams.remove(name));
180-
}
181-
182176
public void setCommandHelper(@Nonnull CommandHelper commandHelper) {
183177
this.commandHelper = commandHelper;
184178
}

cypher-shell/src/main/java/org/neo4j/shell/VariableHolder.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,4 @@ public interface VariableHolder {
2222
*/
2323
@Nonnull
2424
Map<String, Object> getAll();
25-
26-
/**
27-
*
28-
* @param name of variable to delete
29-
*/
30-
Optional remove(@Nonnull String name);
3125
}

cypher-shell/src/main/java/org/neo4j/shell/commands/Param.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
public class Param implements Command {
1818
// Match arguments such as "(key) (value with possible spaces)" where key and value are any strings
19-
private static final Pattern argPattern = Pattern.compile("^\\s*(?<key>[^\\s]+)\\s+(?<value>.+)$");
19+
private static final Pattern argPattern = Pattern.compile("^\\s*(?<key>.+?):?\\s+(?<value>.+)$");
2020
public static final String COMMAND_NAME = ":param";
2121
private final VariableHolder variableHolder;
2222

cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ public void verifyVariableMethods() throws CommandException {
144144
Optional result = offlineTestShell.set("bob", "99");
145145
assertEquals("99", result.get());
146146
assertEquals("99", offlineTestShell.getAll().get("bob"));
147-
148-
offlineTestShell.remove("bob");
149-
assertTrue(offlineTestShell.getAll().isEmpty());
150147
}
151148

152149
@Test
@@ -232,13 +229,6 @@ public void specifyingACypherStringShouldGiveAStringRunner() throws IOException
232229
}
233230
}
234231

235-
@Test
236-
public void unsetAlreadyClearedValue() throws CommandException {
237-
// when
238-
// then
239-
assertFalse("Expected param to be unset", offlineTestShell.remove("unknown var").isPresent());
240-
}
241-
242232
@Test
243233
public void setWithSomeBoltError() throws CommandException {
244234
// then

cypher-shell/src/test/java/org/neo4j/shell/commands/ParamTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,34 @@ public void setValue() throws CommandException {
5050
verify(mockShell).set("bob", "9");
5151
}
5252

53+
@Test
54+
public void setValueWithSpecialCharacters() throws CommandException {
55+
cmd.execute("bob# 9");
56+
57+
verify(mockShell).set("bob#", "9");
58+
}
59+
5360
@Test
5461
public void shouldNotSplitOnSpace() throws CommandException {
5562
cmd.execute("bob 'one two'");
5663
verify(mockShell).set("bob", "'one two'");
5764
}
5865

66+
@Test
67+
public void shouldAcceptColonFormOfParams() throws CommandException {
68+
cmd.execute("bob: one");
69+
verify(mockShell).set("bob", "one");
70+
}
71+
72+
@Test
73+
public void shouldAcceptForTwoColonsFormOfParams() throws CommandException {
74+
cmd.execute("bob:: one");
75+
verify(mockShell).set("bob:", "one");
76+
77+
cmd.execute("t:om two");
78+
verify(mockShell).set("t:om", "two");
79+
}
80+
5981
@Test
6082
public void shouldNotExecuteEscapedCypher() throws CommandException {
6183
cmd.execute("bob \"RETURN 5 as bob\"");

0 commit comments

Comments
 (0)