YYTestDescription.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // YYTestDescription.m
  3. // YYModel <https://github.com/ibireme/YYModel>
  4. //
  5. // Created by ibireme on 16/1/3.
  6. // Copyright (c) 2016 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <XCTest/XCTest.h>
  12. #import "YYModel.h"
  13. typedef struct my_struct {
  14. int a;
  15. double b;
  16. long double c;
  17. } my_struct;
  18. typedef struct my_union {
  19. int a;
  20. double b;
  21. long double c;
  22. } my_union;
  23. @interface YYTestDescriptionModel : NSObject
  24. @property bool boolValue;
  25. @property BOOL BOOLValue;
  26. @property char charValue;
  27. @property unsigned char unsignedCharValue;
  28. @property short shortValue;
  29. @property unsigned short unsignedShortValue;
  30. @property int intValue;
  31. @property unsigned int unsignedIntValue;
  32. @property long longValue;
  33. @property unsigned long unsignedLongValue;
  34. @property long long longLongValue;
  35. @property unsigned long long unsignedLongLongValue;
  36. @property float floatValue;
  37. @property double doubleValue;
  38. @property long double longDoubleValue;
  39. @property (strong) Class classValue;
  40. @property SEL selectorValue;
  41. @property (copy) void (^blockValue)();
  42. @property void *pointerValue;
  43. @property char *cString;
  44. @property CFArrayRef cfArrayValue;
  45. @property NSValue *valueValue;
  46. @property CGSize sizeValue;
  47. @property CGPoint pointValue;
  48. @property CGRect rectValue;
  49. @property CGAffineTransform transformValue;
  50. @property UIEdgeInsets insetsValue;
  51. @property UIOffset offsetValue;
  52. @property my_struct myStructValue; // invalid for NSKeyedArchiver/Unarchiver
  53. @property my_union myUnionValue; // invalid for NSKeyedArchiver/Unarchiver
  54. @property (nonatomic, strong) NSObject *object;
  55. @property (nonatomic, strong) NSNumber *number;
  56. @property (nonatomic, strong) NSDecimalNumber *decimal;
  57. @property (nonatomic, strong) NSString *string;
  58. @property (nonatomic, strong) NSString *string2;
  59. @property (nonatomic, strong) NSMutableString *mString;
  60. @property (nonatomic, strong) NSData *data;
  61. @property (nonatomic, strong) NSMutableData *mData;
  62. @property (nonatomic, strong) NSDate *date;
  63. @property (nonatomic, strong) NSValue *value;
  64. @property (nonatomic, strong) NSURL *url;
  65. @property (nonatomic, strong) NSArray *array;
  66. @property (nonatomic, strong) NSMutableArray *mArray;
  67. @property (nonatomic, strong) NSDictionary *dict;
  68. @property (nonatomic, strong) NSMutableDictionary *mDict;
  69. @property (nonatomic, strong) NSSet *set;
  70. @property (nonatomic, strong) NSMutableSet *mSet;
  71. @end
  72. @implementation YYTestDescriptionModel
  73. - (NSString *)description {
  74. return [self yy_modelDescription];
  75. }
  76. @end
  77. @interface YYTestDescription : XCTestCase
  78. @end
  79. @implementation YYTestDescription
  80. - (void)testDescription {
  81. YYTestDescriptionModel *model = [YYTestDescriptionModel new];
  82. model.string = @"test";
  83. model.intValue = 100;
  84. model.number = @(123);
  85. model.decimal = [NSDecimalNumber decimalNumberWithString:@"456"];
  86. model.value = [NSValue valueWithRange:NSMakeRange(10, 5)];
  87. model.date = [NSDate new];
  88. model.blockValue = ^{};
  89. model.mData = [NSMutableData data];
  90. for (int i = 0; i < 1024; i++) {
  91. [model.mData appendBytes:&i length:sizeof(int)];
  92. }
  93. model.array = @[];
  94. model.dict = @{};
  95. model.set = [NSSet new];
  96. model.mArray = [NSMutableArray new];
  97. model.mDict = [NSMutableDictionary new];
  98. model.mSet = [NSMutableSet new];
  99. for (int i = 0; i < 2; i++) {
  100. YYTestDescriptionModel *sub = [YYTestDescriptionModel new];
  101. sub.intValue = i;
  102. [model.mArray addObject:sub];
  103. model.mDict[@(i).description] = sub;
  104. [model.mSet addObject:sub];
  105. }
  106. NSLog(@"%@",model.description);
  107. }
  108. @end