예제 #1
0
  /**
   * 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());
  }
예제 #2
0
  @Test
  public void testTagConversion() throws Exception {
    assertSameContents(Sets.newHashSet("attribute"), Type.BOOLEAN.toTagSet(true, "attribute"));
    assertSameContents(Sets.newHashSet("noattribute"), Type.BOOLEAN.toTagSet(false, "attribute"));

    assertSameContents(
        Sets.newHashSet("whiskey"), Type.STRING.toTagSet("whiskey", "preferred_cocktail"));

    assertSameContents(
        Sets.newHashSet("cheddar", "ementaler", "gruyere"),
        Type.STRING_LIST.toTagSet(
            Lists.newArrayList("cheddar", "ementaler", "gruyere"), "cheeses"));
  }
예제 #3
0
 public void testGetConfigurabilityKeys() throws Exception {
   RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
   assertSameContents(
       ImmutableSet.of(
           Label.parseAbsolute("//conditions:a"),
           Label.parseAbsolute("//conditions:b"),
           Label.parseAbsolute("//conditions:default")),
       rawMapper.getConfigurabilityKeys("srcs", BuildType.LABEL_LIST));
   assertThat(rawMapper.getConfigurabilityKeys("data", BuildType.LABEL_LIST)).isEmpty();
 }
예제 #4
0
  @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());
  }
예제 #5
0
  /** 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());
  }
 public void testVisitation() throws Exception {
   VisitationRecorder recorder = new VisitationRecorder();
   mapper.visitLabels(recorder);
   MoreAsserts.assertSameContents(
       ImmutableList.of("//x:a", "//x:b", "//x:c"), recorder.labelsVisited);
 }