Merge pull request #2429 from mrcarlberg/integer_value

Fixed: Added ’integerValue’ method for CPNumber and CPString.
This commit is contained in:
Alexandre Wilhelm
2016-03-27 09:20:12 -07:00
4 changed files with 63 additions and 0 deletions
+17
View File
@@ -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,15 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
- (int)integerValue
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
@@ -260,6 +271,7 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
@@ -267,6 +279,7 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
@@ -274,6 +287,7 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
@@ -291,6 +305,7 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
/*
@@ -304,6 +319,7 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
@@ -311,6 +327,7 @@ FIXME: Do we need this?
{
if (typeof self == "boolean")
return self ? 1 : 0;
return self;
}
+8
View File
@@ -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 '/'
+19
View File
@@ -12,4 +12,23 @@
[self assertThrows:function () { [34 compare:[CPNull null]] }];
}
- (void)testintValue
{
var testStrings = [
// [090, 90], // Removed cause Rhino does not support numbers starting with '0'
[-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
+19
View File
@@ -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 = [