Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 154 lines (126 sloc) 4.829 kB
db25b3f @gabriel Rewritten; Updated to support 1.0.5
authored
1 //
2 // YAJLParserTest.m
3 // YAJL
4 //
5 // Created by Gabriel Handford on 6/14/09.
6 // Copyright 2009. All rights reserved.
7 //
8
c4bef1a @gabriel New release 0.2.4; Updating API for streaming; More tests
authored
9 @interface YAJLParserTest : YAJLTestCase {}
db25b3f @gabriel Rewritten; Updated to support 1.0.5
authored
10 @end
11
12 @implementation YAJLParserTest
13
78fb38f @gabriel Tabs to spaces:
authored
14 - (void)test {
15 YAJLParser *parser = [[YAJLParser alloc] init];
16 [parser parse:[self loadData:@"example"]];
17
18 NSError *error = [parser parserError];
19 if (error) {
20 NSLog(@"Parse error:\n%@", error);
21 GHFail(@"Error: %@", error);
22 }
23
24 [parser release];
db25b3f @gabriel Rewritten; Updated to support 1.0.5
authored
25 }
26
553fc18 @gabriel New release 0.2.2 (fixes parserError bug)
authored
27 - (void)testError {
78fb38f @gabriel Tabs to spaces:
authored
28 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
29 YAJLParserStatus status = [parser parse:[self loadData:@"error"]];
30 GHAssertTrue(status == YAJLParserStatusError, @"Should have error status");
31
32 NSError *error = [parser parserError];
33 if (error) {
34 GHTestLog(@"Parse error:\n%@", error);
35 } else {
36 GHFail(@"Should have error");
37 }
38
39 [parser release];
553fc18 @gabriel New release 0.2.2 (fixes parserError bug)
authored
40 }
db25b3f @gabriel Rewritten; Updated to support 1.0.5
authored
41
c60473c @gabriel Enabling verbose error messages
authored
42 - (void)testError2 {
43 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
78fb38f @gabriel Tabs to spaces:
authored
44 YAJLParserStatus status = [parser parse:[self loadData:@"error2"]];
45 GHAssertTrue(status == YAJLParserStatusError, @"Should have error status");
46
47 NSError *error = [parser parserError];
48 if (error) {
49 GHTestLog(@"Parse error:\n%@", error);
c60473c @gabriel Enabling verbose error messages
authored
50 GHAssertTrue([[error localizedDescription] hasPrefix:@"parse error: invalid object key (must be a string)\n"], nil);
78fb38f @gabriel Tabs to spaces:
authored
51 } else {
52 GHFail(@"Should have error");
53 }
54
55 [parser release];
c60473c @gabriel Enabling verbose error messages
authored
56 }
57
553fc18 @gabriel New release 0.2.2 (fixes parserError bug)
authored
58 - (void)testComments {
78fb38f @gabriel Tabs to spaces:
authored
59 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsAllowComments];
60 YAJLParserStatus status = [parser parse:[self loadData:@"comments"]];
61 GHAssertTrue(status == YAJLParserStatusOK, @"Should have OK status");
62
63 NSError *error = [parser parserError];
64 if (error) {
65 GHTestLog(@"Parse error:\n%@", error);
66 GHFail(@"Error: %@", error);
67 }
68
69 [parser release];
553fc18 @gabriel New release 0.2.2 (fixes parserError bug)
authored
70 }
db25b3f @gabriel Rewritten; Updated to support 1.0.5
authored
71
553fc18 @gabriel New release 0.2.2 (fixes parserError bug)
authored
72 - (void)testFailOnComments {
78fb38f @gabriel Tabs to spaces:
authored
73 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
74 YAJLParserStatus status = [parser parse:[self loadData:@"comments"]];
75 GHAssertTrue(status == YAJLParserStatusError, @"Should have error status");
76
77 NSError *error = [parser parserError];
78 if (error) {
79 GHTestLog(@"Parse error:\n%@", error);
80 } else {
81 GHFail(@"Should have error");
82 }
83
84 [parser release];
c4bef1a @gabriel New release 0.2.4; Updating API for streaming; More tests
authored
85 }
86
40a059a @gabriel Testing for overflow
authored
87 - (void)testDoubleOverflow {
78fb38f @gabriel Tabs to spaces:
authored
88 YAJLParser *parser = [[YAJLParser alloc] init];
89 YAJLParserStatus status = [parser parse:[self loadData:@"overflow"]];
90 GHAssertEquals(status, (NSUInteger)YAJLParserStatusError, @"Should have error status");
91
92 NSError *error = [parser parserError];
93 if (error) {
94 GHTestLog(@"Parse error:\n%@", error);
40a059a @gabriel Testing for overflow
authored
95 GHAssertEquals([error code], (NSInteger)YAJLParserErrorCodeDoubleOverflow, nil);
96 GHAssertEqualStrings([[error userInfo] objectForKey:YAJLParserValueKey], @"1.79769e+309", nil);
78fb38f @gabriel Tabs to spaces:
authored
97 } else {
98 GHFail(@"Should have error");
99 }
100
101 [parser release];
40a059a @gabriel Testing for overflow
authored
102 }
103
104 - (void)testLongLongOverflow {
78fb38f @gabriel Tabs to spaces:
authored
105 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsStrictPrecision];
b6624e8 @gabriel Updating to 1.0.11; Added test for snowflake; Fixed strict precision …
authored
106 #if TARGET_OS_IPHONE
78fb38f @gabriel Tabs to spaces:
authored
107 YAJLParserStatus status = [parser parse:[self loadData:@"overflow_longlong"]];
b6624e8 @gabriel Updating to 1.0.11; Added test for snowflake; Fixed strict precision …
authored
108 #else
109 YAJLParserStatus status = [parser parse:[self loadData:@"overflow_longlong_macosx"]];
110 #endif
78fb38f @gabriel Tabs to spaces:
authored
111 GHAssertEquals(status, (NSUInteger)YAJLParserStatusError, @"Should have error status");
112
113 NSError *error = [parser parserError];
114 if (error) {
8ddd6f8 @gabriel Building YAJL as framework on iOS targeting >= 3.0;
authored
115 GHTestLog(@"Parse error:\n%@", error);
40a059a @gabriel Testing for overflow
authored
116 GHAssertEquals([error code], (NSInteger)YAJLParserErrorCodeIntegerOverflow, nil);
117 GHAssertEqualStrings([[error userInfo] objectForKey:YAJLParserValueKey], @"9223372036854775807", nil);
78fb38f @gabriel Tabs to spaces:
authored
118 } else {
119 GHFail(@"Should have error");
120 }
121
122 [parser release];
c4bef1a @gabriel New release 0.2.4; Updating API for streaming; More tests
authored
123 }
124
910a2ff @gabriel Overflow tests.
authored
125 - (void)testOverflow2 {
126 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
78fb38f @gabriel Tabs to spaces:
authored
127 YAJLParserStatus status = [parser parse:[self loadData:@"overflow2"]];
128 GHAssertTrue(status == YAJLParserStatusOK, @"Should have ok status");
910a2ff @gabriel Overflow tests.
authored
129 [parser release];
130 }
131
c4bef1a @gabriel New release 0.2.4; Updating API for streaming; More tests
authored
132 - (void)testStreaming {
78fb38f @gabriel Tabs to spaces:
authored
133 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
134 YAJLParserStatus status;
135 status = [parser parse:[self loadData:@"stream1"]];
136 GHAssertTrue(status == YAJLParserStatusInsufficientData, @"Should have insufficient data");
137
138 status = [parser parse:[self loadData:@"stream2"]];
139 GHAssertTrue(status == YAJLParserStatusOK, @"Should have finished");
140 [parser release];
c4bef1a @gabriel New release 0.2.4; Updating API for streaming; More tests
authored
141 }
142
143 // TODO(gabe): Should error if you try to re-use
144 - (void)_testParseMoreThanOnce {
78fb38f @gabriel Tabs to spaces:
authored
145 YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
146 parser.delegate = self;
147 YAJLParserStatus status;
148 status = [parser parse:[self loadData:@"example"]];
149 GHAssertTrue(status == YAJLParserStatusOK, @"Should be OK");
150 status = [parser parse:[self loadData:@"example"]];
151 GHAssertTrue(status == YAJLParserStatusError, @"Should error");
553fc18 @gabriel New release 0.2.2 (fixes parserError bug)
authored
152 }
db25b3f @gabriel Rewritten; Updated to support 1.0.5
authored
153
154 @end
Something went wrong with that request. Please try again.