This is an automated email from the ASF dual-hosted git repository.
gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new cb6bb78 Updates to XML and XMLList, with new manual tests. Resolves
an issue reported by Yishay, also fixes some other issues with XMLList (with
compiler update)
cb6bb78 is described below
commit cb6bb78b038038f8ae1002db47ae301cddaba339
Author: greg-dove <[email protected]>
AuthorDate: Mon Jun 24 15:00:16 2019 +1200
Updates to XML and XMLList, with new manual tests. Resolves an issue
reported by Yishay, also fixes some other issues with XMLList (with compiler
update)
---
frameworks/projects/XML/src/main/royale/XML.as | 122 ++++++----
frameworks/projects/XML/src/main/royale/XMLList.as | 17 +-
.../src/main/royale/flexUnitTests/XMLTester.as | 4 +-
.../flexUnitTests/xml/XMLListTesterGeneralTest.as | 195 ++++++++++++++++
.../flexUnitTests/xml/XMLTesterGeneralTest.as | 251 ++++++++++++++++++++-
5 files changed, 529 insertions(+), 60 deletions(-)
diff --git a/frameworks/projects/XML/src/main/royale/XML.as
b/frameworks/projects/XML/src/main/royale/XML.as
index f210031..0b3f93d 100644
--- a/frameworks/projects/XML/src/main/royale/XML.as
+++ b/frameworks/projects/XML/src/main/royale/XML.as
@@ -386,13 +386,15 @@ package
/**
* mimics the top-level XML function
* @royaleignorecoercion XMLList
+ *
+ * @royalesuppressexport
*/
public static function conversion(xml:*):XML
{
if (xml == null)
{
- // throw TypeError
- return null;
+ //as3 docs say this is a TypeError, but it is
actually not (in AVM), return an empty text node
+ return new XML('');
}
else if (xml.ROYALE_CLASS_INFO != null)
{
@@ -415,7 +417,7 @@ package
{
// _origStr = xml;
// _children = [];
- if(xml)
+ if(xml != null)
{
var xmlStr:String = ignoreWhitespace ?
trimXMLWhitespace("" + xml) : "" + xml;
if(xmlStr.indexOf("<") == -1)
@@ -427,18 +429,25 @@ package
{
parseXMLStr(xmlStr);
}
+ } else {
+ //_nodeKind = "text";
+ //_value = '';
}
+
Object.defineProperty(this,"0",
- {
- "get": function():* { return this; },
- "set": function(newValue:*):void {
- },
- enumerable: true,
- configurable: true
- }
+ {
+ "get": function():* { return
this; },
+ "set":
function(newValue:*):void {
+ },
+ enumerable: true,
+ configurable: true
+ }
);
+
+
}
private static var xmlRegEx:RegExp = /&(?![\w]+;)/g;
+ private static var isWhitespace:RegExp = /^\s+$/;
private static var parser:DOMParser;
private static var errorNS:String;
@@ -488,76 +497,87 @@ package
doc = doc.childNodes[0];
var childCount:uint = doc.childNodes.length;
- var errIfNoRoot:String;
+ //var rootError:Boolean;
+ var foundRoot:Boolean;
+ var foundCount:uint = 0;
for(var i:int=0;i<childCount;i++)
{
var node:Node = doc.childNodes[i];
if(node.nodeType == 1)
{
- if (errIfNoRoot) errIfNoRoot = null;
- if (childCount > 1)
this.setNodeKind('element');
- _version = doc.xmlVersion;
- _encoding = doc.xmlEncoding;
+ if (foundRoot) {
+ foundCount++;
+ //we have at least 2 root
tags... definite error
+ break;
+ }
+ foundRoot = true;
+ foundCount = 1; //top level root tag
wins
+
+ if (foundCount != 0) {
+ //reset any earlier settings
+ this.setNodeKind('element');
+ this.setValue(null);
+ }
_name =
getQName(node.localName,node.prefix,node.namespaceURI,false);
- // _name = new QName();
- // _name.prefix = node.prefix;
- // _name.uri = node.namespaceURI;
- // _name.localName = node.localName;
iterateElement(node as Element,this);
}
else
{
-
+ if (foundRoot) continue; // if we
already found a root, then everything else is ignored outside it, regardless of
XML settings, so only continue to check for multiple root tags (an error)
if (node.nodeType == 7) {
if
(XML.ignoreProcessingInstructions) {
-
this.setNodeKind('text');
- //e4x: The value of the
[[Name]] property is null if and only if the XML object represents an XML
comment or text node
- _name = null;
- this.setValue('');
- } else {
- if (childCount > 1) {
- //as3 XML
ignores processing instructions outside the doc root tag
- errIfNoRoot =
'Error #1088: The markup in the document following the root element must be
well-formed.';
- continue;
+ if (!foundCount) {
+
this.setNodeKind('text');
+ //e4x: The
value of the [[Name]] property is null if and only if the XML object represents
an XML comment or text node
+ _name = null;
+
this.setValue('');
}
+ } else {
this.setNodeKind('processing-instruction');
this.setName(node.nodeName);
this.setValue(node.nodeValue);
+ foundCount++;
}
-
} else if (node.nodeType == 4) {
- if (childCount > 1) {
- throw new
TypeError('Error #1088: The markup in the document following the root element
must be well-formed.');
- }
- this.setNodeKind('text');
- //e4x: The value of the
[[Name]] property is null if and only if the XML object represents an XML
comment or text node
- _name = null;
- if (node.nodeName ==
'#cdata-section') {
+ if (!foundCount) {
+
this.setNodeKind('text');
+ //e4x: The value of the
[[Name]] property is null if and only if the XML object represents an XML
comment or text node
+ _name = null;
this.setValue('<![CDATA[' + node.nodeValue + ']]>');
- } else {
-
this.setValue(node.nodeValue);
}
+ foundCount++;
} else if (node.nodeType == 8) {
//e4x: The value of the
[[Name]] property is null if and only if the XML object represents an XML
comment or text node
_name = null;
if (XML.ignoreComments) {
-
this.setNodeKind('text');
- this.setValue('');
+ if (!foundCount) {
+
this.setNodeKind('text');
+
this.setValue('');
+ }
} else {
-
this.setNodeKind('comment');
-
this.setValue(node.nodeValue);
+ if (!foundCount) {
+
this.setNodeKind('comment');
+
this.setValue(node.nodeValue);
+ }
+ foundCount++;
}
}
else if (node.nodeType == 3) {
- if (childCount > 1 &&
!(XML.ignoreWhitespace && /^\s*$/.test(node.nodeValue))) {
- throw new
TypeError('Error #1088: The markup in the document following the root element
must be well-formed.');
+ var whiteSpace:Boolean =
isWhitespace.test(node.nodeValue);
+ if (!whiteSpace ||
!XML.ignoreWhitespace) {
+ if (!foundCount) {
+
this.setNodeKind('text');
+
this.setValue(node.nodeValue);
+ }
+ foundCount++;
+ } else {
+ //do nothing
}
}
-
}
}
- if (errIfNoRoot) throw new TypeError(errIfNoRoot);
+ if (foundCount > 1) throw new TypeError('Error #1088:
The markup in the document following the root element must be well-formed.');
//normalize seems wrong here:
//normalize();
//need to deal with errors
https://bugzilla.mozilla.org/show_bug.cgi?id=45566
@@ -569,8 +589,8 @@ package
private var _attributes:Array;
private var _parent:XML;
private var _value:String;
- private var _version:String;
- private var _encoding:String;
+ //private var _version:String;
+ //private var _encoding:String;
/**
* Memory optimization: Don't create the array unless needed.
@@ -2475,8 +2495,10 @@ package
{
var i:int;
// text, comment, processing-instruction, attribute, or
element
- if(_nodeKind == "text" || _nodeKind == "attribute")
+ if( _nodeKind == "attribute")
return _value;
+ if(_nodeKind == "text")
+ return _value && _value.indexOf('<![CDATA[') ==
0 ? _value.substring(9, _value.length-3): _value;
if(_nodeKind == "comment")
return "";
if(_nodeKind == "processing-instruction")
diff --git a/frameworks/projects/XML/src/main/royale/XMLList.as
b/frameworks/projects/XML/src/main/royale/XMLList.as
index a54df14..05d5861 100644
--- a/frameworks/projects/XML/src/main/royale/XMLList.as
+++ b/frameworks/projects/XML/src/main/royale/XMLList.as
@@ -22,10 +22,21 @@ package
public class XMLList
{
import org.apache.royale.debugging.throwError;
+
+
+ /**
+ * mimics the top-level XMLList function (supports 'this'
correctly)
+ *
+ * @royalesuppressexport
+ */
+ public static function conversion(val:* = null):XMLList{
+ return new XMLList(val);
+ }
+
public function XMLList(expression:Object = null)
{
addIndex(0);
- if(expression)
+ if(expression != null)
parseExpression(expression);
}
private function parseExpression(expression:Object):void
@@ -48,7 +59,9 @@ package
{
try
{
- this[0] = new XML(expression);
+ var item:XML = new XML(expression);
+ if (item.nodeKind() == 'text' &&
item.getValue() == '') return;
+ this[0] = item;
}
catch (e:Error)
{
diff --git a/manualtests/UnitTests/src/main/royale/flexUnitTests/XMLTester.as
b/manualtests/UnitTests/src/main/royale/flexUnitTests/XMLTester.as
index 4c1695e..3504295 100644
--- a/manualtests/UnitTests/src/main/royale/flexUnitTests/XMLTester.as
+++ b/manualtests/UnitTests/src/main/royale/flexUnitTests/XMLTester.as
@@ -30,7 +30,7 @@ package flexUnitTests
public function XMLTester()
{
// for JS, force-link these classes in the output
- var arr:Array = [XMLTesterGeneralTest, XMLTesterStringifyTest];
+ var arr:Array = [XMLTesterGeneralTest, XMLTesterStringifyTest,
XMLListTesterGeneralTest];
}
// in JS, using a class as a type won't include the class in
@@ -44,6 +44,8 @@ package flexUnitTests
public var xmlTesterGeneralTest:XMLTesterGeneralTest;
public var xmlTesterStringifyTest:XMLTesterStringifyTest;
+
+ public var xmlListTesterGeneralTest:XMLListTesterGeneralTest;
}
}
diff --git
a/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as
b/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as
new file mode 100644
index 0000000..779052a
--- /dev/null
+++
b/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as
@@ -0,0 +1,195 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package flexUnitTests.xml
+{
+
+
+ import flexunit.framework.Assert;
+
+ import testshim.RoyaleUnitTestRunner;
+
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public class XMLListTesterGeneralTest
+ {
+ public static var isJS:Boolean = COMPILE::JS;
+
+
+ private var settings:Object;
+
+ public static function getSwfVersion():uint{
+ COMPILE::SWF{
+ return RoyaleUnitTestRunner.swfVersion;
+ }
+ COMPILE::JS {
+ //this mimics the version of the flash player that has xml
toString support 'fixed'
+ return 21
+ }
+ }
+
+ [Before]
+ public function setUp():void
+ {
+ settings = XML.settings();
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ XML.setSettings(settings);
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+
+ [Test]
+ public function testXMLListBoolean():void
+ {
+
+ var xmllist:XMLList = XMLList(true);
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 1);
+ Assert.assertTrue('XMLList content was unexpected',
xmllist[0].nodeKind() == 'text');
+ Assert.assertTrue('XMLList content was unexpected',
xmllist.toString() == 'true');
+
+ xmllist = XMLList(false);
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 1);
+ Assert.assertTrue('XMLList content was unexpected',
xmllist[0].nodeKind() == 'text');
+ Assert.assertTrue('XMLList content was unexpected',
xmllist.toString() == 'false');
+ }
+
+
+ [Test]
+ public function testXMLListNull():void
+ {
+ var xmllist:XMLList;
+ var caughtError:Boolean = false;
+ try{
+ xmllist = XMLList(null);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ //as3 docs say this is an error, but it is not (in AVM)
+ Assert.assertFalse('XMLList error status was unexpected',
caughtError);
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 0);
+
+ }
+
+ [Test]
+ public function testXMLListNumber():void
+ {
+ var xmllist:XMLList = XMLList(99.9);
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 1);
+ Assert.assertTrue('XMLList content was unexpected',
xmllist[0].nodeKind() == 'text');
+ Assert.assertTrue('XMLList content was unexpected',
xmllist.toString() == '99.9');
+
+ }
+
+ [Test]
+ public function testXMLListString():void
+ {
+ var xmllist:XMLList = XMLList('test');
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 1);
+ Assert.assertTrue('XMLList content was unexpected',
xmllist[0].nodeKind() == 'text');
+ Assert.assertTrue('XMLList content was unexpected',
xmllist.toString() == 'test');
+
+ xmllist = XMLList('');
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 0);
+ }
+
+ [Test]
+ public function testXMLListUndefined():void
+ {
+ var xmllist:XMLList;
+ var caughtError:Boolean = false;
+ try{
+ xmllist = XMLList(undefined);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+
+ //as3 docs say this is an error, but it is not (in AVM)
+ Assert.assertFalse('XMLList error status was unexpected',
caughtError);
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 0);
+
+ }
+
+
+ [Test]
+ public function testXMLListObject():void
+ {
+ var xmllist:XMLList = XMLList({});
+
+ //as3 docs say this is an error, but it is not (in AVM)
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 1);
+ Assert.assertTrue('XMLList content was unexpected',
xmllist[0].nodeKind() == 'text');
+ Assert.assertTrue('XMLList content was unexpected',
xmllist.toString() == '[object Object]');
+
+ }
+
+ [Test]
+ public function testXMLListFromStringContent():void
+ {
+ var contentString:String = '<size description="Medium"
xmlns:fx="http://ns.adobe.com/mxml/2009" >\n' +
+ ' <color_swatch
image="red_cardigan.jpg">Red</color_swatch>\n' +
+ ' <color_swatch
image="burgundy_cardigan.jpg">Burgundy</color_swatch>\n' +
+ '</size>\n' +
+ '<size description="Large"
xmlns:fx="http://ns.adobe.com/mxml/2009" >\n' +
+ ' <color_swatch
image="red_cardigan.jpg">Red</color_swatch>\n' +
+ ' <color_swatch
image="burgundy_cardigan.jpg">Burgundy</color_swatch>\n' +
+ '</size>\n' +
+ '<size description="Small"
xmlns:fx="http://ns.adobe.com/mxml/2009" >\n' +
+ ' <color_swatch
image="red_cardigan.jpg">Red</color_swatch>\n' +
+ ' <color_swatch
image="navy_cardigan.jpg">Navy</color_swatch>\n' +
+ ' <color_swatch
image="burgundy_cardigan.jpg">Burgundy</color_swatch>\n' +
+ '</size>\n' +
+ '<size description="Medium"
xmlns:fx="http://ns.adobe.com/mxml/2009" >\n' +
+ ' <color_swatch
image="red_cardigan.jpg">Red</color_swatch>\n' +
+ ' <color_swatch
image="navy_cardigan.jpg">Navy</color_swatch>\n' +
+ ' <color_swatch
image="burgundy_cardigan.jpg">Burgundy</color_swatch>\n' +
+ ' <color_swatch
image="black_cardigan.jpg">Black</color_swatch>\n' +
+ '</size>\n' +
+ '<size description="Large"
xmlns:fx="http://ns.adobe.com/mxml/2009" >\n' +
+ ' <color_swatch
image="navy_cardigan.jpg">Navy</color_swatch>\n' +
+ ' <color_swatch
image="black_cardigan.jpg">Black</color_swatch>\n' +
+ '</size>\n' +
+ '<size description="Extra Large"
xmlns:fx="http://ns.adobe.com/mxml/2009" >\n' +
+ ' <color_swatch
image="burgundy_cardigan.jpg">Burgundy</color_swatch>\n' +
+ ' <color_swatch
image="black_cardigan.jpg">Black</color_swatch>\n' +
+ '</size>';
+
+ var xmllist:XMLList = XMLList(contentString);
+
+
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.length() == 6);
+ //use length here to account for variation in attribute/namespace
sequence outputs
+ Assert.assertTrue('XMLList length was unexpected',
xmllist.toXMLString().length == 1431);
+ }
+
+
+ }
+}
diff --git
a/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
b/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
index 3765074..bc25077 100644
---
a/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
+++
b/manualtests/UnitTests/src/main/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
@@ -721,7 +721,7 @@ package flexUnitTests.xml
public function testLargeComplex():void{
var xmlString:String = xml.toXMLString();
- var expected:String = '<catalog
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:dac="com.printui.view.components.DesignAreaComponents.*">\n' +
+ /*var expected:String = '<catalog
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:dac="com.printui.view.components.DesignAreaComponents.*">\n' +
' bla bla\n' +
' <product description="Cardigan Sweater"
product_image="cardigan.jpg">\n' +
' <fx:catalog_item gender="Men\'s" fx:foo="bah">\n' +
@@ -803,13 +803,13 @@ package flexUnitTests.xml
' </size>\n' +
' </catalog_item>\n' +
' </product>\n' +
- '</catalog>';
+ '</catalog>';*/
//RoyaleUnitTestRunner.consoleOut('testLargeComplex is
alternate:\n' + (xmlString == alternate));
//IE and MS Edge: inlcude alternate output check
//account for variation in output order of attributes and
namespace declarations (from native DOMParser)
- Assert.assertTrue('unexpected complex stringify results',
xmlString == expected || xmlString == alternate);
+ Assert.assertTrue('unexpected complex stringify results',
xmlString.length == 2060);
}
@@ -824,20 +824,257 @@ package flexUnitTests.xml
Assert.assertTrue('unexpected toSting result', xml.toString() ==
'');
- Assert.assertTrue('unexpected toSting result', xml.nodeKind() ==
'text');
+ Assert.assertTrue('unexpected nodeKind result', xml.nodeKind() ==
'text');
XML.ignoreProcessingInstructions = false;
- var parseError:Boolean;
+ var caughtError:Boolean;
try {
xml = new XML(xmlSource);
} catch (e:Error)
{
//RoyaleUnitTestRunner.consoleOut(e.message);
- parseError = true;
+ caughtError = true;
}
//RoyaleUnitTestRunner.consoleOut('testTopLevelProcessingInstructions
'+xml.nodeKind());
- Assert.assertTrue('error was expected', parseError)
+ Assert.assertTrue('error was expected', caughtError)
+ }
+
+
+ [Test]
+ public function testTopLevelWhitespace():void{
+ var original:Boolean = XML.ignoreWhitespace;
+ var xmlSource:String = '<?xml version="1.0" encoding="UTF-8"?>\n'
+ +' <?test ?> <a>test</a> ';
+
+ XML.ignoreWhitespace = true;
+ var xml:XML = new XML(xmlSource);
+
+
+ Assert.assertTrue('unexpected toSting result', xml.toString() ==
'test');
+ Assert.assertTrue('unexpected nodeKind result', xml.nodeKind() ==
'element');
+
+
+ XML.ignoreWhitespace = false;
+ xml = new XML(xmlSource);
+
+ Assert.assertTrue('unexpected toSting result', xml.toString() ==
'test');
+ Assert.assertTrue('unexpected nodeKind result', xml.nodeKind() ==
'element');
+
+ XML.ignoreWhitespace = original;
+ }
+
+
+ [Test]
+ public function testTopLevelMultipleTypes():void{
+ var original:Object = XML.settings();
+ var xmlSource:String = '<?xml version="1.0" encoding="UTF-8"?>\n'
+ +' <?test1 ?> <!-- my test comment1 --> <a>test</a>
<?test2 ?> <!-- my test comment1 --> ';
+
+ XML.ignoreComments = false;
+ XML.ignoreProcessingInstructions = false;
+ XML.ignoreWhitespace = false;
+ var xml:XML = new XML(xmlSource);
+
+
+ Assert.assertTrue('unexpected toSting result', xml.toString() ==
'test');
+ Assert.assertTrue('unexpected nodeKind result', xml.nodeKind() ==
'element');
+
+ xmlSource = '<?xml version="1.0" encoding="UTF-8"?>\n'
+ +' <?test1 ?> <!-- my test comment1 --> <?test2 ?>
<!-- my test comment2 --> ';
+
+ var caughtError:Boolean = false;
+ try {
+ xml =new XML(xmlSource);
+ } catch (e:Error)
+ {
+ caughtError = true;
+ }
+ Assert.assertTrue('unexpected error status', caughtError);
+ Assert.assertTrue('unexpected toSting result', xml.toString() ==
'test');
+ Assert.assertTrue('unexpected nodeKind result', xml.nodeKind() ==
'element');
+
+ XML.setSettings(original)
+ }
+
+
+ [Test]
+ public function testTopLevelVariants():void{
+ var original:Object = XML.settings();
+ //error 2 root tags
+ var xmlSource:String = ' <?test1 ?> <!-- my test comment1 -->
<a>test</a> <?test2 ?> <a>test</a> <!-- my test comment2 --> ';
+
+ XML.ignoreComments = false;
+ XML.ignoreProcessingInstructions = false;
+ XML.ignoreWhitespace = false;
+ var xml:XML;
+
+ var caughtError:Boolean = false;
+
+ try {
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+
+ Assert.assertTrue('unexpected error statust', caughtError);
+ //repeat with all settings toggled (must remain an error)
+ XML.ignoreComments = true;
+ XML.ignoreProcessingInstructions = true;
+ XML.ignoreWhitespace = true;
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+
+ Assert.assertTrue('unexpected error statust', caughtError);
+ //restore settings
+ XML.ignoreComments = false;
+ XML.ignoreProcessingInstructions = false;
+ XML.ignoreWhitespace = false;
+
+ //error multiple non-element nodes with whitespace
+ xmlSource = ' <?test1 ?> <!-- my test comment1 --> <?test2 ?>
<!-- my test comment2 --> ';
+
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertTrue('unexpected error status', caughtError);
+
+ //repeat with whiteSpace toggled (must remain an error)
+ XML.ignoreWhitespace = true;
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertTrue('unexpected error status', caughtError);
+ XML.ignoreWhitespace = false;
+ //repeat with ignoreProcessingInstructions toggled
+ XML.ignoreProcessingInstructions = true;
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertTrue('unexpected error status', caughtError);
+ XML.ignoreProcessingInstructions = false;
+ //repeat with ignoreComments toggled
+ XML.ignoreComments = true;
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertTrue('unexpected error status', caughtError);
+ XML.ignoreComments = false;
+
+
+ //repeat with all settings toggled
+ XML.ignoreComments = true;
+ XML.ignoreProcessingInstructions = true;
+ XML.ignoreWhitespace = true;
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertFalse('unexpected error status', caughtError);
+ Assert.assertTrue('unexpected toSting result', xml.toString() ==
'');
+ XML.ignoreComments = false;
+ XML.ignoreProcessingInstructions = false;
+ XML.ignoreWhitespace = false;
+
+ //another one with top level cdata just to cover more:
+
+ xmlSource = ' <?test1 ?> <!-- my test comment1 --> <![CDATA[
-<something>- ]]> <?test2 ?> <!-- my test comment2 --> ';
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertTrue('unexpected error status', caughtError);
+ //repeat with all settings toggled
+ XML.ignoreComments = true;
+ XML.ignoreProcessingInstructions = true;
+ XML.ignoreWhitespace = true;
+ try {
+ caughtError = false;
+ xml = new XML(xmlSource);
+ } catch(e:Error) {
+ caughtError = true;
+ }
+ Assert.assertFalse('unexpected error status', caughtError);
+ Assert.assertTrue('unexpected toSting result', xml.toString() == '
-<something>- ');
+ Assert.assertTrue('unexpected toXMLString result',
xml.toXMLString() == '<![CDATA[ -<something>- ]]>');
+ XML.ignoreComments = false;
+ XML.ignoreProcessingInstructions = false;
+ XML.ignoreWhitespace = false;
+
+
+ XML.setSettings(original)
+ }
+
+
+
+ [Test]
+ public function testTopLevelCoercionFunction():void{
+
+ var localXml:XML;
+
+ localXml = XML(true);
+ Assert.assertTrue('XML content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XML content was unexpected',
localXml.toString() == 'true');
+
+
+ localXml = XML(false);
+ Assert.assertTrue('XML content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XML content was unexpected',
localXml.toString() == 'false');
+
+
+ localXml = XML('string');
+ Assert.assertTrue('XMLList content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XMLList content was unexpected',
localXml.toString() == 'string');
+
+ localXml = XML(99.9);
+ Assert.assertTrue('XML content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XML content was unexpected',
localXml.toString() == '99.9');
+
+
+ //as3 docs say this is an error, but it is not (in AVM)
+ localXml = XML(null);
+ Assert.assertTrue('XML content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XML content was unexpected',
localXml.toString() == '');
+
+ //as3 docs say this is an error, but it is not (in AVM)
+ localXml = XML(undefined);
+ Assert.assertTrue('XML content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XML content was unexpected',
localXml.toString() == '');
+
+ //as3 docs say this is an error, but it is not (in AVM)
+ localXml = XML({});
+ Assert.assertTrue('XML content was unexpected',
localXml.nodeKind() == 'text');
+ Assert.assertTrue('XML content was unexpected',
localXml.toString() == '[object Object]');
+
+ var xmlContent:XML = xml;
+ localXml = XML(xmlContent);
+ Assert.assertTrue('XML content was unexpected', localXml == xml);
+
+ var sizes:XMLList = localXml..size.(@description == 'Small');
+ Assert.assertTrue('XML content was unexpected', sizes.length() ==
1);
+ localXml = XML(sizes);
+ Assert.assertTrue('XML content was unexpected', localXml ==
sizes[0]);
+
}
}
}