aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
diff options
context:
space:
mode:
authorGravatar vladmos <vladmos@google.com>2017-05-04 18:00:59 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-05-04 23:05:35 +0200
commit25da19da81e9eaf06632349ad41ef9910940e33f (patch)
treeb95a160f0145bd004e319f02d417a828481227ee /src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
parent444b86319a901603a1030c484dac9f87501bad9d (diff)
Implement a flag for extend-like behavior of the `+=` operator for lists
Usage: --incompatible_list_plus_equals=true (the default value is false). PiperOrigin-RevId: 155084916
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 848498b229..a71f656070 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -987,6 +987,73 @@ public class SkylarkEvaluationTest extends EvaluationTest {
}
@Test
+ public void testPlusEqualsOnListCopying() throws Exception {
+ new SkylarkTest("--incompatible_list_plus_equals=false")
+ .setUp(
+ "def func():",
+ " l1 = [1, 2]",
+ " l2 = l1",
+ " l2 += [3, 4]",
+ " return l1, l2",
+ "lists = str(func())")
+ .testLookup("lists", "([1, 2], [1, 2, 3, 4])");
+ }
+
+ @Test
+ public void testPlusEqualsOnListMutating() throws Exception {
+ new SkylarkTest("--incompatible_list_plus_equals=true")
+ .setUp(
+ "def func():",
+ " l1 = [1, 2]",
+ " l2 = l1",
+ " l2 += [3, 4]",
+ " return l1, l2",
+ "lists = str(func())")
+ .testLookup("lists", "([1, 2, 3, 4], [1, 2, 3, 4])");
+
+ // The same but with += after an IndexExpression
+ new SkylarkTest("--incompatible_list_plus_equals=true")
+ .setUp(
+ "def func():",
+ " l = [1, 2]",
+ " d = {0: l}",
+ " d[0] += [3, 4]",
+ " return l, d[0]",
+ "lists = str(func())")
+ .testLookup("lists", "([1, 2, 3, 4], [1, 2, 3, 4])");
+ }
+
+ @Test
+ public void testPlusEqualsOnTuple() throws Exception {
+ new SkylarkTest("--incompatible_list_plus_equals=false")
+ .setUp(
+ "def func():",
+ " t1 = (1, 2)",
+ " t2 = t1",
+ " t2 += (3, 4)",
+ " return t1, t2",
+ "tuples = func()")
+ .testLookup("tuples", SkylarkList.Tuple.of(
+ SkylarkList.Tuple.of(1, 2),
+ SkylarkList.Tuple.of(1, 2, 3, 4)
+ ));
+
+ // This behavior should remain the same regardless of the incompatible_list_plus_equals flag
+ new SkylarkTest("--incompatible_list_plus_equals=true")
+ .setUp(
+ "def func():",
+ " t1 = (1, 2)",
+ " t2 = t1",
+ " t2 += (3, 4)",
+ " return t1, t2",
+ "tuples = func()")
+ .testLookup("tuples", SkylarkList.Tuple.of(
+ SkylarkList.Tuple.of(1, 2),
+ SkylarkList.Tuple.of(1, 2, 3, 4)
+ ));
+ }
+
+ @Test
public void testPlusEqualsOnDict() throws Exception {
new SkylarkTest().setUp("def func():",
" d = {'a' : 1}",