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