public void IndexedGetHashcode3() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; string s = "abcd"; try { comparer.SetConstraintsForUnitTestingOnly(s, 0, 2); Assert.Equal(comparer.GetHashCode(s), comparer.GetHashCode("abc")); } finally { comparer.RemoveConstraintsForUnitTestingOnly(); } }
public void EqualsEndEnd() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aabaaaa", "value1"); ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("baaaa", "value2"); dictionary.Set(p1); dictionary.Set(p2); string constraint = "aabaaa"; ProjectPropertyInstance p3 = ProjectPropertyInstance.Create("abaaa", "value3"); dictionary.Set(p3); // Should match o3 ProjectPropertyInstance value1 = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, constraint, 1, 5); Assert.True(Object.ReferenceEquals(p3, value1)); // "Should have returned the 'abaaa' value" dictionary.Remove("abaaa"); // get rid of o3 ProjectPropertyInstance value2 = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, constraint, 1, 5); Assert.Null(value2); // "Should not have been a match in the dictionary" // Even if the string is exactly the same, if only a substring is being compared, then although it // will be judged equal, the hash codes will NOT be the same, and for that reason, a lookup in the // dictionary will fail. int originalHashCode = comparer.GetHashCode("aabaaa"); try { comparer.SetConstraintsForUnitTestingOnly(constraint, 1, 5); Assert.True(comparer.Equals("aabaaa", constraint)); // same on both sides Assert.NotEqual(originalHashCode, comparer.GetHashCode(constraint)); } finally { comparer.RemoveConstraintsForUnitTestingOnly(); } }
public void IndexedGetHashcode1() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Default; comparer.GetHashCode(""); // does not crash Assert.True(0 == comparer.GetHashCode((string)null)); Assert.Equal(comparer.GetHashCode("aBc"), comparer.GetHashCode("AbC")); Assert.Equal(comparer.GetHashCode("xyz", 0, 1), comparer.GetHashCode("x")); }
public void MatchProperty() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Default; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p = ProjectPropertyInstance.Create("foo", "bar"); dictionary.Set(p); string s = "$(foo)"; ProjectPropertyInstance value = dictionary.GetProperty(s, 2, 4); Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted" Assert.Equal(MSBuildNameIgnoreCaseComparer.Default.GetHashCode("foo"), comparer.GetHashCode(s, 2, 3)); }
public void IndexedGetHashcode1() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; string s = "xyz"; try { comparer.SetConstraintsForUnitTestingOnly(s, 0, 0); comparer.GetHashCode(""); // does not crash Assert.Equal(true, 0 == comparer.GetHashCode(null)); Assert.Equal(comparer.GetHashCode("aBc"), comparer.GetHashCode("AbC")); Assert.Equal(comparer.GetHashCode(s), comparer.GetHashCode("x")); } finally { comparer.RemoveConstraintsForUnitTestingOnly(); } }
public void IndexedGetHashcode3() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Default; Assert.Equal(comparer.GetHashCode("abcd", 0, 3), comparer.GetHashCode("abc")); }
public void IndexedGetHashcode2() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Default; Assert.Equal(comparer.GetHashCode("xyz", 1, 2), comparer.GetHashCode("YZ")); }
public void MatchProperty() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p = ProjectPropertyInstance.Create("foo", "bar"); dictionary.Set(p); string s = "$(foo)"; ProjectPropertyInstance value = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, s, 2, 4); Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted" try { comparer.SetConstraintsForUnitTestingOnly(s, 2, 4); Assert.Equal(MSBuildNameIgnoreCaseComparer.Default.GetHashCode("foo"), comparer.GetHashCode(s)); } finally { comparer.RemoveConstraintsForUnitTestingOnly(); } }