aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
index 6471192af5..ad4519132c 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
@@ -62,6 +62,19 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
}
@Test
+ public void testToCollection() throws Exception {
+ eval("s = depset(['a', 'b'])");
+ assertThat(get("s").toCollection(String.class)).containsExactly("a", "b").inOrder();
+ assertThat(get("s").toCollection(Object.class)).containsExactly("a", "b").inOrder();
+ assertThat(get("s").toCollection()).containsExactly("a", "b").inOrder();
+ try {
+ get("s").toCollection(Integer.class);
+ Assert.fail("toCollection() with wrong type should have raised IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ @Test
public void testOrder() throws Exception {
eval("s = depset(['a', 'b'], order='postorder')");
assertThat(get("s").getSet(String.class).getOrder()).isEqualTo(Order.COMPILE_ORDER);
@@ -94,13 +107,9 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
@Test
public void testBadGenericType() throws Exception {
- new BothModesTest()
- .testIfExactError(
- "cannot add an item of type 'int' to a depset of 'string'",
- "depset(['a', 5])")
- .testIfExactError(
- "cannot add value of type 'string' to a depset",
- "depset() + 'a'");
+ new BothModesTest().testIfExactError(
+ "cannot add an item of type 'int' to a depset of 'string'",
+ "depset(['a', 5])");
}
@Test
@@ -130,7 +139,8 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
private void assertContainsInOrder(String statement, Object... expectedElements)
throws Exception {
- new BothModesTest().testCollection(statement, expectedElements);
+ assertThat(((SkylarkNestedSet) eval(statement)).toCollection())
+ .containsExactly(expectedElements);
}
@Test
@@ -158,12 +168,10 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
public void testUnionWithNonsequence() throws Exception {
new BothModesTest()
.testIfExactError(
- "method depset.union(new_elements: Iterable) is not applicable for arguments (int): "
- + "'new_elements' is 'int', but should be 'Iterable'",
+ "cannot union value of type 'int' to a depset",
"depset([]).union(5)")
.testIfExactError(
- "method depset.union(new_elements: Iterable) is not applicable for arguments (string): "
- + "'new_elements' is 'string', but should be 'Iterable'",
+ "cannot union value of type 'string' to a depset",
"depset(['a']).union('b')");
}