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

Commit b97583d

Browse files
committed
Fix Path formatting, fixes #102
1 parent 9930540 commit b97583d

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/OutputFormatter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,12 @@ default String pathAsString(@Nonnull Path path) {
6767
for (Path.Segment segment : path) {
6868
Relationship relationship = segment.relationship();
6969
if (relationship.startNodeId() == lastTraversed.id()) {
70-
//-[:r]->
7170
list.add("-" + relationshipAsString(relationship) + "->");
72-
list.add(nodeAsString(segment.end()));
73-
lastTraversed = segment.start();
7471
} else {
7572
list.add("<-" + relationshipAsString(relationship) + "-");
76-
list.add(nodeAsString(segment.end()));
77-
lastTraversed = segment.end();
7873
}
74+
list.add(nodeAsString(segment.end()));
75+
lastTraversed = segment.end();
7976
}
8077
}
8178

cypher-shell/src/test/java/org/neo4j/shell/prettyprint/TableOutputFormatTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,70 @@ public void prettyPrintRelationships() throws Exception {
150150
assertThat(actual, containsString("| [:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}] |"));
151151
}
152152

153+
@Test
154+
public void prettyPrintPath() throws Exception {
155+
// given
156+
BoltResult result = mock(BoltResult.class);
157+
Record record = mock(Record.class);
158+
Value value = mock(Value.class);
159+
Path path = mock(Path.class);
160+
161+
162+
Node n1 = mock(Node.class);
163+
when(n1.id()).thenReturn(1L);
164+
when(n1.labels()).thenReturn(asList("L1"));
165+
when(n1.asMap(anyObject())).thenReturn(Collections.emptyMap());
166+
167+
Relationship r1 = mock(Relationship.class);
168+
when(r1.startNodeId()).thenReturn(2L);
169+
when(r1.type()).thenReturn("R1");
170+
when(r1.asMap(anyObject())).thenReturn(Collections.emptyMap());
171+
172+
Node n2 = mock(Node.class);
173+
when(n2.id()).thenReturn(2L);
174+
when(n2.labels()).thenReturn(asList("L2"));
175+
when(n2.asMap(anyObject())).thenReturn(Collections.emptyMap());
176+
177+
Relationship r2 = mock(Relationship.class);
178+
when(r2.startNodeId()).thenReturn(2L);
179+
when(r2.type()).thenReturn("R2");
180+
when(r2.asMap(anyObject())).thenReturn(Collections.emptyMap());
181+
182+
Node n3 = mock(Node.class);
183+
when(n3.id()).thenReturn(3L);
184+
when(n3.labels()).thenReturn(asList("L3"));
185+
when(n3.asMap(anyObject())).thenReturn(Collections.emptyMap());
186+
187+
Path.Segment s1 = mock(Path.Segment.class);
188+
when(s1.relationship()).thenReturn(r1);
189+
when(s1.start()).thenReturn(n1);
190+
when(s1.end()).thenReturn(n2);
191+
192+
Path.Segment s2 = mock(Path.Segment.class);
193+
when(s2.relationship()).thenReturn(r2);
194+
when(s2.start()).thenReturn(n2);
195+
when(s2.end()).thenReturn(n3);
196+
197+
when(path.start()).thenReturn(n1);
198+
when(path.iterator()).thenAnswer((i) -> Arrays.asList(s1,s2).iterator());
199+
200+
when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
201+
when(value.asPath()).thenReturn(path);
202+
203+
when(record.keys()).thenReturn(asList("path"));
204+
when(record.get(eq("path"))).thenReturn(value);
205+
when(record.values()).thenReturn(asList(value));
206+
when(record.asMap(anyObject())).thenReturn(Collections.singletonMap("path",value));
207+
when(result.getRecords()).thenReturn(asList(record));
208+
when(result.getSummary()).thenReturn(mock(ResultSummary.class));
209+
210+
// when
211+
String actual = verbosePrinter.format(result);
212+
213+
// then
214+
assertThat(actual, containsString("| (:L1)<-[:R1]-(:L2)-[:R2]->(:L3) |"));
215+
}
216+
153217
@Test
154218
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() throws Exception {
155219
BoltResult result = mock(BoltResult.class);

0 commit comments

Comments
 (0)