Skip to content

Commit 5aab68a

Browse files
committed
Add test for addAll
1 parent 39477a1 commit 5aab68a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

ObjectiveGitTests/GTIndexSpec.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,33 @@
227227
renamedFileURL = [NSURL fileURLWithPath:newPath isDirectory:NO];
228228
});
229229

230+
it(@"should add all files from the current file system to the index", ^{
231+
NSData *currentFileContent = [[NSFileManager defaultManager] contentsAtPath:fileURL.path];
232+
expect(currentFileContent).notTo(beNil());
233+
NSString *currentFileString = [[NSString alloc] initWithData:currentFileContent encoding:NSUTF8StringEncoding];
234+
currentFileString = [currentFileString stringByAppendingString:@"I would like to append this to the file"];
235+
currentFileContent = [currentFileString dataUsingEncoding:NSUTF8StringEncoding];
236+
expect(@([[NSFileManager defaultManager] createFileAtPath:fileURL.path contents:currentFileContent attributes:nil])).to(beTruthy());
237+
238+
NSString *newFileContent = @"This is a new file \n1 2 3";
239+
NSData *newFileData = [newFileContent dataUsingEncoding:NSUTF8StringEncoding];
240+
expect(newFileData).notTo(beNil());
241+
expect(@([[NSFileManager defaultManager] createFileAtPath:renamedFileURL.path contents:newFileData attributes:nil])).to(beTruthy());
242+
243+
GTIndexEntry *entry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping]];
244+
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeUnmodified, GTDeltaTypeModified))).to(beTruthy());
245+
entry = [index entryWithPath:[renamedFilename decomposedStringWithCanonicalMapping]];
246+
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeUnmodified, GTDeltaTypeUntracked))).to(beTruthy());
247+
248+
expect(@([index addAll:NULL])).to(beTruthy());
249+
expect(@([index write:NULL])).to(beTruthy());
250+
251+
entry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping]];
252+
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeModified, GTDeltaTypeUnmodified))).to(beTruthy());
253+
entry = [index entryWithPath:[renamedFilename decomposedStringWithCanonicalMapping]];
254+
expect(@(fileStatusEqualsExpected(entry.path, GTDeltaTypeAdded, GTDeltaTypeUnmodified))).to(beTruthy());
255+
});
256+
230257
it(@"it preserves decomposed Unicode in index paths with precomposeunicode disabled", ^{
231258
NSString *decomposedFilename = [filename decomposedStringWithCanonicalMapping];
232259
GTIndexEntry *entry = [index entryWithPath:decomposedFilename error:NULL];

0 commit comments

Comments
 (0)