Browse Source

fixed flash9 Xml.nodeValue for comments (does not include <!--/-->)

Nicolas Cannasse 14 years ago
parent
commit
e35a0fed04
3 changed files with 24 additions and 8 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 2 0
      std/flash9/_std/Xml.hx
  3. 21 8
      tests/unit/TestXML.hx

+ 1 - 0
doc/CHANGES.txt

@@ -46,6 +46,7 @@
 	all : fixed issues with inlining and class/function type parameters
 	all : big speedup for compiler internal completion
 	all : added --macro keepClass('classname')
+	flash9 : fixed Xml.nodeValue for comments (does not include <!--/-->)
 
 2010-08-14: 2.06
 	neko : change serializer to be able to handle instances of basic classes from other modules

+ 2 - 0
std/flash9/_std/Xml.hx

@@ -142,6 +142,8 @@ enum XmlType {
 		var nodeType = nodeType;
 		if( nodeType == Xml.Element || nodeType == Xml.Document )
 			throw "bad nodeType";
+		if( nodeType == Xml.Comment )
+			return _node.toString().substr(4,-7);
 		return _node.toString();
 	}
 

+ 21 - 8
tests/unit/TestXML.hx

@@ -126,22 +126,35 @@ class TestXML extends Test {
 		eq( Xml.createDocument().toString(), "");
 		eq( Xml.createPCData("Hello").toString(), "Hello" );
 		#if flash8
-
 		// too hard for him
+		return;
+		#end
 
-		#elseif flash9
-		// flash9 printer love to include additional whitespaces
-		eq( Xml.createCData("<x>").toString(), "<![CDATA[ <x> ]]>" );
-		eq( Xml.createComment("Hello").toString(), "<!-- Hello -->" );
+		eq( Xml.createCData("<x>").toString(), "<![CDATA[<x>]]>" );
+		eq( Xml.createComment("Hello").toString(), "<!--Hello-->" );
+		
+		#if flash9
 		eq( Xml.createProlog("XHTML").toString(), "<?XHTML ?>");
 		// doctype is parsed but not printed
 		eq( Xml.createDocType("XHTML").toString(), "" );
 		#else
-		eq( Xml.createCData("<x>").toString(), "<![CDATA[<x>]]>" );
-		eq( Xml.createComment("Hello").toString(), "<!--Hello-->" );
-		eq( Xml.createDocType("XHTML").toString(), "<!DOCTYPE XHTML>" );
 		eq( Xml.createProlog("XHTML").toString(), "<?XHTML?>");
+		eq( Xml.createDocType("XHTML").toString(), "<!DOCTYPE XHTML>" );
 		#end
+				
+		eq( Xml.parse("<!--Hello-->").firstChild().nodeValue, "Hello" );
+		var c = Xml.createComment("Hello");
+		eq( c.nodeValue, "Hello" );
+		c.nodeValue = "Blabla";
+		eq( c.nodeValue, "Blabla" );
+		eq( c.toString(), "<!--Blabla-->");
+		eq( Xml.parse("<![CDATA[Hello]]>").firstChild().nodeValue, "Hello" );
+		var c = Xml.createCData("Hello");
+		eq( c.nodeValue, "Hello" );
+		c.nodeValue = "Blabla";
+		eq( c.nodeValue, "Blabla" );
+		eq( c.toString(), "<![CDATA[Blabla]]>");
+		eq( Xml.createPCData("Hello").nodeValue, "Hello" );
 	}
 
 	function testNS() {