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 EqualsEndPastEnd1() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p = ProjectPropertyInstance.Create("bbb", "value"); dictionary.Set(p); ProjectPropertyInstance value = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "abbbaaa", 1, 3); Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted" }
public void EqualsStartZero() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aab", "value1"); ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("aba", "value2"); dictionary.Set(p1); dictionary.Set(p2); ProjectPropertyInstance value = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "aabaa", 0, 2); Assert.True(Object.ReferenceEquals(p1, value)); // "Should have returned the 'aab' value" }
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(); } }