diff options
author | 2015-09-25 11:59:40 +0000 | |
---|---|---|
committer | 2015-09-25 14:41:38 +0000 | |
commit | 1c07e325fd073cb1d801098507e658f160750df3 (patch) | |
tree | 8032d21a4509dffc5486b3f482df2a3d223b1a2b /src/test/java/com/google/devtools/build | |
parent | 1249c9a9aec28d9964ac8d72f3685d24d02828dc (diff) |
Implemented copy constructor for Skylark dictionaries: new_dict = dict(old_dict)
--
MOS_MIGRATED_REVID=103932279
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java | 33 |
1 files changed, 23 insertions, 10 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 72fd205ecf..de926812a7 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 @@ -123,8 +123,8 @@ public class MethodLibraryTest extends EvaluationTestCase { + "but should be string", "'test'.startswith(1)") .testIfErrorContains( - "Method dict(args: Iterable, **kwargs) is not applicable for arguments " - + "(string, dict): 'args' is string, but should be Iterable", + "expected value of type 'list(object)' for parameter args in dict(), " + + "but got \"a\" (string)", "dict('a')"); } @@ -647,6 +647,20 @@ public class MethodLibraryTest extends EvaluationTestCase { } @Test + public void testDictionaryCopy() throws Exception { + new SkylarkTest() + .setUp("x = {1 : 2}", "y = dict(x)") + .testEval("x[1] == 2 and y[1] == 2", "True"); + } + + @Test + public void testDictionaryCopyKeyCollision() throws Exception { + new SkylarkTest() + .setUp("x = {'test' : 2}", "y = dict(x, test = 3)") + .testEval("y['test']", "3"); + } + + @Test public void testDictionaryWithMultipleKeys() throws Exception { new BothModesTest().testStatement("{0: 'a', 1: 'b', 0: 'c'}[0]", "c"); } @@ -741,19 +755,18 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testDictionaryCreationInvalidPositional() throws Exception { - String unexpectedString = - "expected value of type 'list(object)' for dict(args), but got \"a\" (string)"; - new BothModesTest() .testIfErrorContains( - "Method dict(args: Iterable, **kwargs) is not applicable for arguments " - + "(string, dict): 'args' is string, but should be Iterable", + "expected value of type 'list(object)' for parameter args in dict(), " + + "but got \"a\" (string)", "dict('a')") - .testIfErrorContains(unexpectedString, "dict(['a'])") - .testIfErrorContains(unexpectedString, "dict([('a')])") + .testIfErrorContains( + "Cannot convert dictionary update sequence element #0 to a sequence", "dict(['a'])") + .testIfErrorContains( + "Cannot convert dictionary update sequence element #0 to a sequence", "dict([('a')])") .testIfErrorContains("too many (3) positional arguments", "dict((3,4), (3,2), (1,2))") .testIfErrorContains( - "Tuple has length 3, but exactly two elements are required", + "Sequence #0 has length 3, but exactly two elements are required", "dict([('a', 'b', 'c')])"); } |