Making the xml_eq test method ignore whitespace only nodes by default. This can be configured by setting the ignoreWhiteSpace option. (see #1639)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7987 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+64
-11
@@ -97,10 +97,13 @@
|
|||||||
* Parameters:
|
* Parameters:
|
||||||
* got - {DOMElement}
|
* got - {DOMElement}
|
||||||
* expected - {DOMElement}
|
* expected - {DOMElement}
|
||||||
* options - {Object} Optional object for configuring test options. Set
|
* options - {Object} Optional object for configuring test options.
|
||||||
* 'prefix' property to true in order to compare element and attribute
|
*
|
||||||
* prefixes (namespace uri always tested). By default, prefixes
|
* Valid options:
|
||||||
* are not tested.
|
* prefix - {Boolean} Compare element and attribute
|
||||||
|
* prefixes (namespace uri always tested). Default is false.
|
||||||
|
* includeWhiteSpace - {Boolean} Include whitespace only nodes when
|
||||||
|
* comparing child nodes. Default is false.
|
||||||
*/
|
*/
|
||||||
function assertElementNodesEqual(got, expected, options) {
|
function assertElementNodesEqual(got, expected, options) {
|
||||||
var testPrefix = (options && options.prefix === true);
|
var testPrefix = (options && options.prefix === true);
|
||||||
@@ -190,14 +193,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compare children
|
// compare children
|
||||||
|
var gotChildNodes = getChildNodes(got, options);
|
||||||
|
var expChildNodes = getChildNodes(expected, options);
|
||||||
|
|
||||||
assertEqual(
|
assertEqual(
|
||||||
got.childNodes.length, expected.childNodes.length,
|
gotChildNodes.length, expChildNodes.length,
|
||||||
"Children length mismatch for " + got.nodeName
|
"Children length mismatch for " + got.nodeName
|
||||||
);
|
);
|
||||||
for(var j=0; j<got.childNodes.length; ++j) {
|
for(var j=0; j<gotChildNodes.length; ++j) {
|
||||||
try {
|
try {
|
||||||
assertElementNodesEqual(
|
assertElementNodesEqual(
|
||||||
got.childNodes[j], expected.childNodes[j]
|
gotChildNodes[j], expChildNodes[j], options
|
||||||
);
|
);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw "Bad child " + j + " for element " + got.nodeName + ": " + err;
|
throw "Bad child " + j + " for element " + got.nodeName + ": " + err;
|
||||||
@@ -207,6 +213,50 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function getChildNodes
|
||||||
|
* Returns the child nodes of the specified nodes. By default this method
|
||||||
|
* will ignore child text nodes which are made up of whitespace content.
|
||||||
|
* The 'includeWhiteSpace' option is used to control this behaviour.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* node - {DOMElement}
|
||||||
|
* options - {Object} Optional object for test configuration.
|
||||||
|
*
|
||||||
|
* Valid options:
|
||||||
|
* includeWhiteSpace - {Boolean} Include whitespace only nodes when
|
||||||
|
* comparing child nodes. Default is false.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Array} of {DOMElement}
|
||||||
|
*/
|
||||||
|
function getChildNodes(node, options) {
|
||||||
|
//check whitespace
|
||||||
|
if (options && options.includeWhiteSpace) {
|
||||||
|
return node.childNodes;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nodes = [];
|
||||||
|
for (var i = 0; i < node.childNodes.length; i++ ) {
|
||||||
|
var child = node.childNodes[i];
|
||||||
|
if (child.nodeType == 1) {
|
||||||
|
//element node, add it
|
||||||
|
nodes.push(child);
|
||||||
|
}
|
||||||
|
else if (child.nodeType == 3) {
|
||||||
|
//text node, add if non empty
|
||||||
|
if (child.nodeValue &&
|
||||||
|
child.nodeValue.replace(/^\s*(.*?)\s*$/, "$1") != "" ) {
|
||||||
|
|
||||||
|
nodes.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: Test.AnotherWay._test_object_t.xml_eq
|
* Function: Test.AnotherWay._test_object_t.xml_eq
|
||||||
* Test if two XML nodes are equivalent. Tests for same node types, same
|
* Test if two XML nodes are equivalent. Tests for same node types, same
|
||||||
@@ -221,10 +271,13 @@
|
|||||||
* got - {DOMElement | String} A DOM node or XML string to test.
|
* got - {DOMElement | String} A DOM node or XML string to test.
|
||||||
* expected - {DOMElement | String} The expected DOM node or XML string.
|
* expected - {DOMElement | String} The expected DOM node or XML string.
|
||||||
* msg - {String} A message to print with test output.
|
* msg - {String} A message to print with test output.
|
||||||
* options - {Object} Optional object for configuring test options. Set
|
* options - {Object} Optional object for configuring test.
|
||||||
* 'prefix' property to true in order to compare element and attribute
|
*
|
||||||
* prefixes (namespace uri always tested). By default, prefixes
|
* Valid options:
|
||||||
* are not tested.
|
* prefix - {Boolean} Compare element and attribute
|
||||||
|
* prefixes (namespace uri always tested). Default is false.
|
||||||
|
* includeWhiteSpace - {Boolean} Include whitespace only nodes when
|
||||||
|
* comparing child nodes. Default is false.
|
||||||
*/
|
*/
|
||||||
var proto = Test.AnotherWay._test_object_t.prototype;
|
var proto = Test.AnotherWay._test_object_t.prototype;
|
||||||
proto.xml_eq = function(got, expected, msg, options) {
|
proto.xml_eq = function(got, expected, msg, options) {
|
||||||
|
|||||||
Reference in New Issue
Block a user