// Copyright 2015 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.docgen; import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableMap; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Unit tests for {@link RuleLinkExpander}. */ @RunWith(JUnit4.class) public class RuleLinkExpanderTest { private RuleLinkExpander expander; @Before public void setUp() { expander = new RuleLinkExpander(ImmutableMap.builder() .put("cc_library", "c-cpp") .put("cc_binary", "c-cpp") .put("java_binary", "java") .put("proto_library", "protocol-buffer") .build()); } @Test public void testRule() { String docs = "java_binary rule"; String expected = "java_binary rule"; assertEquals(expected, expander.expand(docs)); } @Test public void testRuleAndAttribute() { String docs = "runtime_deps attribute"; String expected = "runtime_deps attribute"; assertEquals(expected, expander.expand(docs)); } @Test public void testRuleExamples() { String docs = "examples"; String expected = "examples"; assertEquals(expected, expander.expand(docs)); } @Test public void testRuleArgs() { String docs = "args"; String expected = "args"; assertEquals(expected, expander.expand(docs)); } @Test public void testStaticPageRef() { String docs = "Common Definitions"; String expected = "Common Definitions"; assertEquals(expected, expander.expand(docs)); } @Test public void testStaticPageWithHeadingRef() { String docs = "Label Expansion"; String expected = "Label Expansion"; assertEquals(expected, expander.expand(docs)); } @Test(expected = IllegalArgumentException.class) public void testRefNotFound() { String docs = "bar"; expander.expand(docs); } }