2929import org .junit .runner .RunWith ;
3030import org .junit .runners .JUnit4 ;
3131
32- /**
33- * Tests for {@link Label}.
34- */
32+ /** Tests for {@link Label}. */
3533@ RunWith (JUnit4 .class )
3634public class LabelTest {
3735
@@ -175,10 +173,7 @@ public void testIdentities() throws Exception {
175173 Label l2 = Label .parseCanonical ("//foo/bar:baz" );
176174 Label l3 = Label .parseCanonical ("//foo/bar:quux" );
177175
178- new EqualsTester ()
179- .addEqualityGroup (l1 , l2 )
180- .addEqualityGroup (l3 )
181- .testEquals ();
176+ new EqualsTester ().addEqualityGroup (l1 , l2 ).addEqualityGroup (l3 ).testEquals ();
182177 }
183178
184179 @ Test
@@ -225,6 +220,7 @@ public void testDotDot() throws Exception {
225220
226221 /**
227222 * Asserts that creating a label throws a SyntaxException.
223+ *
228224 * @param label the label to create.
229225 */
230226 private static void assertSyntaxError (String expectedError , String label ) {
@@ -238,12 +234,9 @@ private static void assertSyntaxError(String expectedError, String label) {
238234
239235 @ Test
240236 public void testBadCharacters () throws Exception {
241- assertSyntaxError ("target names may not contain ':'" ,
242- "//foo:bar:baz" );
243- assertSyntaxError ("target names may not contain ':'" ,
244- "//foo:bar:" );
245- assertSyntaxError ("target names may not contain ':'" ,
246- "//foo/bar::" );
237+ assertSyntaxError ("target names may not contain ':'" , "//foo:bar:baz" );
238+ assertSyntaxError ("target names may not contain ':'" , "//foo:bar:" );
239+ assertSyntaxError ("target names may not contain ':'" , "//foo/bar::" );
247240 }
248241
249242 @ Test
@@ -267,9 +260,9 @@ public void testDotAsAPathSegment() throws Exception {
267260 assertSyntaxError (INVALID_TARGET_NAME , "//foo:./bar/baz" );
268261 // TODO(bazel-team): enable when we have removed the "Workaround" in Label
269262 // that rewrites broken Labels by removing the trailing '.'
270- //assertSyntaxError(INVALID_PACKAGE_NAME,
263+ // assertSyntaxError(INVALID_PACKAGE_NAME,
271264 // "//foo:bar/baz/.");
272- //assertSyntaxError(INVALID_PACKAGE_NAME,
265+ // assertSyntaxError(INVALID_PACKAGE_NAME,
273266 // "//foo:.");
274267 }
275268
@@ -280,11 +273,9 @@ public void testTrailingDotSegment() throws Exception {
280273
281274 @ Test
282275 public void testSomeOtherBadLabels () throws Exception {
283- assertSyntaxError ("package names may not end with '/'" ,
284- "//foo/:bar" );
276+ assertSyntaxError ("package names may not end with '/'" , "//foo/:bar" );
285277 assertSyntaxError ("package names may not start with '/'" , "///p:foo" );
286- assertSyntaxError ("package names may not contain '//' path separators" ,
287- "//a//b:foo" );
278+ assertSyntaxError ("package names may not contain '//' path separators" , "//a//b:foo" );
288279 }
289280
290281 @ Test
@@ -305,24 +296,22 @@ public void testSomeGoodLabels() throws Exception {
305296
306297 @ Test
307298 public void testDoubleSlashPathSeparator () throws Exception {
308- assertSyntaxError ("package names may not contain '//' path separators" ,
309- "//foo//bar:baz" );
310- assertSyntaxError ("target names may not contain '//' path separator" ,
311- "//foo:bar//baz" );
299+ assertSyntaxError ("package names may not contain '//' path separators" , "//foo//bar:baz" );
300+ assertSyntaxError ("target names may not contain '//' path separator" , "//foo:bar//baz" );
312301 }
313302
314303 @ Test
315304 public void testNonPrintableCharacters () throws Exception {
316305 assertSyntaxError (
317- "target names may not contain non-printable characters: '\\ x02'" ,
318- "//foo:..\002 bar" );
306+ "target names may not contain non-printable characters: '\\ x02'" , "//foo:..\002 bar" );
319307 }
320308
321309 /** Make sure that control characters - such as CR - are escaped on output. */
322310 @ Test
323311 public void testInvalidLineEndings () throws Exception {
324- assertSyntaxError ("invalid target name '..bar\\ r': "
325- + "target names may not end with carriage returns" , "//foo:..bar\r " );
312+ assertSyntaxError (
313+ "invalid target name '..bar\\ r': " + "target names may not end with carriage returns" ,
314+ "//foo:..bar\r " );
326315 }
327316
328317 @ Test
@@ -391,6 +380,22 @@ public void testWorkspaceName() throws Exception {
391380 assertThat (Label .parseCanonical ("@//bar:baz" ).getWorkspaceName ()).isEmpty ();
392381 }
393382
383+ @ Test
384+ public void testUnambiguousCanonicalForm () throws Exception {
385+ assertThat (Label .parseCanonical ("//foo/bar:baz" ).getUnambiguousCanonicalForm ())
386+ .isEqualTo ("@@//foo/bar:baz" );
387+ assertThat (Label .parseCanonical ("@foo//bar:baz" ).getUnambiguousCanonicalForm ())
388+ .isEqualTo ("@@foo//bar:baz" );
389+ assertThat (
390+ Label .create (
391+ PackageIdentifier .create (
392+ RepositoryName .create ("foo" ).toNonVisible (RepositoryName .create ("bar" )),
393+ PathFragment .create ("baz" )),
394+ "quux" )
395+ .getUnambiguousCanonicalForm ())
396+ .isEqualTo ("@@[unknown repo 'foo' requested from @bar]//baz:quux" );
397+ }
398+
394399 @ Test
395400 public void starlarkStrAndRepr () throws Exception {
396401 Label label = Label .parseCanonical ("//x" );
0 commit comments