Skip to content

Commit

Permalink
enable '.003' or '-.003' style number in CPDecimalMakeWithString func…
Browse files Browse the repository at this point in the history
…tion and add new test cases
  • Loading branch information
Eric Wong committed Aug 4, 2012
1 parent 729d249 commit 9f1a8fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Foundation/CPDecimal.j
Expand Up @@ -115,7 +115,8 @@ function CPDecimalMakeWithString(string, locale)

// Note: this doesn't accept .01 for example, should it?
// If yes simply add '?' after integer part group, i.e. ([+\-]?)((?:0|[1-9]\d*)?)
var matches = string.match(/^([+\-]?)((?:0|[1-9]\d*))(?:\.(\d*))?(?:[eE]([+\-]?)(\d+))?$/);
// Note: now it accept .01 style.
var matches = string.match(/^([+\-]?)((?:0|[1-9]\d*)?)(?:\.(\d*))?(?:[eE]([+\-]?)(\d+))?$/);
if (!matches)
return CPDecimalMakeNaN();

Expand Down
4 changes: 4 additions & 0 deletions Tests/Foundation/CPDecimalNumberTest.j
Expand Up @@ -522,6 +522,10 @@
[self assert:"123456789123456789123456789000000000000000" equals:[dcmn stringValue] message:"stringValue: - large number"];
dcmn = [CPDecimalNumber decimalNumberWithString:@"82346.2341144"];
[self assert:"82346.2341144" equals:[dcmn descriptionWithLocale:nil] message:"descriptionWithLocale: - large number"];
dcmn = [CPDecimalNumber decimalNumberWithString:@".125"];
[self assert:"0.125" equals:[dcmn descriptionWithLocale:nil] message:"stringValue: - no integral part number"];
dcmn = [CPDecimalNumber decimalNumberWithString:@"-.003"];
[self assert:"-0.003" equals:[dcmn descriptionWithLocale:nil] message:"stringValue: - no integral part negative number"];
}

- (void)testEncoding
Expand Down

0 comments on commit 9f1a8fa

Please sign in to comment.