diff options
author | 2018-06-14 08:17:33 -0700 | |
---|---|---|
committer | 2018-06-14 08:18:48 -0700 | |
commit | 3695591d4b40497380640d7886c55a00d4d3fd70 (patch) | |
tree | d546e70bc02e582a1508e5093a153c8c26da03c2 /src/test | |
parent | 09222fac7c8851d26e44e087a6beb4ce2ed5dc39 (diff) |
Skylark Pretty Printer: shorten empty list
When pretty printing a Skylark value, lists are presented as the
opening bracket on a line by itself, each entry on its own line,
and the closing bracket again on its own line. While this generally
improves readability, for the empty list this is not the case, as
the expression [] can easily be understood at a glance. In fact, the
additional line even makes the outer structure harder to see, as it
is spread over even more lines. Therefore, shorten the printing of
the empty list to be on a single line.
Change-Id: I032d1550b1f99bce47dbec7e77a4d5c6656d78a1
PiperOrigin-RevId: 200558784
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java index 37ff47a0bf..d6c165931b 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java @@ -148,6 +148,10 @@ public class PrinterTest { " 2,\n" + " 3\n" + "]"); + assertThat(Printer.getPrettyPrinter().repr(ImmutableList.<String>of()).toString()) + .isEqualTo("[]"); + assertThat(Printer.getPrettyPrinter().repr(ImmutableList.of("foo")).toString()) + .isEqualTo("[\n \"foo\"\n]"); assertThat( Printer.getPrettyPrinter() .repr(ImmutableMap.<Object, Object>of("foo", "bar", "baz", ImmutableList.of(1, 2))) @@ -160,6 +164,17 @@ public class PrinterTest { " 2\n" + " ]\n" + "}"); + assertThat( + Printer.getPrettyPrinter() + .repr(ImmutableMap.<Object, Object>of( + "foo", "bar", "empty", ImmutableList.of(), "a", "b")) + .toString()) + .isEqualTo( + "{\n" + + " \"foo\": \"bar\",\n" + + " \"empty\": [],\n" + + " \"a\": \"b\"\n" + + "}"); } private SkylarkPrinter makeSimplifiedFormatPrinter() { |