<?xml version="1.0"?>
<mx:Application name="lightspark_XMLList_test"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	applicationComplete="appComplete();"
	backgroundColor="white">

<mx:Script>
	<![CDATA[
	import Tests;
	private function appComplete():void
	{
		var xml1:XML=new XML("<test1></test1>");
		var xml2:XML=new XML("<test2></test2>");
		var list:XMLList=new XMLList();

		list[10]=xml1;
		list[2]=xml2;

		Tests.assertEquals(2,list.length(),"Sparse XMLList: length");
		var str:String = "";
		for each(var x:XML in list)
			str+=x.toXMLString();
		Tests.assertEquals("<test1/><test2/>",str,"Sparse XMLList: elements order");

		try
		{
			var xml3:XML = XML(list);
			Tests.assertDontReach("XML from XMLList with more than an element");
		}
		catch(e:Error)
		{
			Tests.assertTrue(e is TypeError, "XML from XMLList with more than an element");
		}

		var list2:XMLList=new XMLList();
		list2[1]=xml1;

		var xml4:XML = XML(list2);
		Tests.assertEquals(xml4.toXMLString(), xml1.toXMLString(), "XML from XMLList with a single element");

		var xml5:XML = XML("<a><child1/></a>");
		var xml6:XML = XML("<b><child2/></b>");
		var list3:XMLList = new XMLList();
		list3[0] = xml5;
		list3[1] = xml6;
		Tests.assertEquals(2, list3.length(), "XMLList sanity check");
		var list4:XMLList = list3.children();
		Tests.assertEquals("<child1/>\n<child2/>", list4.toXMLString(), "XMLList::children");

		var list5:XMLList = new XMLList("<node name='alice'/><node name='bob'/>").(hasOwnProperty("@name") && @name == "alice");
		Tests.assertEquals(1, list5.length(), "hasOwnProperty selector");

		Tests.report(visual, this.name);
	}
	]]>
</mx:Script>

<mx:UIComponent id="visual" />

</mx:Application>
