Skip to content

Commit

Permalink
Fix failing decimal128 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Sep 15, 2020
1 parent d25427c commit 3fd7b18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions Realm/RLMDecimal128.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@ - (instancetype)initWithNumber:(NSNumber *)number {

- (instancetype)initWithString:(NSString *)string error:(NSError **)error {
if ((self = [self init])) {
const char *str = string.UTF8String;
if (!realm::Decimal128::is_valid_str(str)) {
try {
_value = realm::Decimal128(string.UTF8String);
}
catch (std::exception const& e) {
if (error) {
NSString *msg = [NSString stringWithFormat:@"String '%@' is not a valid Decimal128", string];
*error = [NSError errorWithDomain:RLMErrorDomain
code:RLMErrorInvalidInput
userInfo:@{NSLocalizedDescriptionKey: msg}];
*error = RLMMakeError(RLMErrorInvalidInput, e);
}
return nil;
}
_value = realm::Decimal128(str);
}
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion Realm/Tests/Decimal128Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)testDecimal128Initialization {
RLMDecimal128 *d1 = [[RLMDecimal128 alloc] initWithNumber:@3.14159];
RLMDecimal128 *d2 = [[RLMDecimal128 alloc] initWithString:@"3.14159" error:nil];
NSError *error;
RLMDecimal128 *d3 = [[RLMDecimal128 alloc] initWithString:@"not a number" error:&error];
RLMDecimal128 *d3 = [[RLMDecimal128 alloc] initWithString:@"123456789123456789123.0" error:&error];
XCTAssertNotNil(error);
RLMDecimal128 *d4 = [[RLMDecimal128 alloc] initWithValue:@3.14159];
RLMDecimal128 *d5 = [[RLMDecimal128 alloc] initWithValue:@"123.456"];
Expand Down

0 comments on commit 3fd7b18

Please sign in to comment.