Skip to content
This repository
branch: 98a5ebf13614f6…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 109 lines (87 sloc) 2.98 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
//
// YAJLParserTest.m
// YAJL
//
// Created by Gabriel Handford on 6/14/09.
// Copyright 2009. All rights reserved.
//


@interface YAJLParserTest : YAJLTestCase {}
@end

@implementation YAJLParserTest

- (void)test {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
[parser parse:[self loadData:@"example"]];

NSError *error = [parser parserError];
if (error) {
NSLog(@"Parse error:\n%@", error);
GHFail(@"Error: %@", error);
}

[parser release];
}

- (void)testError {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
YAJLParserStatus status = [parser parse:[self loadData:@"error"]];
GHAssertTrue(status == YAJLParserStatusError, @"Should have error status");

NSError *error = [parser parserError];
if (error) {
GHTestLog(@"Parse error:\n%@", error);
} else {
GHFail(@"Should have error");
}

[parser release];
}

- (void)testComments {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsAllowComments];
YAJLParserStatus status = [parser parse:[self loadData:@"comments"]];
GHAssertTrue(status == YAJLParserStatusOK, @"Should have error status");

NSError *error = [parser parserError];
if (error) {
GHTestLog(@"Parse error:\n%@", error);
GHFail(@"Error: %@", error);
}

[parser release];
}

- (void)testFailOnComments {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
YAJLParserStatus status = [parser parse:[self loadData:@"comments"]];
GHAssertTrue(status == YAJLParserStatusError, @"Should have error status");

NSError *error = [parser parserError];
if (error) {
GHTestLog(@"Parse error:\n%@", error);
} else {
GHFail(@"Should have error");
}

[parser release];
}

- (void)testOverflow {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
YAJLParserStatus status = [parser parse:[self loadData:@"overflow"]];
GHAssertTrue(status == YAJLParserStatusError, @"Should have error status");

NSError *error = [parser parserError];
if (error) {
GHTestLog(@"Parse error:\n%@", error);
} else {
GHFail(@"Should have error");
}

[parser release];
}

- (void)testStreaming {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
YAJLParserStatus status;
status = [parser parse:[self loadData:@"stream1"]];
GHAssertTrue(status == YAJLParserStatusInsufficientData, @"Should have insufficient data");

status = [parser parse:[self loadData:@"stream2"]];
GHAssertTrue(status == YAJLParserStatusOK, @"Should have finished");
[parser release];
}

// TODO(gabe): Should error if you try to re-use
- (void)_testParseMoreThanOnce {
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0];
parser.delegate = self;
YAJLParserStatus status;
status = [parser parse:[self loadData:@"example"]];
GHAssertTrue(status == YAJLParserStatusOK, @"Should be OK");
status = [parser parse:[self loadData:@"example"]];
GHAssertTrue(status == YAJLParserStatusError, @"Should error");
}

@end
Something went wrong with that request. Please try again.