aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar brandjon <brandjon@google.com>2018-04-04 12:24:33 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-04 12:26:27 -0700
commita9cafcbf0b57f986ad652715ff3b734c52ec5dbd (patch)
treea58cbe9aace703a2572c02c7aa08f1168a11bae2 /src/test
parentc4987159509cd8de3f0c4070b53ea1bf3b8278cd (diff)
Add option to restrict format strings to %s
This is useful for contexts like ctx.actions.args()'s methods, where %d and %r aren't appropriate placeholders. RELNOTES: None PiperOrigin-RevId: 191629195
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java19
1 files changed, 19 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 5adbd10b4e..c19d145936 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
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static org.junit.Assert.fail;
import com.google.common.base.Joiner;
@@ -137,6 +138,24 @@ public class PrinterTest {
"%.s");
}
+ private SkylarkPrinter makeSimplifiedFormatPrinter() {
+ return new Printer.BasePrinter(new StringBuilder(), /*simplifiedFormatStrings=*/ true);
+ }
+
+ @Test
+ public void testSimplifiedDisallowsPlaceholdersBesidesPercentS() {
+ assertThat(makeSimplifiedFormatPrinter().format("Allowed: %%").toString())
+ .isEqualTo("Allowed: %");
+ assertThat(makeSimplifiedFormatPrinter().format("Allowed: %s", "abc").toString())
+ .isEqualTo("Allowed: abc");
+ assertThrows(
+ IllegalFormatException.class,
+ () -> makeSimplifiedFormatPrinter().format("Disallowed: %r", "abc"));
+ assertThrows(
+ IllegalFormatException.class,
+ () -> makeSimplifiedFormatPrinter().format("Disallowed: %d", 5));
+ }
+
@Test
public void testListLimitStringLength() throws Exception {
int lengthDivisibleByTwo = Printer.SUGGESTED_CRITICAL_LIST_ELEMENTS_STRING_LENGTH;