aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2016-01-07 13:58:43 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-07 20:19:50 +0000
commitd640bd3cecaa9ff8a1a3df4a339eebc9b786af3d (patch)
treeac90f0f3d13ccc476781554509acae16a6cc57a7 /src/test/java/com/google/devtools
parent763f1397155fc7c12e1f1071a1bc942f91b867c4 (diff)
Remove syntactic sugar when assigning to a dict item.
e.g. a['key'] = value is handled through a proper lvalue, instead of using syntactic sugar. Benefits include: - better error messages (reference to the '+' operator was cryptic) - more robust, e.g. it is compatible with the += operator - can be used in a tuple, e.g. a[1], a[2] = 3, 4 - it is a step towards mutable dict -- MOS_MIGRATED_REVID=111597545
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java20
1 files changed, 19 insertions, 1 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 752a0517b0..e2f4ca7976 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
@@ -816,6 +816,24 @@ public class SkylarkEvaluationTest extends EvaluationTest {
}
@Test
+ public void testDictTupleAssignmentAsLValue() throws Exception {
+ new SkylarkTest().setUp("def func():",
+ " d = {'a' : 1}",
+ " d['b'], d['c'] = 2, 3",
+ " return d",
+ "d = func()").testLookup("d", ImmutableMap.of("a", 1, "b", 2, "c", 3));
+ }
+
+ @Test
+ public void testDictItemPlusEqual() throws Exception {
+ new SkylarkTest().setUp("def func():",
+ " d = {'a' : 2}",
+ " d['a'] += 3",
+ " return d",
+ "d = func()").testLookup("d", ImmutableMap.of("a", 5));
+ }
+
+ @Test
public void testDictAssignmentAsLValueNoSideEffects() throws Exception {
new SkylarkTest().setUp("def func(d):",
" d['b'] = 2",
@@ -827,7 +845,7 @@ public class SkylarkEvaluationTest extends EvaluationTest {
public void testListIndexAsLValueAsLValue() throws Exception {
new SkylarkTest()
.testIfErrorContains(
- "unsupported operand type(s) for +: 'list' and 'dict'",
+ "can only assign an element in a dictionary, not in a 'list'",
"def id(l):",
" return l",
"def func():",