From 7780a98abe26f2858198127cb4c24f11effd0336 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 15 Mar 2016 22:25:10 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Fixed:=20Added=20=E2=80=99integerValue?= =?UTF-8?q?=E2=80=99=20method=20for=20CPNumber=20and=20CPString.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the classes more compliant to Cocoa --- Foundation/CPNumber.j | 7 +++++++ Foundation/CPString.j | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/Foundation/CPNumber.j b/Foundation/CPNumber.j index 33bcb73ac..e03a721a8 100644 --- a/Foundation/CPNumber.j +++ b/Foundation/CPNumber.j @@ -256,6 +256,13 @@ FIXME: Do we need this? return self; } +- (int)integerValue +{ + if (typeof self == "boolean") + return self ? 1 : 0; + return self; +} + - (long long)longLongValue { if (typeof self == "boolean") diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 69e9caf8a..d87c4efd8 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -731,6 +731,14 @@ var CPStringNull = [CPNull null]; return parseInt(self, 10); } +/*! + Returns the text as an integer +*/ +- (int)integerValue +{ + return parseInt(self, 10); +} + /*! Returns an the path components of this string. This method assumes that the string's content is a '/' From 111b12161ca197f14efe3a38c600a846cbba2b56 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 23 Mar 2016 09:02:09 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Added:=20test=20cases=20for=20=E2=80=99intV?= =?UTF-8?q?alue=E2=80=99=20and=20=E2=80=99integerValue=E2=80=99=20methods?= =?UTF-8?q?=20on=20CPString=20and=20CPNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tests/Foundation/CPNumberTest.j | 19 +++++++++++++++++++ Tests/Foundation/CPStringTest.j | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Tests/Foundation/CPNumberTest.j b/Tests/Foundation/CPNumberTest.j index 5939a2bc8..16dce718c 100644 --- a/Tests/Foundation/CPNumberTest.j +++ b/Tests/Foundation/CPNumberTest.j @@ -12,4 +12,23 @@ [self assertThrows:function () { [34 compare:[CPNull null]] }]; } +- (void)testintValue +{ + var testStrings = [ + [090, 90], + [-1, -1], + [3.1415, 3], + [2.7183, 2], + [-0, 0], + [00, 0], + [-00, 0], + [+001, 1], + ]; + + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] intValue] equals:testStrings[i][1]]; + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] integerValue] equals:testStrings[i][1]]; +} + @end diff --git a/Tests/Foundation/CPStringTest.j b/Tests/Foundation/CPStringTest.j index 326c781db..5443003c0 100644 --- a/Tests/Foundation/CPStringTest.j +++ b/Tests/Foundation/CPStringTest.j @@ -165,6 +165,25 @@ [self assert:[testStrings[i][0] boolValue] equals:testStrings[i][1]]; } +- (void)testintValue +{ + var testStrings = [ + [" 090", 90], + [" -1", -1], + [" 3.1415", 3], + [" 2.7183", 2], + [" -0", 0], + [" 00", 0], + [" -00", 0], + [" +001", 1], + ]; + + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] intValue] equals:testStrings[i][1]]; + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] integerValue] equals:testStrings[i][1]]; +} + - (void)testCommonPrefixWithString { var testStringsCase = [ From c1ec27045c79a9f4cae26274947e02a0d4cc2fbf Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 23 Mar 2016 09:35:19 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Fixed:=20Rhino=20does=20not=20support=20num?= =?UTF-8?q?bers=20starting=20with=20=E2=80=990=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tests/Foundation/CPNumberTest.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Foundation/CPNumberTest.j b/Tests/Foundation/CPNumberTest.j index 16dce718c..4047ea5f4 100644 --- a/Tests/Foundation/CPNumberTest.j +++ b/Tests/Foundation/CPNumberTest.j @@ -15,7 +15,7 @@ - (void)testintValue { var testStrings = [ - [090, 90], +// [090, 90], // Removed cause Rhino does not support numbers starting with '0' [-1, -1], [3.1415, 3], [2.7183, 2], From b208571ed731f575a16a45fb4fe09e7352fdfe3d Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 23 Mar 2016 10:17:15 +0100 Subject: [PATCH 4/4] Fixed: Formatting --- Foundation/CPNumber.j | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Foundation/CPNumber.j b/Foundation/CPNumber.j index e03a721a8..52519091b 100644 --- a/Foundation/CPNumber.j +++ b/Foundation/CPNumber.j @@ -239,6 +239,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -246,6 +247,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -253,6 +255,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -260,6 +263,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -267,6 +271,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -274,6 +279,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -281,6 +287,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -298,6 +305,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } /* @@ -311,6 +319,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; } @@ -318,6 +327,7 @@ FIXME: Do we need this? { if (typeof self == "boolean") return self ? 1 : 0; + return self; }