-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathNSArray+StringArraySpec.m
More file actions
108 lines (85 loc) · 2.87 KB
/
NSArray+StringArraySpec.m
File metadata and controls
108 lines (85 loc) · 2.87 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
//
// NSArray+StringArraySpec.m
// ObjectiveGitFramework
//
// Created by Danny Greg on 22/08/2013.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
//
@import ObjectiveGit;
@import Nimble;
@import Quick;
#import "QuickSpec+GTFixtures.h"
QuickSpecBegin(StringArray)
describe(@"String arrays", ^{
void (^validateStrArray)(NSArray *, git_strarray) = ^(NSArray *array, git_strarray strArray) {
expect(@(strArray.count)).to(equal(@(array.count)));
for (NSUInteger idx = 0; idx < array.count; idx++) {
const char *convertedString = strArray.strings[idx];
NSString *comparisonString = @(convertedString);
expect(array[idx]).to(equal(comparisonString));
}
};
describe(@"allow conversion to a git_strarray", ^{
__block NSArray *originalArray = nil;
__block git_strarray strArray;
beforeEach(^{
originalArray = @[ @"First", @"Second", @"Third", @"Fourth", @"Fifth", @"Sixth" ];
strArray = originalArray.git_strarray;
});
afterEach(^{
git_strarray_free(&strArray);
});
it(@"should return null for an empty array", ^{
NSArray *emptyArray = [NSArray array];
expect(@(emptyArray.git_strarray.count)).to(equal(@0));
expect([NSValue valueWithPointer:emptyArray.git_strarray.strings]).to(equal([NSValue valueWithPointer:NULL]));
});
it(@"should correctly translate the strings", ^{
validateStrArray(originalArray, strArray);
});
it(@"should be able to be copied", ^{
git_strarray copiedArray;
git_strarray_copy(&copiedArray, &strArray);
validateStrArray(originalArray, copiedArray);
git_strarray_free(&copiedArray);
});
it(@"should stay valid outside of an autorelease pool", ^{
git_strarray dontAutoreleaseThis;
@autoreleasepool {
dontAutoreleaseThis = originalArray.git_strarray;
}
validateStrArray(originalArray, dontAutoreleaseThis);
});
});
describe(@"allows conversion from a git_strarray", ^{
__block git_strarray originalStrArray;
beforeEach(^{
originalStrArray.count = 3;
originalStrArray.strings = calloc(originalStrArray.count, sizeof(char *));
originalStrArray.strings[0] = "First";
originalStrArray.strings[1] = "Second";
originalStrArray.strings[2] = "Third";
});
afterEach(^{
free(originalStrArray.strings);
});
it(@"should return an empty array for an NULL strarray", ^{
git_strarray strarray = { .strings = NULL, .count = 0 };
NSArray *array = [NSArray git_arrayWithStrarray:strarray];
expect(@(array.count)).to(equal(@0));
});
it(@"should correctly translate the strarray", ^{
NSArray *array = [NSArray git_arrayWithStrarray:originalStrArray];
validateStrArray(array, originalStrArray);
});
it(@"should omit NULL strings", ^{
originalStrArray.strings[1] = NULL;
NSArray *array = [NSArray git_arrayWithStrarray:originalStrArray];
expect(array).to(equal((@[ @"First", @"Third" ])));
});
});
});
afterEach(^{
[self tearDown];
});
QuickSpecEnd