royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [royale-asjs] branch feature/testing updated: Added tests for date utils They actually found a bug…
Date Sun, 05 Nov 2017 23:08:32 GMT
This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch feature/testing
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/feature/testing by this push:
     new c44f852  Added tests for date utils They actually found a bug…
c44f852 is described below

commit c44f85277ab915ffb833fac9094e9f7611c507e1
Author: Harbs <harbs@in-tools.com>
AuthorDate: Mon Nov 6 01:08:26 2017 +0200

    Added tests for date utils
    They actually found a bug…
---
 .../org/apache/royale/utils/date/addYears.as       |   4 +-
 .../src/test/royale/flexUnitTests/CoreTester.as    |   1 +
 .../src/test/royale/flexUnitTests/DateUtilsTest.as | 144 +++++++++++++++++++++
 .../royale/org/apache/royale/test/TestRunner.as    |   4 +-
 4 files changed, 149 insertions(+), 4 deletions(-)

diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/date/addYears.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/date/addYears.as
index 4ef938d..574d591 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/date/addYears.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/date/addYears.as
@@ -25,10 +25,10 @@ package org.apache.royale.utils.date
 	 *  @playerversion AIR 2.6
 	 *  @productversion Royale 0.9
 	 */
-    public function addYears(date:Date):Date
+    public function addYears(date:Date, years:int=1):Date
     {
 		var newDate:Date = new Date(date.valueOf());
-		newDate.setDate(date.getDate()+1);
+		newDate.setFullYear(date.getFullYear() + years);
 		return newDate;
     }
 }
diff --git a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as b/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
index 098a6a9..74dd366 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
+++ b/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
@@ -24,5 +24,6 @@ package flexUnitTests
     {
         public var strandTesterTest:StrandTesterTest;
 		public var binaryDataTesterTest:BinaryDataTesterTest;
+		public var dateUtilsTest:DateUtilsTest;
     }
 }
diff --git a/frameworks/projects/Core/src/test/royale/flexUnitTests/DateUtilsTest.as b/frameworks/projects/Core/src/test/royale/flexUnitTests/DateUtilsTest.as
new file mode 100644
index 0000000..3202e67
--- /dev/null
+++ b/frameworks/projects/Core/src/test/royale/flexUnitTests/DateUtilsTest.as
@@ -0,0 +1,144 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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
+{
+    import org.apache.royale.utils.date.*;
+    import org.apache.royale.core.Strand;
+    import org.apache.royale.test.asserts.*;
+    
+    public class DateUtilsTest
+    {		
+        [Before]
+        public function setUp():void
+        {
+        }
+        
+        [After]
+        public function tearDown():void
+        {
+        }
+        
+        [BeforeClass]
+        public static function setUpBeforeClass():void
+        {
+        }
+        
+        [AfterClass]
+        public static function tearDownAfterClass():void
+        {
+        }
+        
+        [Test]
+        public function testAddDays():void
+        {
+            var date:Date = new Date(1995, 11, 17);
+            var newDate:Date = addDays(date);
+
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getDate() + 1, newDate.getDate(), "New date should be next
day");
+            newDate = addDays(date,2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getDate() + 2, newDate.getDate(), "New date should be two days
later");
+            newDate = addDays(date,-2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getDate() - 2, newDate.getDate(), "New date should be two days
earlier");
+        }
+
+        [Test]
+        public function testAddHours():void
+        {
+            var date:Date = new Date(1995, 11, 17, 10, 5, 11);
+            var newDate:Date = addHours(date);
+
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getHours() + 1, newDate.getHours(), "New date should be next
hour");
+            newDate = addHours(date,2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getHours() + 2, newDate.getHours(), "New date should be two
hours later");
+            newDate = addHours(date,-2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getHours() - 2, newDate.getHours(), "New date should be two
hours earlier");
+        }
+
+        [Test]
+        public function testAddMinutes():void
+        {
+            var date:Date = new Date(1995, 11, 17, 10, 5, 11);
+            var newDate:Date = addMinutes(date);
+
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getMinutes() + 1, newDate.getMinutes(), "New date should be
next minute");
+            newDate = addMinutes(date,2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getMinutes() + 2, newDate.getMinutes(), "New date should be
two minutes later");
+            newDate = addMinutes(date,-2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getMinutes() - 2, newDate.getMinutes(), "New date should be
two minutes earlier");
+        }
+
+        [Test]
+        public function testAddMonths():void
+        {
+            var date:Date = new Date(1995, 9, 17, 10, 5, 11);
+            var newDate:Date = addMonths(date);
+
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getMonth() + 1, newDate.getMonth(), "New date should be next
month");
+            newDate = addMonths(date,2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getMonth() + 2, newDate.getMonth(), "New date should be two
months later");
+            newDate = addMonths(date,-2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getMonth() - 2, newDate.getMonth(), "New date should be two
months earlier");
+        }
+
+        [Test]
+        public function testAddSeconds():void
+        {
+            var date:Date = new Date(1995, 11, 17, 10, 5, 11);
+            var newDate:Date = addSeconds(date);
+
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getSeconds() + 1, newDate.getSeconds(), "New date should be
next second");
+            newDate = addSeconds(date,2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getSeconds() + 2, newDate.getSeconds(), "New date should be
two seconds later");
+            newDate = addSeconds(date,-2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getSeconds() - 2, newDate.getSeconds(), "New date should be
two seconds earlier");
+        }
+
+        [Test]
+        public function testAddYears():void
+        {
+            var date:Date = new Date(1995, 11, 17, 10, 5, 11);
+            var newDate:Date = addYears(date);
+
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getFullYear() + 1, newDate.getFullYear(), "New date should
be next year");
+            newDate = addYears(date,2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getFullYear() + 2, newDate.getFullYear(), "New date should
be two years later");
+            newDate = addYears(date,-2);
+            assertTrue(date != newDate,"Dates should not be equal");
+            assertEquals(date.getFullYear() - 2, newDate.getFullYear(), "New date should
be two years earlier");
+        }
+
+    }
+}
diff --git a/frameworks/projects/Testing/src/main/royale/org/apache/royale/test/TestRunner.as
b/frameworks/projects/Testing/src/main/royale/org/apache/royale/test/TestRunner.as
index 729b79c..166fb7b 100644
--- a/frameworks/projects/Testing/src/main/royale/org/apache/royale/test/TestRunner.as
+++ b/frameworks/projects/Testing/src/main/royale/org/apache/royale/test/TestRunner.as
@@ -280,7 +280,7 @@ package org.apache.royale.test
 		 */
 		private function collectMethodWithMetadataTag(target:Object, tagName:String):Function
 		{
-			var reflection:Object = target["FLEXJS_REFLECTION_INFO"]();
+			var reflection:Object = target["ROYALE_REFLECTION_INFO"]();
 			var methods:Object = reflection.methods();
 			for(var methodName:String in methods)
 			{
@@ -310,7 +310,7 @@ package org.apache.royale.test
 		private function collectTests(target:Object):Vector.<TestInfo>
 		{
 			var tests:Vector.<TestInfo> = new <TestInfo>[];
-			var reflection:Object = target["FLEXJS_REFLECTION_INFO"]();
+			var reflection:Object = target["ROYALE_REFLECTION_INFO"]();
 			var methods:Object = reflection.methods();
 			for(var methodName:String in methods)
 			{

-- 
To stop receiving notification emails like this one, please contact
['"commits@royale.apache.org" <commits@royale.apache.org>'].

Mime
View raw message