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

Commit c605063

Browse files
committed
Fix misaligned Explain.
1 parent 35db911 commit c605063

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public String formatInfo(@Nonnull ResultSummary summary) {
158158
String[] columns = info.keySet().toArray(new String[0]);
159159
StringBuilder sb = new StringBuilder();
160160
Record record = new InternalRecord(asList(columns), info.values().toArray(new Value[0]));
161-
formatResultAndCountRows(columns, Collections.singletonList(record).iterator(), sb::append);
161+
formatResultAndCountRows(columns, Collections.singletonList(record).iterator(), line -> sb.append( line).append( OutputFormatter.NEWLINE) );
162162
return sb.toString();
163163
}
164164

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static java.util.Arrays.asList;
2121
import static java.util.Collections.singletonMap;
2222
import static org.hamcrest.CoreMatchers.is;
23+
import static org.hamcrest.CoreMatchers.startsWith;
2324
import static org.hamcrest.MatcherAssert.assertThat;
2425
import static org.hamcrest.core.StringContains.containsString;
2526
import static org.mockito.Matchers.anyObject;
@@ -62,6 +63,36 @@ public void prettyPrintPlanInformation() {
6263
});
6364
}
6465

66+
@Test
67+
public void prettyPrintPlanInformationWithNewlines() {
68+
// given
69+
ResultSummary resultSummary = mock(ResultSummary.class);
70+
ProfiledPlan plan = mock(ProfiledPlan.class);
71+
72+
when(resultSummary.hasPlan()).thenReturn(true);
73+
when(resultSummary.hasProfile()).thenReturn(false);
74+
when(resultSummary.plan()).thenReturn(plan);
75+
when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
76+
when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
77+
when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY);
78+
Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v);
79+
when(plan.arguments()).thenReturn(argumentMap);
80+
81+
BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
82+
83+
// when
84+
String actual = verbosePrinter.format(result);
85+
86+
// THEN
87+
assertThat(actual, startsWith(String.join(NEWLINE,
88+
"+--------------------------------------------------------------------+",
89+
"| Plan | Statement | Version | Planner | Runtime | Time |",
90+
"+--------------------------------------------------------------------+",
91+
"| \"EXPLAIN\" | \"READ_ONLY\" | \"3.1\" | \"COST\" | \"INTERPRETED\" | 12 |",
92+
"+--------------------------------------------------------------------+",
93+
NEWLINE)));
94+
}
95+
6596
@Test
6697
public void prettyPrintPoint() {
6798
// given

0 commit comments

Comments
 (0)