use of com.facebook.buck.rules.SourceRoot in project buck by facebook.
the class CountingRuleKeyHasherTest method testCounting.
@Test
public void testCounting() {
CountingRuleKeyHasher<HashCode> hasher = newCountHasher();
int count = 0;
assertEquals(count, hasher.getCount());
hasher.putKey("");
assertEquals(++count, hasher.getCount());
hasher.putKey("42").putKey("43").putKey("44");
assertEquals(count += 3, hasher.getCount());
hasher.putNull();
assertEquals(++count, hasher.getCount());
hasher.putBoolean(true);
assertEquals(++count, hasher.getCount());
hasher.putBoolean(false).putBoolean(true);
assertEquals(count += 2, hasher.getCount());
hasher.putNumber(0);
assertEquals(++count, hasher.getCount());
hasher.putNumber(42).putNumber(43);
assertEquals(count += 2, hasher.getCount());
hasher.putNumber((long) 0);
assertEquals(++count, hasher.getCount());
hasher.putNumber((long) 42).putNumber((long) 43);
assertEquals(count += 2, hasher.getCount());
hasher.putNumber((short) 0);
assertEquals(++count, hasher.getCount());
hasher.putNumber((short) 42).putNumber((short) 43);
assertEquals(count += 2, hasher.getCount());
hasher.putNumber((byte) 0);
assertEquals(++count, hasher.getCount());
hasher.putNumber((byte) 42).putNumber((byte) 43);
assertEquals(count += 2, hasher.getCount());
hasher.putNumber((float) 0);
assertEquals(++count, hasher.getCount());
hasher.putNumber((float) 42).putNumber((float) 43);
assertEquals(count += 2, hasher.getCount());
hasher.putNumber((double) 0);
assertEquals(++count, hasher.getCount());
hasher.putNumber((double) 42).putNumber((double) 43);
assertEquals(count += 2, hasher.getCount());
hasher.putString("");
assertEquals(++count, hasher.getCount());
hasher.putString("42").putString("43");
assertEquals(count += 2, hasher.getCount());
hasher.putBytes(new byte[0]);
assertEquals(++count, hasher.getCount());
hasher.putBytes(new byte[] { 42 });
assertEquals(++count, hasher.getCount());
hasher.putBytes(new byte[] { 42, 42 }).putBytes(new byte[] { 43 });
assertEquals(count += 2, hasher.getCount());
hasher.putPattern(Pattern.compile(""));
assertEquals(++count, hasher.getCount());
hasher.putPattern(Pattern.compile("42")).putPattern(Pattern.compile("43"));
assertEquals(count += 2, hasher.getCount());
hasher.putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"));
assertEquals(++count, hasher.getCount());
hasher.putSha1(Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd")).putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"));
assertEquals(count += 2, hasher.getCount());
hasher.putPath(Paths.get(""), HashCode.fromInt(0));
assertEquals(++count, hasher.getCount());
hasher.putPath(Paths.get(""), HashCode.fromInt(42));
assertEquals(++count, hasher.getCount());
hasher.putPath(Paths.get("42"), HashCode.fromInt(0));
assertEquals(++count, hasher.getCount());
hasher.putPath(Paths.get("42"), HashCode.fromInt(42));
assertEquals(++count, hasher.getCount());
hasher.putPath(Paths.get("42/42"), HashCode.fromInt(42)).putPath(Paths.get("43"), HashCode.fromInt(43));
assertEquals(count += 2, hasher.getCount());
hasher.putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(0));
assertEquals(++count, hasher.getCount());
hasher.putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(42));
assertEquals(++count, hasher.getCount());
hasher.putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(0));
assertEquals(++count, hasher.getCount());
hasher.putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(42));
assertEquals(++count, hasher.getCount());
hasher.putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).putArchiveMemberPath(newArchiveMember("43/43", "43/43"), HashCode.fromInt(43));
assertEquals(count += 2, hasher.getCount());
hasher.putNonHashingPath("");
assertEquals(++count, hasher.getCount());
hasher.putNonHashingPath("42").putNonHashingPath("43");
assertEquals(count += 2, hasher.getCount());
hasher.putSourceRoot(new SourceRoot(""));
assertEquals(++count, hasher.getCount());
hasher.putSourceRoot(new SourceRoot("42")).putSourceRoot(new SourceRoot("43"));
assertEquals(count += 2, hasher.getCount());
hasher.putRuleKey(RULE_KEY_1);
assertEquals(++count, hasher.getCount());
hasher.putRuleKey(RULE_KEY_2).putRuleKey(RULE_KEY_1);
assertEquals(count += 2, hasher.getCount());
hasher.putBuildRuleType(BuildRuleType.of(""));
assertEquals(++count, hasher.getCount());
hasher.putBuildRuleType(BuildRuleType.of("42")).putBuildRuleType(BuildRuleType.of("43"));
assertEquals(count += 2, hasher.getCount());
hasher.putBuildTarget(TARGET_1);
assertEquals(++count, hasher.getCount());
hasher.putBuildTarget(TARGET_2).putBuildTarget(TARGET_1);
assertEquals(count += 2, hasher.getCount());
hasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1));
assertEquals(++count, hasher.getCount());
hasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_2)).putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1));
assertEquals(count += 2, hasher.getCount());
hasher.putContainer(RuleKeyHasher.Container.LIST, 0);
assertEquals(++count, hasher.getCount());
hasher.putContainer(RuleKeyHasher.Container.LIST, 42).putContainer(RuleKeyHasher.Container.LIST, 43);
assertEquals(count += 2, hasher.getCount());
hasher.putContainer(RuleKeyHasher.Container.MAP, 0);
assertEquals(++count, hasher.getCount());
hasher.putContainer(RuleKeyHasher.Container.MAP, 42).putContainer(RuleKeyHasher.Container.MAP, 43);
assertEquals(count += 2, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.SUPPLIER);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.OPTIONAL);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.APPENDABLE);
assertEquals(++count, hasher.getCount());
hasher.putWrapper(RuleKeyHasher.Wrapper.SUPPLIER).putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT).putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT).putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE).putWrapper(RuleKeyHasher.Wrapper.APPENDABLE).putWrapper(RuleKeyHasher.Wrapper.OPTIONAL);
assertEquals(count += 7, hasher.getCount());
hasher.putKey("key").putContainer(RuleKeyHasher.Container.LIST, 3).putString("a").putNumber(1).putNull();
assertEquals(count += 5, hasher.getCount());
}
Aggregations