Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
[RMDescription] Cast NSInteger/NSUInteger to long long for formatted …
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
calimarkus committed Feb 6, 2018
1 parent 25d04d6 commit c1e9323
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion features/algebraic-type-forward-declaration.feature
Expand Up @@ -104,7 +104,7 @@ Feature: Outputting forward declarations in Algebraic Types
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSomeRandomSubtype: {
Expand Down
2 changes: 1 addition & 1 deletion features/algebraic-types-coding.feature
Expand Up @@ -113,7 +113,7 @@ Feature: Outputting Algebraic Types
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSecondSubtype: {
Expand Down
2 changes: 1 addition & 1 deletion features/algebraic-types-cplusplus.feature
Expand Up @@ -100,7 +100,7 @@ Feature: Outputting ObjC++ Algebraic Types
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSomeRandomSubtype: {
Expand Down
8 changes: 4 additions & 4 deletions features/algebraic-types.feature
Expand Up @@ -136,15 +136,15 @@ Feature: Outputting Algebraic Types
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSomeRandomSubtype: {
return [NSString stringWithFormat:@"%@ - SomeRandomSubtype \n", [super description]];
break;
}
case _SimpleADTSubtypesSomeAttributeSubtype: {
return [NSString stringWithFormat:@"%@ - \n\t someAttributeSubtype: %tu; \n", [super description], _someAttributeSubtype];
return [NSString stringWithFormat:@"%@ - \n\t someAttributeSubtype: %llu; \n", [super description], (unsigned long long)_someAttributeSubtype];
break;
}
case _SimpleADTSubtypesSecondSubtype: {
Expand Down Expand Up @@ -317,7 +317,7 @@ Feature: Outputting Algebraic Types
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSecondSubtype: {
Expand Down Expand Up @@ -488,7 +488,7 @@ Feature: Outputting Algebraic Types
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSomeRandomSubtype: {
Expand Down
2 changes: 1 addition & 1 deletion features/coding.feature
Expand Up @@ -70,7 +70,7 @@ Feature: Outputting Value Objects With Coded Values
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t numberOfRatings: %tu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _numberOfRatings];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t numberOfRatings: %llu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, (unsigned long long)_numberOfRatings];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
Expand Down
2 changes: 1 addition & 1 deletion features/configuration.feature
Expand Up @@ -136,7 +136,7 @@ Feature: Outputting Value Objects With A Custom Plugin
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t numberOfRatings: %tu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _numberOfRatings];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t numberOfRatings: %llu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, (unsigned long long)_numberOfRatings];
}
@end
Expand Down
2 changes: 1 addition & 1 deletion features/cplusplus.feature
Expand Up @@ -73,7 +73,7 @@ Feature: Outputting C++ Value Objects
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t numberOfRatings: %tu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _numberOfRatings];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t numberOfRatings: %llu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, (unsigned long long)_numberOfRatings];
}
- (NSUInteger)hash
Expand Down
4 changes: 2 additions & 2 deletions features/forward-declaration.feature
Expand Up @@ -100,7 +100,7 @@ Feature: Outputting Value Objects With Forward Declarations
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t numberOfRatings: %tu; \n\t proxy: %@; \n\t followers: %@; \n\t helloObj: %@; \n\t worldVc: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _numberOfRatings, _proxy, _followers, _helloObj, _worldVc];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t numberOfRatings: %llu; \n\t proxy: %@; \n\t followers: %@; \n\t helloObj: %@; \n\t worldVc: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, (unsigned long long)_numberOfRatings, _proxy, _followers, _helloObj, _worldVc];
}
- (NSUInteger)hash
Expand Down Expand Up @@ -230,7 +230,7 @@ Feature: Outputting Value Objects With Forward Declarations
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t countIconHeight: %f; \n\t countIconWidth: %f; \n\t numberOfRatings: %tu; \n\t foo: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _countIconHeight, _countIconWidth, _numberOfRatings, _foo];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t countIconHeight: %f; \n\t countIconWidth: %f; \n\t numberOfRatings: %llu; \n\t foo: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, _countIconHeight, _countIconWidth, (unsigned long long)_numberOfRatings, _foo];
}
@end
Expand Down
2 changes: 1 addition & 1 deletion features/nullability.feature
Expand Up @@ -219,7 +219,7 @@ Feature: Outputting Objects With Nullability Annotations
{
switch (_subtype) {
case _SimpleADTSubtypesFirstSubtype: {
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %tu; \n", [super description], _firstSubtype_firstValue, _firstSubtype_secondValue];
return [NSString stringWithFormat:@"%@ - FirstSubtype \n\t firstValue: %@; \n\t secondValue: %llu; \n", [super description], _firstSubtype_firstValue, (unsigned long long)_firstSubtype_secondValue];
break;
}
case _SimpleADTSubtypesSomeRandomSubtype: {
Expand Down
4 changes: 2 additions & 2 deletions features/object.feature
Expand Up @@ -80,7 +80,7 @@ Feature: Outputting Objects
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t numberOfRatings: %u; \n\t someType: %@; \n\t someClass: %@; \n\t someBlock: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _numberOfRatings, _someType, _someClass, _someBlock];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t numberOfRatings: %u; \n\t someType: %@; \n\t someClass: %@; \n\t someBlock: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, _numberOfRatings, _someType, _someClass, _someBlock];
}
@end
Expand Down Expand Up @@ -161,7 +161,7 @@ Feature: Outputting Objects
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t countIconHeight: %f; \n\t countIconWidth: %f; \n\t numberOfRatings: %tu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _countIconHeight, _countIconWidth, _numberOfRatings];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t countIconHeight: %f; \n\t countIconWidth: %f; \n\t numberOfRatings: %llu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, _countIconHeight, _countIconWidth, (unsigned long long)_numberOfRatings];
}
@end
Expand Down
4 changes: 2 additions & 2 deletions features/value_object.feature
Expand Up @@ -85,7 +85,7 @@ Feature: Outputting Value Objects
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t numberOfRatings: %u; \n\t someType: %@; \n\t someClass: %@; \n\t someBlock: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _numberOfRatings, _someType, _someClass, _someBlock];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t numberOfRatings: %u; \n\t someType: %@; \n\t someClass: %@; \n\t someBlock: %@; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, _numberOfRatings, _someType, _someClass, _someBlock];
}
- (NSUInteger)hash
Expand Down Expand Up @@ -208,7 +208,7 @@ Feature: Outputting Value Objects
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %zd; \n\t countIconHeight: %f; \n\t countIconWidth: %f; \n\t numberOfRatings: %tu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, _likeCount, _countIconHeight, _countIconWidth, _numberOfRatings];
return [NSString stringWithFormat:@"%@ - \n\t doesUserLike: %@; \n\t identifier: %@; \n\t likeCount: %lld; \n\t countIconHeight: %f; \n\t countIconWidth: %f; \n\t numberOfRatings: %llu; \n", [super description], _doesUserLike ? @"YES" : @"NO", _identifier, (long long)_likeCount, _countIconHeight, _countIconWidth, (unsigned long long)_numberOfRatings];
}
@end
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/plugins/description-test.ts
Expand Up @@ -412,7 +412,7 @@ describe('ObjectSpecPlugins.Description', function() {
{
belongsToProtocol:Maybe.Just('NSObject'),
code: [
'return [NSString stringWithFormat:@"%@ - \\n\\t age: %zd; \\n", [super description], _age];'
'return [NSString stringWithFormat:@"%@ - \\n\\t age: %lld; \\n", [super description], (long long)_age];'
],
comments: [],
compilerAttributes:[],
Expand Down Expand Up @@ -465,7 +465,7 @@ describe('ObjectSpecPlugins.Description', function() {
{
belongsToProtocol:Maybe.Just('NSObject'),
code: [
'return [NSString stringWithFormat:@"%@ - \\n\\t age: %tu; \\n", [super description], _age];'
'return [NSString stringWithFormat:@"%@ - \\n\\t age: %llu; \\n", [super description], (unsigned long long)_age];'
],
comments: [],
compilerAttributes:[],
Expand Down Expand Up @@ -943,7 +943,7 @@ describe('ObjectSpecPlugins.Description', function() {
{
belongsToProtocol:Maybe.Just('NSObject'),
code: [
'return [NSString stringWithFormat:@"%@ - \\n\\t age: %tu; \\n", [super description], _age];'
'return [NSString stringWithFormat:@"%@ - \\n\\t age: %llu; \\n", [super description], (unsigned long long)_age];'
],
comments: [],
compilerAttributes:[],
Expand Down Expand Up @@ -1429,7 +1429,7 @@ describe('AlgebraicTypePlugins.Description', function() {
code: [
'switch (_subtype) {',
' case _TestSubtypesSomeSubtype: {',
' return [NSString stringWithFormat:@"%@ - SomeSubtype \\n\\t someString: %@; \\n\\t someUnsignedInteger: %tu; \\n", [super description], _someSubtype_someString, _someSubtype_someUnsignedInteger];',
' return [NSString stringWithFormat:@"%@ - SomeSubtype \\n\\t someString: %@; \\n\\t someUnsignedInteger: %llu; \\n", [super description], _someSubtype_someString, (unsigned long long)_someSubtype_someUnsignedInteger];',
' break;',
' }',
' case _TestSubtypesCoolSingleAttributeBoolSubtype: {',
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/description.ts
Expand Up @@ -34,6 +34,12 @@ function useValueAccessor(valueAccessor:string):string {
return valueAccessor;
}

function castValueAccessorValue(castToApply: string):(valueAccessor:string) => string {
return function(valueAccessor:string):string {
return '(' + castToApply + ')' + valueAccessor;
};
}

function useFunctionReturnValueAsDescriptionValue(functionToCall:string):(valueAccessor:string) => string {
return function(valueAccessor:string):string {
return functionToCall + '(' + valueAccessor + ')';
Expand Down Expand Up @@ -72,15 +78,15 @@ function attributeDescriptionForType(type:ObjC.Type):AttributeDescription {
NSInteger: function() {
return {
descriptionFunctionImport: Maybe.Nothing<ObjC.Import>(),
token: '%zd',
valueGenerator: useValueAccessor
token: '%lld',
valueGenerator: castValueAccessorValue('long long')
};
},
NSUInteger: function() {
return {
descriptionFunctionImport: Maybe.Nothing<ObjC.Import>(),
token: '%tu',
valueGenerator: useValueAccessor
token: '%llu',
valueGenerator: castValueAccessorValue('unsigned long long')
};
},
double: function() {
Expand Down

0 comments on commit c1e9323

Please sign in to comment.