29
29
import org .junit .runner .RunWith ;
30
30
import org .junit .runners .JUnit4 ;
31
31
32
- /**
33
- * Tests for {@link Label}.
34
- */
32
+ /** Tests for {@link Label}. */
35
33
@ RunWith (JUnit4 .class )
36
34
public class LabelTest {
37
35
@@ -175,10 +173,7 @@ public void testIdentities() throws Exception {
175
173
Label l2 = Label .parseCanonical ("//foo/bar:baz" );
176
174
Label l3 = Label .parseCanonical ("//foo/bar:quux" );
177
175
178
- new EqualsTester ()
179
- .addEqualityGroup (l1 , l2 )
180
- .addEqualityGroup (l3 )
181
- .testEquals ();
176
+ new EqualsTester ().addEqualityGroup (l1 , l2 ).addEqualityGroup (l3 ).testEquals ();
182
177
}
183
178
184
179
@ Test
@@ -225,6 +220,7 @@ public void testDotDot() throws Exception {
225
220
226
221
/**
227
222
* Asserts that creating a label throws a SyntaxException.
223
+ *
228
224
* @param label the label to create.
229
225
*/
230
226
private static void assertSyntaxError (String expectedError , String label ) {
@@ -238,12 +234,9 @@ private static void assertSyntaxError(String expectedError, String label) {
238
234
239
235
@ Test
240
236
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::" );
247
240
}
248
241
249
242
@ Test
@@ -267,9 +260,9 @@ public void testDotAsAPathSegment() throws Exception {
267
260
assertSyntaxError (INVALID_TARGET_NAME , "//foo:./bar/baz" );
268
261
// TODO(bazel-team): enable when we have removed the "Workaround" in Label
269
262
// that rewrites broken Labels by removing the trailing '.'
270
- //assertSyntaxError(INVALID_PACKAGE_NAME,
263
+ // assertSyntaxError(INVALID_PACKAGE_NAME,
271
264
// "//foo:bar/baz/.");
272
- //assertSyntaxError(INVALID_PACKAGE_NAME,
265
+ // assertSyntaxError(INVALID_PACKAGE_NAME,
273
266
// "//foo:.");
274
267
}
275
268
@@ -280,11 +273,9 @@ public void testTrailingDotSegment() throws Exception {
280
273
281
274
@ Test
282
275
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" );
285
277
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" );
288
279
}
289
280
290
281
@ Test
@@ -305,24 +296,22 @@ public void testSomeGoodLabels() throws Exception {
305
296
306
297
@ Test
307
298
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" );
312
301
}
313
302
314
303
@ Test
315
304
public void testNonPrintableCharacters () throws Exception {
316
305
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" );
319
307
}
320
308
321
309
/** Make sure that control characters - such as CR - are escaped on output. */
322
310
@ Test
323
311
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 " );
326
315
}
327
316
328
317
@ Test
@@ -391,6 +380,22 @@ public void testWorkspaceName() throws Exception {
391
380
assertThat (Label .parseCanonical ("@//bar:baz" ).getWorkspaceName ()).isEmpty ();
392
381
}
393
382
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
+
394
399
@ Test
395
400
public void starlarkStrAndRepr () throws Exception {
396
401
Label label = Label .parseCanonical ("//x" );
0 commit comments