[OpenLayers-Dev] Testing for equivalence in XML with xml_eq

Tim Schaub tschaub at openplans.org
Fri Feb 22 18:41:21 EST 2008


Tim Schaub wrote:
> Hey-
> 
> Erik Uzureau wrote:
>> Tim, this is a nice new addition to the testing suite. Great work!
>>
>> a) do you think you could put a copy of this email in a wiki
>> somewhere? It would probably be nice to be able to refer back to this
>> in the future
> 
> Sure.  Without a more appropriate place (but wiki's aren't really about 
> appropriate places are they?) to put it, I've added some stuff to the 
> WritingUnitTests page:
> 
> http://trac.openlayers.org/wiki/WritingUnitTests#ModificationstoTest.AnotherWay
> 
> If anybody else wants to document any other changes to testing stuff 
> [1], it could be tacked on there.
> 
>> b) have you contacted the Test.Anotherway people to see if they would
>> be interested in a patch?
>>
> 
> Well, let's see how it works for us before we go trying to sell it.
> 
> Tim
> 

[1] http://trac.openlayers.org/log/trunk/openlayers/tests/run-tests.html

>> Erik
>>
>> On 2/22/08, Tim Schaub wrote:
>>> Hey-
>>>
>>> So, I assume that the people for whom this is relevant already read
>>> commit messages, but I thought I'd document an addition to our testing
>>> framework here anyway.
>>>
>>> If you're writing tests for anything that does parsing of XML, I've
>>> added a method to Test.AnotherWay test objects that will be useful.  The
>>> new xml_eq method is similar to html_eq except it works for generic xml
>>> (and works in Safari and FF3 where html_eq fails).
>>>
>>> Use is pretty straightforward.  You can compare element nodes to element
>>> nodes, nodes to strings, or strings to strings.
>>>
>>> I added a single script to our run-tests.html page that extends
>>> Test.AnotherWay:
>>> http://trac.openlayers.org/browser/trunk/openlayers/tests/xml_eq.js
>>>
>>> Though I grimace when I see this much code in email, I'll paste a couple
>>> examples:
>>>
>>> // Pretend we're on a test page in a test function
>>> var format = new OpenLayers.Format.XML();
>>> var doc, got, exp;
>>>
>>> // Create a doc and check that root is equivalent to some string
>>> doc = format.read(
>>>     "<chicken>soup</chicken>"
>>> );
>>> got = doc.documentElement;
>>> exp = "<chicken>soup</chicken>";
>>> t.xml_eq(got, exp, "passes");
>>>
>>> // See what happens with bad expectations
>>> exp = "<chicken>fat</chicken>";
>>> t.xml_eq(got, exp, "fails");
>>> // Fails with the following message:
>>> // Bad child 0 for element chicken: Node value mismatch: got soup
>>> // but expected fat
>>>
>>> // Test xml with different namespace aliases
>>> got = "<foo:chicken xmlns:foo='namespace'>soup</foo:chicken>";
>>> exp = "<bar:chicken xmlns:bar='namespace'>soup</bar:chicken>";
>>> t.xml_eq(got, exp, "passes");
>>>
>>> // Assert that prefixes are equal
>>> t.xml_eq(got, exp, "fails", {prefix: true});
>>> // Fails with the following message:
>>> // Node name mismatch: got foo:chicken but expected bar:chicken
>>>
>>>
>>> Etc.
>>>
>>> Tim
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> Dev at openlayers.org
>>> http://openlayers.org/mailman/listinfo/dev
>>>
>>
>>
> 
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
> 
> !DSPAM:4033,47bf5cb176555219720167!
> 




More information about the Dev mailing list