Skip to content

Commit

Permalink
Add test that range() returns a list
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brandjon authored and Copybara-Service committed May 24, 2018
1 parent bfacee1 commit 33f08e7
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,24 @@ public void testRange() throws Exception {
.testIfErrorContains("step cannot be 0", "range(2, 3, 0)");
}

@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()
Expand Down

0 comments on commit 33f08e7

Please sign in to comment.