]>
Commit | Line | Data |
---|---|---|
13ba007e A |
1 | // TEST_CFLAGS -framework Foundation |
2 | ||
3 | #import <Foundation/Foundation.h> | |
4 | #import <Foundation/NSDictionary.h> | |
5 | #import <objc/runtime.h> | |
6 | #import <objc/objc-abi.h> | |
7 | #import <math.h> | |
8 | #include "test.h" | |
9 | ||
10 | int main() { | |
11 | PUSH_POOL { | |
12 | ||
13 | #if __has_feature(objc_bool) // placeholder until we get a more precise macro. | |
14 | NSArray *array = @[ @1, @2, @YES, @NO, @"Hello", @"World" ]; | |
15 | testassert([array count] == 6); | |
16 | NSDictionary *dict = @{ @"Name" : @"John Q. Public", @"Age" : @42 }; | |
17 | testassert([dict count] == 2); | |
18 | NSDictionary *numbers = @{ @"π" : @M_PI, @"e" : @M_E }; | |
19 | testassert([[numbers objectForKey:@"π"] doubleValue] == M_PI); | |
20 | testassert([[numbers objectForKey:@"e"] doubleValue] == M_E); | |
21 | ||
22 | BOOL yesBool = YES; | |
23 | BOOL noBool = NO; | |
24 | array = @[ | |
25 | @(true), | |
26 | @(YES), | |
27 | [NSNumber numberWithBool:YES], | |
28 | @YES, | |
29 | @(yesBool), | |
30 | @((BOOL)YES), | |
31 | ||
32 | @(false), | |
33 | @(NO), | |
34 | [NSNumber numberWithBool:NO], | |
35 | @NO, | |
36 | @(noBool), | |
37 | @((BOOL)NO), | |
38 | ]; | |
39 | NSData * jsonData = [NSJSONSerialization dataWithJSONObject:array options:0 error:nil]; | |
40 | NSString * string = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
41 | #if __cplusplus | |
42 | testassert([string isEqualToString:@"[true,true,true,true,true,true,false,false,false,false,false,false]"]); | |
43 | #else | |
44 | // C99 @(true) and @(false) evaluate to @(1) and @(0). | |
45 | testassert([string isEqualToString:@"[1,true,true,true,true,true,0,false,false,false,false,false]"]); | |
46 | #endif | |
47 | ||
48 | #endif | |
49 | ||
50 | } POP_POOL; | |
51 | ||
52 | succeed(__FILE__); | |
53 | ||
54 | return 0; | |
55 | } |