From: <bo...@us...> - 2008-12-15 14:13:03
|
Revision: 286 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=286&view=rev Author: bodewig Date: 2008-12-15 14:12:57 +0000 (Mon, 15 Dec 2008) Log Message: ----------- make empty element comparisons work for elements with attributes Modified Paths: -------------- trunk/xmlunit/NUnit.ReadMe trunk/xmlunit/src/csharp/XmlDiff.cs trunk/xmlunit/tests/csharp/XmlDiffTests.cs Modified: trunk/xmlunit/NUnit.ReadMe =================================================================== --- trunk/xmlunit/NUnit.ReadMe 2008-12-15 13:51:51 UTC (rev 285) +++ trunk/xmlunit/NUnit.ReadMe 2008-12-15 14:12:57 UTC (rev 286) @@ -24,6 +24,10 @@ - xmlns attributes are now no longer treated as normal attributes and the namespace of attributes is now sigificant +- comparisions of empty elements with attributes failed. + I.e. <foo><bar x="1"/></foo> was considered different from + <foo><bar x="1"></bar></foo> + Changes in version 0.3.1: - made it compile and all tests pass on .NET 1.1 as well as 2.0 and NUnit 2.4 Modified: trunk/xmlunit/src/csharp/XmlDiff.cs =================================================================== --- trunk/xmlunit/src/csharp/XmlDiff.cs 2008-12-15 13:51:51 UTC (rev 285) +++ trunk/xmlunit/src/csharp/XmlDiff.cs 2008-12-15 14:12:57 UTC (rev 286) @@ -171,9 +171,6 @@ } if (controlAttributes[i].Value != testAttr.Value) { - Console.Error.WriteLine("control: {0}, expected {1}, was {2}", - controlAttrName, - controlAttributes[i].Value, testAttr.Value); DifferenceFound(DifferenceType.ATTR_VALUE_ID, result); } @@ -222,12 +219,12 @@ private void CheckEmptyOrAtEndElement(DiffResult result, ReaderWithState control, ReaderWithState test) { - if (control.Reader.IsEmptyElement) { - if (!test.Reader.IsEmptyElement) { + if (control.LastElementWasEmpty) { + if (!test.LastElementWasEmpty) { CheckEndElement(test, result); } } else { - if (test.Reader.IsEmptyElement) { + if (test.LastElementWasEmpty) { CheckEndElement(control, result); } } @@ -319,12 +316,41 @@ internal ReaderWithState(XmlReader reader) { Reader = reader; HasRead = false; + LastElementWasEmpty = false; } + internal readonly XmlReader Reader; internal bool HasRead; + internal bool LastElementWasEmpty; + internal bool Read() { - return HasRead = Reader.Read(); + HasRead = Reader.Read(); + if (HasRead) { + switch (Reader.NodeType) { + case XmlNodeType.Element: + LastElementWasEmpty = Reader.IsEmptyElement; + break; + case XmlNodeType.EndElement: + LastElementWasEmpty = false; + break; + default: + // don't care + break; + } + } + return HasRead; } + + internal string State { + get { + return string.Format("Name {0}, NodeType {1}, IsEmpty {2}," + + " HasRead {3}, LastWasEmpty {4}", + Reader.Name, + Reader.NodeType, + Reader.IsEmptyElement, + HasRead, LastElementWasEmpty); + } + } } } } Modified: trunk/xmlunit/tests/csharp/XmlDiffTests.cs =================================================================== --- trunk/xmlunit/tests/csharp/XmlDiffTests.cs 2008-12-15 13:51:51 UTC (rev 285) +++ trunk/xmlunit/tests/csharp/XmlDiffTests.cs 2008-12-15 14:12:57 UTC (rev 286) @@ -24,8 +24,6 @@ private void AssertExpectedResult(string input1, string input2, bool expected) { TextReader reader1 = new StringReader(input1); TextReader reader2 = new StringReader(input2); - System.Console.Error.WriteLine("comparing {0} to {1}", input1, - input2); DiffResult result = PerformDiff(reader1, reader2); string msg = string.Format("comparing {0} to {1}: {2}", input1, input2, result.Difference); @@ -51,23 +49,13 @@ [Test] public void EqualResultForSameEmptyElements() { string[] input1 = {"<empty/>", "<elem><empty/></elem>"}; string[] input2 = {"<empty></empty>", "<elem><empty></empty></elem>"}; - System.Console.Error.WriteLine("ooooooooooooooooooooooooooooooooooooooooo"); - try { AssertExpectedResult(input1, input2, true); - } finally { - System.Console.Error.WriteLine("ooooooooooooooooooooooooooooooooooooooooo"); - } } [Test] public void EqualResultForEmptyElementsWithAttributes() { string[] input1 = {"<empty x='1'/>", "<elem><empty x='1'/></elem>"}; string[] input2 = {"<empty x='1'></empty>", "<elem><empty x='1'></empty></elem>"}; - System.Console.Error.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - try { AssertExpectedResult(input1, input2, true); - } finally { - System.Console.Error.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - } } [Test] public void NotEqualResultForEmptyVsNotEmptyElements() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |