public void TestStringHashKey() { String_AST hello1 = new String_AST("Hello World"); String_AST hello2 = new String_AST("Hello World"); String_AST diff1 = new String_AST("My name is johnny"); String_AST diff2 = new String_AST("My name is johnny"); //Assert.Equals(hello1.HashKey(), hello2.HashKey());//this assertion works on structs fine //if (hello1.HashKey() != hello2.HashKey()) {//outof the box, comparison like this do not work for structs. if (!hello1.HashKey().Equals(hello2.HashKey())) { throw new AssertFailedException("strings with same content have different hash keys"); } //if (diff1.HashKey() != diff2.HashKey()) { if (!diff1.HashKey().Equals(diff2.HashKey())) { throw new AssertFailedException("strings with same content have different hash keys"); } //if (hello1.HashKey() == diff1.HashKey()) { if (hello1.HashKey().Equals(diff1.HashKey())) { throw new AssertFailedException("strings with different content have same hash keys"); } }
public void TestStringConcatenation() { string input = @"""Hello"" + "" World!"""; var evaluated = testEval(input); String_AST str = evaluated as String_AST; if (str is null) { Assert.Fail(string.Format("object is not String. got={0}", evaluated)); } if (str.Value != "Hello World!") { Assert.Fail(string.Format("String has wrong value. got={0}", str.Value)); } }
private void testStringObject(Object_AST resultObj, Object_AST expectedObj) { String_AST result = resultObj as String_AST; if (result is null) { throw new AssertFailedException(string.Format("resultObj is not String_AST. got={0}", resultObj)); } String_AST expected = expectedObj as String_AST; if (expected is null) { throw new AssertFailedException(string.Format("expectedObj is not String_AST. got={0}", expected)); } Assert.AreEqual(result.Value, expected.Value, string.Format("resultObj has wrong value. got={0}, want={1}", result.Value, expected.Value)); }