aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2018-03-22 08:32:01 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-22 08:33:15 -0700
commit8c434685584388a6e5e1b70685e9d9acbb948831 (patch)
tree762545b6f1a82f7895a2134dc14132813c5c2454 /src/test
parent3dc6c7253ef273530702fa84e1bf67f416a49da6 (diff)
RELNOTES: In int() function, do not auto-detect base if input starts with '0'.
PiperOrigin-RevId: 190069001
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
index 6553a3d88e..fd7365136c 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
@@ -967,6 +967,7 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testIfErrorContains("invalid literal for int() with base 10: \"1.5\"", "int('1.5')")
.testIfErrorContains("invalid literal for int() with base 10: \"ab\"", "int('ab')")
.testStatement("int(42)", 42)
+ .testStatement("int('016')", 16)
.testStatement("int(-1)", -1)
.testStatement("int(True)", 1)
.testStatement("int(False)", 0)
@@ -982,12 +983,17 @@ public class MethodLibraryTest extends EvaluationTestCase {
.testStatement("int('11', 36)", 37)
.testStatement("int('az', 36)", 395)
.testStatement("int('11', 10)", 11)
- .testStatement("int('11', 0)", 11);
+ .testStatement("int('11', 0)", 11)
+ .testStatement("int('016', 8)", 14)
+ .testStatement("int('016', 16)", 22);
}
@Test
public void testIntWithBase_InvalidBase() throws Exception {
new BothModesTest()
+ .testIfErrorContains(
+ "cannot infer base for int() when value begins with a 0: \"016\"",
+ "int('016', 0)")
.testIfExactError("invalid literal for int() with base 3: \"123\"", "int('123', 3)")
.testIfExactError("invalid literal for int() with base 15: \"FF\"", "int('FF', 15)")
.testIfExactError("int() base must be >= 2 and <= 36", "int('123', -1)")