This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 7c13d44b6501147928095e638372961a2c923370 Author: Josh Tynjala <[email protected]> AuthorDate: Mon Dec 19 09:59:49 2022 -0800 RoyaleUnit: NaN assertions --- .../main/royale/org/apache/royale/test/Assert.as | 23 ++++ .../org/apache/royale/test/asserts/assertNaN.as | 30 +++++ .../royale/org/apache/royale/test/bdd/IExpect.as | 8 ++ .../royale/org/apache/royale/test/bdd/expect.as | 13 +++ .../src/test/royale/tests/AssertTests.as | 130 +++++++++++++++++++++ .../src/test/royale/tests/ExpectBDDTests.as | 61 ++++++++++ 6 files changed, 265 insertions(+) diff --git a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as index dd004fe173..1e71760497 100644 --- a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as +++ b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as @@ -129,6 +129,18 @@ package org.apache.royale.test failNull(actual, message); } + /** + * Asserts that the provided value is NaN (equivalent to testing the + * value in an <code>if(isNaN(value))</code> statement). + */ + public static function assertNaN(actual:Number, message:String = null):void + { + if (!isNaN(actual)) + { + failWithUserMessage("expected NaN but was <" + actual + ">", message); + } + } + /** * Fails. */ @@ -259,6 +271,17 @@ package org.apache.royale.test } } + /** + * Fails if the value is NaN. + */ + public static function failNaN(actual:Number, message:String = null):void + { + if (isNaN(actual)) + { + failWithUserMessage("expected not NaN: <" + actual + ">", message); + } + } + /** * @private */ diff --git a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertNaN.as b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertNaN.as new file mode 100644 index 0000000000..46bad43a27 --- /dev/null +++ b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertNaN.as @@ -0,0 +1,30 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.royale.test.asserts +{ + import org.apache.royale.test.Assert; + + /** + * Alias for org.apache.royale.test.Assert assertNaN method + */ + public function assertNaN(condition:*, message:String = null):void + { + Assert.assertNaN(condition, message); + } +} \ No newline at end of file diff --git a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as index 1691a4516e..76b338d507 100644 --- a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as +++ b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as @@ -76,6 +76,14 @@ package org.apache.royale.test.bdd */ function get false():IExpect; + /** + * Asserts that the provided value is NaN (equivalent to testing the + * value in an <code>if(isNaN(value))</code> statement). + * + * @see Assert#assertNaN + */ + function get NaN():IExpect; + /** * Asserts that the provided value is null (equivalent to testing the * value in an <code>if(value == null)</code> statement). diff --git a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as index 2752bda0c0..fd7ff805df 100644 --- a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as +++ b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as @@ -121,6 +121,19 @@ class Expect implements IExpect return this; } + public function get NaN():IExpect + { + if (_not) + { + Assert.failNaN(_value); + } + else + { + Assert.assertNaN(_value); + } + return this; + } + public function get to():IExpect { return this; diff --git a/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as b/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as index bb50747073..914d3cccf9 100644 --- a/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as +++ b/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as @@ -746,6 +746,71 @@ package tests Assert.assertStrictlyEquals({}, {}); } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testAssertNaNWith0():void + { + Assert.assertNaN(0); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testAssertNaNWith1():void + { + Assert.assertNaN(1); + } + + [Test] + public function testAssertNaNWithNaN():void + { + Assert.assertNaN(NaN); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testAssertNaNWithNull():void + { + Assert.assertNaN(null); + } + + [Test] + public function testAssertNaNWithObject():void + { + var value:* = {}; + Assert.assertNaN(value); + } + + [Test] + public function testAssertNaNWithUndefined():void + { + Assert.assertNaN(undefined); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testAssertNaNWithTrue():void + { + var value:* = true; + Assert.assertNaN(value); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testAssertNaNWithFalse():void + { + var value:* = false; + Assert.assertNaN(value); + } + + [Test] + public function testAssertNaNWithString():void + { + var value:* = "royale"; + Assert.assertNaN(value); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testAssertNaNWithEmptyString():void + { + var value:* = ""; + Assert.assertNaN(value); + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testFail():void { @@ -991,5 +1056,70 @@ package tests { Assert.failNotNull(""); } + + [Test] + public function testFailNaNWith0():void + { + Assert.failNaN(0); + } + + [Test] + public function testFailNaNWith1():void + { + Assert.failNaN(1); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testFailNaNWithNaN():void + { + Assert.failNaN(NaN); + } + + [Test] + public function testFailNaNWithNull():void + { + Assert.failNaN(null); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testFailNaNWithObject():void + { + var value:* = {}; + Assert.failNaN(value); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testFailNaNWithUndefined():void + { + Assert.failNaN(undefined); + } + + [Test] + public function testFailNaNWithTrue():void + { + var value:* = true; + Assert.failNaN(value); + } + + [Test] + public function testFailNaNWithFalse():void + { + var value:* = false; + Assert.failNaN(value); + } + + [Test(expected="org.apache.royale.test.AssertionError")] + public function testFailNaNWithString():void + { + var value:* = "royale"; + Assert.failNaN(value); + } + + [Test] + public function testFailNaNWithEmptyString():void + { + var value:* = ""; + Assert.failNaN(value); + } } } \ No newline at end of file diff --git a/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as b/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as index 5845bd66f5..c4c9bf99e7 100644 --- a/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as +++ b/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as @@ -40,6 +40,12 @@ package tests expect(true).is.null; } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testExpectTrueWithNaNGetter():void + { + expect(true).is.NaN; + } + [Test] public function testExpectTrueWithEqualsTrue():void { @@ -196,6 +202,12 @@ package tests expect(false).is.null; } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testExpectFalseWithNaNGetter():void + { + expect(false).is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectFalseWithEqualsTrue():void { @@ -352,6 +364,12 @@ package tests expect(null).is.null; } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testExpectNullWithNaNGetter():void + { + expect(null).is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectNullWithEqualsTrue():void { @@ -508,6 +526,12 @@ package tests expect(undefined).is.null; } + [Test] + public function testExpectUndefinedWithNaNGetter():void + { + expect(undefined).is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectUndefinedWithEqualsTrue():void { @@ -664,6 +688,12 @@ package tests expect(0).is.null; } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testExpect0WithNaNGetter():void + { + expect(0).is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpect0WithEqualsTrue():void { @@ -820,6 +850,12 @@ package tests expect(1).is.null; } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testExpect1WithNaNGetter():void + { + expect(1).is.NaN; + } + [Test] public function testExpect1WithEqualsTrue():void { @@ -976,6 +1012,12 @@ package tests expect(NaN).is.null; } + [Test] + public function testExpectNaNWithNaNGetter():void + { + expect(NaN).is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectNaNWithEqualsTrue():void { @@ -1132,6 +1174,13 @@ package tests expect("royale").is.null; } + [Test] + + public function testExpectStringWithNaNGetter():void + { + expect("royale").is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectStringWithEqualsTrue():void { @@ -1288,6 +1337,12 @@ package tests expect("").is.null; } + [Test(expected="org.apache.royale.test.AssertionError")] + public function testExpectEmptyStringWithNaNGetter():void + { + expect("").is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectEmptyStringWithEqualsTrue():void { @@ -1444,6 +1499,12 @@ package tests expect({}).is.null; } + [Test] + public function testExpectObjectWithNaNGetter():void + { + expect({}).is.NaN; + } + [Test(expected="org.apache.royale.test.AssertionError")] public function testExpectObjectWithEqualsTrue():void {
