aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
diff options
context:
space:
mode:
authorGravatar vladmos <vladmos@google.com>2017-06-30 14:01:45 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-07-03 09:04:59 +0200
commit469079377a9561a7c2cc7a46492c44e012b9fb33 (patch)
tree7b9baaf83c2a9ee2c9a57862d833ae72d5ae9305 /src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
parent86c9d942452d82a479d499ffe61695a983f16bba (diff)
Refactor Printer
It's now easier to customize Printer if in different situations objects should be printed differently. Also its API is cleaner now. Names of methods of SkylarkValue objects now reflect names of Skylark functions: SkylarkValue#repr and SkylarkPrintableValue#str. PiperOrigin-RevId: 160635154
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java38
1 files changed, 4 insertions, 34 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 0a7f8410a8..fdf43271bb 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
@@ -98,12 +98,12 @@ public class PrinterTest {
@Test
public void testFormatPositional() throws Exception {
- assertThat(Printer.formatToString("%s %d", Tuple.of("foo", 3))).isEqualTo("foo 3");
+ assertThat(Printer.formatWithList("%s %d", Tuple.of("foo", 3))).isEqualTo("foo 3");
assertThat(Printer.format("%s %d", "foo", 3)).isEqualTo("foo 3");
// Note: formatToString doesn't perform scalar x -> (x) conversion;
// The %-operator is responsible for that.
- assertThat(Printer.formatToString("", Tuple.of())).isEmpty();
+ assertThat(Printer.formatWithList("", Tuple.of())).isEmpty();
assertThat(Printer.format("%s", "foo")).isEqualTo("foo");
assertThat(Printer.format("%s", 3.14159)).isEqualTo("3.14159");
checkFormatPositionalFails("not all arguments converted during string formatting",
@@ -131,34 +131,6 @@ public class PrinterTest {
}
@Test
- public void testSingleQuotes() throws Exception {
- assertThat(Printer.str("test", '\'')).isEqualTo("test");
- assertThat(Printer.repr("test", '\'')).isEqualTo("'test'");
-
- assertThat(Printer.repr("'", '\'')).isEqualTo("'\\''");
- assertThat(Printer.str("\"", '\'')).isEqualTo("\"");
- assertThat(Printer.repr("\"", '\'')).isEqualTo("'\"'");
-
- List<?> list = MutableList.of(null, "foo", "bar");
- List<?> tuple = Tuple.of("foo", "bar");
-
- assertThat(Printer.str(Tuple.of(1, list, 3), '\'')).isEqualTo("(1, ['foo', 'bar'], 3)");
- assertThat(Printer.repr(Tuple.of(1, list, 3), '\'')).isEqualTo("(1, ['foo', 'bar'], 3)");
- assertThat(Printer.str(MutableList.of(null, 1, tuple, 3), '\''))
- .isEqualTo("[1, ('foo', 'bar'), 3]");
- assertThat(Printer.repr(MutableList.of(null, 1, tuple, 3), '\''))
- .isEqualTo("[1, ('foo', 'bar'), 3]");
-
- Map<Object, Object> dict =
- ImmutableMap.<Object, Object>of(1, tuple, 2, list, "foo", MutableList.of(null));
-
- assertThat(Printer.str(dict, '\''))
- .isEqualTo("{1: ('foo', 'bar'), 2: ['foo', 'bar'], 'foo': []}");
- assertThat(Printer.repr(dict, '\''))
- .isEqualTo("{1: ('foo', 'bar'), 2: ['foo', 'bar'], 'foo': []}");
- }
-
- @Test
public void testListLimitStringLength() throws Exception {
int lengthDivisibleByTwo = Printer.SUGGESTED_CRITICAL_LIST_ELEMENTS_STRING_LENGTH;
if (lengthDivisibleByTwo % 2 == 1) {
@@ -249,9 +221,7 @@ public class PrinterTest {
}
private String printList(List<?> list, int criticalElementsCount, int criticalStringLength) {
- StringBuilder builder = new StringBuilder();
- Printer.printList(
- builder, list, "[", ", ", "]", "", '"', criticalElementsCount, criticalStringLength);
- return builder.toString();
+ return Printer.printAbbreviatedList(
+ list, "[", ", ", "]", "", criticalElementsCount, criticalStringLength);
}
}