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 68f3fe1  incremental implementation of XML.replace method, supports 
numeric propertyName with couple of tests
68f3fe1 is described below

commit 68f3fe14aa5fb440b57fc64b420905098b7921d3
Author: greg-dove <greg.d...@gmail.com>
AuthorDate: Wed Jan 13 10:59:40 2021 +1300

    incremental implementation of XML.replace method, supports numeric 
propertyName with couple of tests
---
 frameworks/projects/XML/src/main/royale/XML.as     | 15 ++++++++-----
 .../flexUnitTests/xml/XMLTesterGeneralTest.as      | 26 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/frameworks/projects/XML/src/main/royale/XML.as 
b/frameworks/projects/XML/src/main/royale/XML.as
index 0b2d810..183d2f2 100644
--- a/frameworks/projects/XML/src/main/royale/XML.as
+++ b/frameworks/projects/XML/src/main/royale/XML.as
@@ -2345,16 +2345,19 @@ package
                        if(ref == TEXT || ref == COMMENT || ref == 
PROCESSING_INSTRUCTION || ref ==  ATTRIBUTE)
                        {
                                // Changing this to pretend we're a string
-                               return s().replace(propertyName,value);
+                               return s().replace(propertyName,value); //@todo 
check this in flash/add tests, it seems inconsistent with the above, but may be 
a flash quirk?
                                //return this;
                        }
-                       if(value === null || value === undefined)
-                               return this;
                        if((value is XML) || (value is XMLList))
-                               value = value.copy();
+                               value = value.copy(); //step 3 above
                        else
-                               value = value.toString();
-                       
+                               value = value + ''; //step 2 above (null and 
undefined 'value' is converted to string representation)
+                       var idx:uint = parseInt(propertyName,10);
+                       if (idx.toString() == propertyName+'') {
+                               replaceChildAt(idx, value);
+                               return this; //to step 4 above
+                       }
+                       //@todo step 5+ above...
                        return null;
                }
                
diff --git 
a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
 
b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
index 3938c8e..cc82b5e 100644
--- 
a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
+++ 
b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
@@ -449,6 +449,32 @@ package flexUnitTests.xml
                     '</root>', 'testAppendNonXMLChild 4 result is bad');
             
         }
+
+        [Test]
+        public function testReplace():void{
+            //WIP
+            var xml:XML =<test><a href="something">test link 
content</a></test>;
+
+            var child:XML = xml.children()[0];
+            xml.replace(0, child.toString());
+            assertEquals(
+                    xml.toXMLString(),
+                    '<test>test link content</test>', 'testReplace 1 result is 
bad');
+            xml =<test><a href="something">test link content</a></test>;
+            xml.replace(0, null);
+
+            assertEquals(
+                    xml.toXMLString(),
+                    '<test>null</test>', 'testReplace 2 result is bad');
+
+            xml =<test><a href="something">test link content</a></test>;
+            xml.replace(0, undefined);
+
+            assertEquals(
+                    xml.toXMLString(),
+                    '<test>undefined</test>', 'testReplace 3 result is bad');
+
+        }
         
         
         [Test]

Reply via email to