aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar brandjon <brandjon@google.com>2018-05-24 13:35:26 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-24 13:36:46 -0700
commit33f08e75fa4e7480f8d46b8305ce03a171adefa0 (patch)
tree29a682033c07a166fae812a303a7d3ba805233ea /src/test/java
parentbfacee1b5dd0635e82e78e4221cadeadc49ad56d (diff)
Add test that range() returns a list
This is useful before we optimize range() to return a lazy object that appears like a list to the user. RELNOTES: None PiperOrigin-RevId: 197944773
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java18
1 files changed, 18 insertions, 0 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 76b643259f..20db34609c 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
@@ -490,6 +490,24 @@ public class MethodLibraryTest extends EvaluationTestCase {
}
@Test
+ public void testRangeIsList() throws Exception {
+ // range() may change in the future to a read-only view, but for now it's a list and can be
+ // updated. This test ensures we won't break backward compatibility until we intend to.
+ new BothModesTest()
+ .testStatement("a = range(2); a.append(2); str(a)", "[0, 1, 2]")
+ .testStatement("a = range(2); type(a)", "list");
+ new SkylarkTest()
+ .testStatement(
+ "def f():\n"
+ + " a = range(2)\n"
+ + " b = a\n"
+ + " a += [2]\n"
+ + " return str(b)\n"
+ + "f()\n",
+ "[0, 1, 2]");
+ }
+
+ @Test
public void testEnumerate() throws Exception {
new BothModesTest()
.testStatement("str(enumerate([]))", "[]")