Add unit test to show how unique ID supplier can generate conflicting IDs
@@ -46,6 +46,29 @@ public final class UniqueIdSupplierTest {
assertThat(uniqueId2).contains(inputHashString + "$1");
}
+ @Test
+ public void testFilePathsHavingSameHashCode_generatesConflictingNames() {
+ // Strings "FB" and "Ea" generate the same hashcode, and consequently the same IDs.
+ CompilerInput input1 = new CompilerInput(SourceFile.fromCode("FB", "function foo() {}"));
+ CompilerInput input2 = new CompilerInput(SourceFile.fromCode("Ea", "function foo() {}"));
+
+ String uniqueId1 = uniqueIdSupplier.getUniqueId(input1);
+ String uniqueId2 = uniqueIdSupplier.getUniqueId(input2);
+ assertThat(uniqueId1).isNotEmpty();
+ assertThat(uniqueId2).isNotEmpty();
+ // TODO(b/184589799.): Fix this to generate unique IDs.
+ assertThat(uniqueId1).isEqualTo(uniqueId2);
+
+ int fileHashCode1 = input1.getSourceFile().getOriginalPath().hashCode();
+ int fileHashCode2 = input2.getSourceFile().getOriginalPath().hashCode();
+ String inputHashString1 = (fileHashCode1 < 0) ? ("m" + -fileHashCode1) : ("" + fileHashCode1);
+ String inputHashString2 = (fileHashCode2 < 0) ? ("m" + -fileHashCode2) : ("" + fileHashCode2);
+ // TODO(b/184589799): Fix this to generate unique IDs.
+ assertThat(inputHashString1).isEqualTo(inputHashString2);
+ assertThat(uniqueId1).contains(inputHashString1 + "$0");
+ assertThat(uniqueId2).contains(inputHashString2 + "$0");
+ }
+
@Test
public void testMultipleCompilerInputsGenerateUniqueIds() {
CompilerInput input1 = new CompilerInput(SourceFile.fromCode("tmp1", "function foo() {}"));
