mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-30 20:07:36 +00:00
Fixed: CPNumberFormatter minimum and maximum wrong encoding when set to nil
Previously, a decoded CPNumberFormatter was converting the minimum and maximum values to 0 if they were set to nil. This was causing unexpected behavior when creating a CPNumberFormatter from a xib. This patch actually decodes _minimum and _maximum values as objects to preserve nil. Test added in Foundation/CPNumberFormatter.j
This commit is contained in:
1 parent
2f18218ce5
commit
f75955bb04
2 files changed
+35
-2
No files matched your search
@@ -309,13 +309,16 @@ var CPNumberFormatterStyleKey = @"CPNumberFormatterStyleKey",
|
||||
_numberStyle = [aCoder decodeIntForKey:CPNumberFormatterStyleKey];
|
||||
_minimumFractionDigits = [aCoder decodeIntForKey:CPNumberFormatterMinimumFractionDigitsKey];
|
||||
_maximumFractionDigits = [aCoder decodeIntForKey:CPNumberFormatterMaximumFractionDigitsKey];
|
||||
_minimum = [aCoder decodeIntForKey:CPNumberFormatterMinimumKey];
|
||||
_maximum = [aCoder decodeIntForKey:CPNumberFormatterMaximumKey];
|
||||
_roundingMode = [aCoder decodeIntForKey:CPNumberFormatterRoundingModeKey];
|
||||
_groupingSeparator = [aCoder decodeObjectForKey:CPNumberFormatterGroupingSeparatorKey];
|
||||
_currencyCode = [aCoder decodeObjectForKey:CPNumberFormatterCurrencyCodeKey];
|
||||
_currencySymbol = [aCoder decodeObjectForKey:CPNumberFormatterCurrencySymbolKey];
|
||||
_generatesDecimalNumbers = [aCoder decodeBoolForKey:CPNumberFormatterGeneratesDecimalNumbers];
|
||||
|
||||
// We decode _minimum and _maximum as object here because otherwise, nil values are not preserved
|
||||
// causing a min and max always set to 0 after an decoding.
|
||||
_minimum = [aCoder decodeObjectForKey:CPNumberFormatterMinimumKey];
|
||||
_maximum = [aCoder decodeObjectForKey:CPNumberFormatterMaximumKey];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
@@ -251,4 +251,34 @@
|
||||
[self assert:1.23456 equals:generated];
|
||||
}
|
||||
|
||||
- (void)testEncodingDecodingWithZeroMinMaxValues
|
||||
{
|
||||
var numberFormatter = [CPNumberFormatter new];
|
||||
|
||||
[numberFormatter setMaximum:0];
|
||||
[numberFormatter setMinimum:0];
|
||||
|
||||
var encoded = [CPKeyedArchiver archivedDataWithRootObject:numberFormatter],
|
||||
decoded = [CPKeyedUnarchiver unarchiveObjectWithData:encoded];
|
||||
|
||||
[self assertNotNull:[decoded minimum]];
|
||||
[self assertNotNull:[decoded maximum]];
|
||||
[self assert:0 equals:[decoded minimum]];
|
||||
[self assert:0 equals:[decoded maximum]];
|
||||
}
|
||||
|
||||
- (void)testEncodingDecodingWithNilMinMaxValues
|
||||
{
|
||||
var numberFormatter = [CPNumberFormatter new];
|
||||
|
||||
[numberFormatter setMaximum:nil];
|
||||
[numberFormatter setMinimum:nil];
|
||||
|
||||
var encoded = [CPKeyedArchiver archivedDataWithRootObject:numberFormatter],
|
||||
decoded = [CPKeyedUnarchiver unarchiveObjectWithData:encoded];
|
||||
|
||||
[self assertNull:[decoded minimum]];
|
||||
[self assertNull:[decoded maximum]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user