forked from jsonmodel/jsonmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTests.m
More file actions
85 lines (69 loc) · 2.67 KB
/
ArrayTests.m
File metadata and controls
85 lines (69 loc) · 2.67 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
//
// ArrayTests.m
// JSONModelDemo
//
// Created by Marin Todorov on 19/12/2012.
// Copyright (c) 2012 Underplot ltd. All rights reserved.
//
#import "ArrayTests.h"
#import "JSONModelLib.h"
#import "ReposModel.h"
@implementation ArrayTests
{
ReposModel* repos;
}
-(void)setUp
{
[super setUp];
NSString* filePath = [[NSBundle bundleForClass:[JSONModel class]].resourcePath stringByAppendingPathComponent:@"github-iphone.json"];
NSString* jsonContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
XCTAssertNotNil(jsonContents, @"Can't fetch test data file contents.");
NSError* err;
repos = [[ReposModel alloc] initWithString:jsonContents error:&err];
XCTAssertNil(err, @"%@", [err localizedDescription]);
XCTAssertNotNil(repos, @"Could not load the test data file.");
}
-(void)testLoading
{
XCTAssertTrue([repos.repositories isMemberOfClass:[JSONModelArray class]], @".properties is not a JSONModelArray");
XCTAssertEqualObjects([[repos.repositories[0] class] description], @"GitHubRepoModel", @".properties[0] is not a GitHubRepoModel");
}
- (void)testCount
{
XCTAssertEqualObjects(@(repos.repositories.count), @100, @"wrong count");
}
- (void)testReadArray
{
JSONModelArray *array = [JSONModelArray new];
XCTAssertEqualObjects(@(array.count), @0, @"wrong count");
XCTAssertNil([array firstObject], @"first object of an empty array should be nil");
XCTAssertNil([array lastObject], @"last object of an empty array should be nil");
// XCTAssertThrows(array[0], @"read of empty array should throw an exception");
// XCTAssertThrows(array[2], @"read of empty array should throw an exception");
// XCTAssertNilThrows(array[-2], @"read of empty array should throw an exception");
XCTAssertNil(array[0], @"read of empty array should be nil");
XCTAssertNil(array[2], @"read of empty array should be nil");
XCTAssertNil(array[-2], @"read of empty array should be nil");
}
-(void)testFirstObject
{
XCTAssertEqualObjects([[repos.repositories.firstObject class] description], @"GitHubRepoModel", @"wrong class");
XCTAssertEqualObjects([repos.repositories.firstObject description], @"cocos2d for iPhone", @"wrong description");
}
/*
* https://github.com/icanzilb/JSONModel/pull/14
*/
-(void)testArrayReverseTransformGitHubIssue_14
{
NSDictionary* dict = [repos toDictionary];
XCTAssertNotNil(dict, @"Could not convert ReposModel back to an NSDictionary");
}
/*
* https://github.com/icanzilb/JSONModel/issues/15
*/
-(void)testArrayReverseTransformGitHubIssue_15
{
NSString* string = [repos toJSONString];
XCTAssertNotNil(string, @"Could not convert ReposModel back to a string");
}
@end