You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2022/07/11 05:26:54 UTC

[royale-asjs] branch develop updated: Add test coverage for a range of scenarios for XMLish String coercion

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 a259b4e4ce Add test coverage for a range of scenarios for XMLish String coercion
a259b4e4ce is described below

commit a259b4e4ce567313a8289df98ab500f65c97c174
Author: greg-dove <gr...@gmail.com>
AuthorDate: Mon Jul 11 17:26:43 2022 +1200

    Add test coverage for a range of scenarios for XMLish String coercion
---
 .../flexUnitTests/xml/XMLListTesterGeneralTest.as  | 92 ++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as
index d36cc67d21..9655d09f91 100644
--- a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as
+++ b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLListTesterGeneralTest.as
@@ -415,5 +415,97 @@ package flexUnitTests.xml
 //but in JS, list.valueOf() == Null, because:
             assertTrue((Null == Undefined))//true
         }
+
+        [Test]
+        public function testListCoercion():void{
+            var node:XML = <type type="without name attribute"><val>2</val></type>;
+
+            var emptyList:XMLList = node.@name;
+            var typeList:XMLList = node.@type;
+            var someValList:XMLList;
+            var nullList:XMLList = null;
+
+            var str:String = emptyList;
+            assertTrue(str == '');
+
+            str = nullList;
+            assertTrue(str === null);
+
+            str = 'test'+emptyList;
+            assertTrue(str == 'test');
+
+            str = 'list '+typeList+emptyList;
+            assertTrue(str == 'list without name attribute');
+
+            str = typeList+emptyList + ' is how I would describe that node';
+            assertTrue(str == 'without name attribute is how I would describe that node');
+
+            var n:Number = Number(emptyList);
+            assertTrue(n == 0);
+
+            n = Number(nullList);
+            assertTrue(n == 0);
+
+            n = 1+emptyList;
+            assertTrue(n == 1);
+
+            var b:Boolean = Boolean(emptyList);
+            assertTrue(b === true);
+
+            b = emptyList || false;
+            assertTrue(b === true);
+
+            //non-empty coercion example
+            someValList = node.val;
+            n = 1+someValList; // this should be string concatenation ultimately coerced to Number
+            assertTrue(n === 12);
+
+            n = 1+nullList; // this should be string concatenation ultimately coerced to Number
+            assertTrue(n === 1);
+
+            //check again with inline lists
+            str = node.@name;
+            assertTrue(str == '');
+
+            str = 'test'+node.@name;
+            assertTrue(str == 'test');
+
+            str = 'list '+node.@type+node.@name;
+            assertTrue(str == 'list without name attribute');
+
+            str = node.@type + node.@name + ' is how I would describe that node';
+            assertTrue(str == 'without name attribute is how I would describe that node');
+
+            n = Number(node.@name);
+            assertTrue(n == 0);
+
+            n = 1 + node.@name;
+            assertTrue(n == 1);
+
+            n = 1+node.val;
+            assertTrue(n === 12);
+
+            //tests with non-XMLish member access
+            var thing:TestClassLocal = new TestClassLocal();
+            str = thing.myXMLList;
+            assertTrue(str === null);
+
+            thing.myXMLList = new XMLList();
+            str = thing.myXMLList;
+            assertTrue(str == '');
+
+            str = thing.myXMLList.notAChild;
+            assertTrue(str == '');
+            privateRef = thing;
+
+            var inst:XMLListTesterGeneralTest  = this;
+            str = inst.privateRef.myXMLList.notAChild;
+            assertTrue(str == '');
+        }
+        private var privateRef:TestClassLocal;
     }
 }
+class TestClassLocal {
+
+    public var myXMLList:XMLList;
+}
\ No newline at end of file