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.java33
1 files changed, 31 insertions, 2 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 3f06c5495a..fc5b685cb2 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
@@ -16,14 +16,15 @@ package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.collect.nestedset.Order;
+import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -39,7 +40,7 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
eval("ds = set([1, 2, 3], order='compile')");
SkylarkNestedSet ds = get("ds");
assertThat(ds.getOrder().getName()).isEqualTo("compile");
- assertThat(ds.expandedSet()).isEqualTo(ImmutableSet.of(1, 2, 3));
+ assertThat(ds.getSet(Object.class)).containsExactly(1, 2, 3);
}
@Test
@@ -49,6 +50,18 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
}
@Test
+ public void testGetSet() throws Exception {
+ eval("s = depset(['a', 'b'])");
+ assertThat(get("s").getSet(String.class)).containsExactly("a", "b").inOrder();
+ assertThat(get("s").getSet(Object.class)).containsExactly("a", "b").inOrder();
+ try {
+ get("s").getSet(Integer.class);
+ Assert.fail("getSet() with wrong type should have raised IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ @Test
public void testNsetOrder() throws Exception {
eval("n = depset(['a', 'b'], order='compile')");
assertThat(get("n").getSet(String.class).getOrder()).isEqualTo(Order.COMPILE_ORDER);
@@ -61,6 +74,12 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
}
@Test
+ public void testNsetHomogeneousGenericType() throws Exception {
+ eval("n = depset(['a', 'b', 'c'])");
+ assertThat(get("n").getContentType()).isEqualTo(SkylarkType.of(String.class));
+ }
+
+ @Test
public void testDepsetBadOrder() throws Exception {
new BothModesTest().testIfExactError("Invalid order: bad", "depset(['a'], order='bad')");
}
@@ -252,6 +271,16 @@ public class SkylarkNestedSetTest extends EvaluationTestCase {
}
@Test
+ public void testToList() throws Exception {
+ eval(
+ "s = depset() + [2, 4, 6] + [3, 4, 5]",
+ "x = s.to_list()");
+ Object value = lookup("x");
+ assertThat(value).isInstanceOf(MutableList.class);
+ assertThat((Iterable<?>) value).containsExactly(2, 4, 6, 3, 5).inOrder();
+ }
+
+ @Test
public void testSetOrderCompatibility() throws Exception {
// Two sets are compatible if
// (a) both have the same order or