Commit cdc1a205 by Tomas Dvorak

Ascii output includes top and bottom border

parent 98eb5224
...@@ -52,10 +52,11 @@ public class OutputFormatTest { ...@@ -52,10 +52,11 @@ public class OutputFormatTest {
// filter only lines starting with character '|' // filter only lines starting with character '|'
final String actual = Stream.of(analysis.getStdOut().split("\n")) final String actual = Stream.of(analysis.getStdOut().split("\n"))
.filter(line -> line.startsWith("|")) .filter(line -> line.startsWith("|") || line.startsWith("+"))
.collect(Collectors.joining("\n")); .collect(Collectors.joining("\n"));
final String expected = final String expected =
"+------------------------------------------------------------+\n" +
"| key | types | occurrences | percents |\n" + "| key | types | occurrences | percents |\n" +
"| ------------------ | ------------ | ----------- | -------- |\n" + "| ------------------ | ------------ | ----------- | -------- |\n" +
"| _id | ObjectId | 5 | 100 |\n" + "| _id | ObjectId | 5 | 100 |\n" +
...@@ -64,7 +65,8 @@ public class OutputFormatTest { ...@@ -64,7 +65,8 @@ public class OutputFormatTest {
"| pets | String,Array | 2 | 40 |\n" + "| pets | String,Array | 2 | 40 |\n" +
"| birthday | String | 2 | 40 |\n" + "| birthday | String | 2 | 40 |\n" +
"| someBinData | BinData-old | 1 | 20 |\n" + "| someBinData | BinData-old | 1 | 20 |\n" +
"| someWeirdLegacyKey | String | 1 | 20 |"; "| someWeirdLegacyKey | String | 1 | 20 |\n" +
"+------------------------------------------------------------+";
Assert.assertEquals(expected, actual); Assert.assertEquals(expected, actual);
......
...@@ -235,7 +235,11 @@ if(outputFormat === 'json') { ...@@ -235,7 +235,11 @@ if(outputFormat === 'json') {
var pad = function(width, string, symbol) { return (width <= string.length) ? string : pad(width, string + symbol, symbol); }; var pad = function(width, string, symbol) { return (width <= string.length) ? string : pad(width, string + symbol, symbol); };
var output = "";
table.forEach(function(row, ri){ table.forEach(function(row, ri){
print("| " + row.map(function(cell, i) {return pad(colMaxWidth(table, i), cell, ri == 1 ? "-" : " ");}).join(" | ") + " |"); output += ("| " + row.map(function(cell, i) {return pad(colMaxWidth(table, i), cell, ri == 1 ? "-" : " ");}).join(" | ") + " |\n");
}); });
var lineLength = output.split("\n")[0].length - 2; // length of first (header) line minus two chars for edges
var border = "+" + pad(lineLength, "", "-") + "+";
print(border + "\n" + output + border);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment