/** * Tests that {@link Type#selectableConvert} returns either the native type or a selector on that * type, in accordance with the provided input. */ @SuppressWarnings("unchecked") @Test public void testSelectableConvert() throws Exception { Object nativeInput = Arrays.asList("//a:a1", "//a:a2"); Object selectableInput = SelectorList.of( new SelectorValue( ImmutableMap.of( "//conditions:a", nativeInput, Type.Selector.DEFAULT_CONDITION_KEY, nativeInput))); List<Label> expectedLabels = ImmutableList.of(Label.create("a", "a1"), Label.create("a", "a2")); // Conversion to direct type: Object converted = Type.LABEL_LIST.selectableConvert(nativeInput, null, currentRule); assertTrue(converted instanceof List<?>); assertSameContents(expectedLabels, (List<Label>) converted); // Conversion to selectable type: converted = Type.LABEL_LIST.selectableConvert(selectableInput, null, currentRule); Type.SelectorList<?> selectorList = (Type.SelectorList<?>) converted; assertSameContents( ImmutableMap.of( Label.parseAbsolute("//conditions:a"), expectedLabels, Label.parseAbsolute(Type.Selector.DEFAULT_CONDITION_KEY), expectedLabels) .entrySet(), ((Type.Selector<Label>) selectorList.getSelectors().get(0)).getEntries().entrySet()); }
@Test public void testFilesetEntry() throws Exception { Label srcDir = Label.create("foo", "src"); Label entryLabel = Label.create("foo", "entry"); FilesetEntry input = new FilesetEntry(srcDir, ImmutableList.of(entryLabel), null, null, null, null); assertEquals(input, Type.FILESET_ENTRY.convert(input, null, currentRule)); assertThat(Type.FILESET_ENTRY.flatten(input)).containsExactly(entryLabel); }
/** Tests basic {@link Type.Selector} functionality. */ @Test public void testSelector() throws Exception { Object input = ImmutableMap.of( "//conditions:a", "//a:a", "//conditions:b", "//b:b", Type.Selector.DEFAULT_CONDITION_KEY, "//d:d"); Type.Selector<Label> selector = new Type.Selector<>(input, null, currentRule, Type.LABEL); assertEquals(Type.LABEL, selector.getOriginalType()); Map<Label, Label> expectedMap = ImmutableMap.of( Label.parseAbsolute("//conditions:a"), Label.create("a", "a"), Label.parseAbsolute("//conditions:b"), Label.create("b", "b"), Label.parseAbsolute(Type.Selector.DEFAULT_CONDITION_KEY), Label.create("d", "d")); assertSameContents(expectedMap.entrySet(), selector.getEntries().entrySet()); }
@Test public void testSelectorList() throws Exception { Object selector1 = new SelectorValue( ImmutableMap.of( "//conditions:a", ImmutableList.of("//a:a"), "//conditions:b", ImmutableList.of("//b:b"))); Object selector2 = new SelectorValue( ImmutableMap.of( "//conditions:c", ImmutableList.of("//c:c"), "//conditions:d", ImmutableList.of("//d:d"))); Type.SelectorList<List<Label>> selectorList = new Type.SelectorList<>( ImmutableList.of(selector1, selector2), null, currentRule, Type.LABEL_LIST); assertEquals(Type.LABEL_LIST, selectorList.getOriginalType()); assertSameContents( ImmutableSet.of( Label.parseAbsolute("//conditions:a"), Label.parseAbsolute("//conditions:b"), Label.parseAbsolute("//conditions:c"), Label.parseAbsolute("//conditions:d")), selectorList.getKeyLabels()); List<Type.Selector<List<Label>>> selectors = selectorList.getSelectors(); assertSameContents( ImmutableMap.of( Label.parseAbsolute("//conditions:a"), ImmutableList.of(Label.create("a", "a")), Label.parseAbsolute("//conditions:b"), ImmutableList.of(Label.create("b", "b"))) .entrySet(), selectors.get(0).getEntries().entrySet()); assertSameContents( ImmutableMap.of( Label.parseAbsolute("//conditions:c"), ImmutableList.of(Label.create("c", "c")), Label.parseAbsolute("//conditions:d"), ImmutableList.of(Label.create("d", "d"))) .entrySet(), selectors.get(1).getEntries().entrySet()); }
/** Tests that {@link Type.Selector} correctly references its default value. */ @Test public void testSelectorDefault() throws Exception { Object input = ImmutableMap.of( "//conditions:a", "//a:a", "//conditions:b", "//b:b", Type.Selector.DEFAULT_CONDITION_KEY, "//d:d"); assertEquals( Label.create("d", "d"), new Type.Selector<Label>(input, null, currentRule, Type.LABEL).getDefault()); }