Skip to content

Commit 9230e79

Browse files
committed
adding removeHeaderFile.js nodeunit test
1 parent 14e1342 commit 9230e79

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

test/removeHeaderFile.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
var fullProject = require('./fixtures/full-project')
2+
fullProjectStr = JSON.stringify(fullProject),
3+
pbx = require('../lib/pbxProject'),
4+
pbxFile = require('../lib/pbxFile'),
5+
proj = new pbx('.');
6+
7+
function cleanHash() {
8+
return JSON.parse(fullProjectStr);
9+
}
10+
11+
exports.setUp = function (callback) {
12+
proj.hash = cleanHash();
13+
callback();
14+
}
15+
16+
exports.addHeaderFile = {
17+
'should return a pbxFile': function (test) {
18+
var newFile = proj.addHeaderFile('file.h');
19+
20+
test.equal(newFile.constructor, pbxFile);
21+
22+
var deletedFile = proj.removeHeaderFile('file.h');
23+
24+
test.equal(deletedFile.constructor, pbxFile);
25+
26+
test.done()
27+
},
28+
'should set a fileRef on the pbxFile': function (test) {
29+
var newFile = proj.addHeaderFile('file.h');
30+
31+
test.ok(newFile.fileRef);
32+
33+
var deletedFile = proj.removeHeaderFile('file.h');
34+
35+
test.ok(deletedFile.fileRef);
36+
37+
test.done()
38+
},
39+
'should remove 2 fields from the PBXFileReference section': function (test) {
40+
var newFile = proj.addHeaderFile('file.h'),
41+
fileRefSection = proj.pbxFileReferenceSection(),
42+
frsLength = Object.keys(fileRefSection).length;
43+
44+
test.equal(68, frsLength);
45+
test.ok(fileRefSection[newFile.fileRef]);
46+
test.ok(fileRefSection[newFile.fileRef + '_comment']);
47+
48+
var deletedFile = proj.removeHeaderFile('file.h'),
49+
fileRefSection = proj.pbxFileReferenceSection(),
50+
frsLength = Object.keys(fileRefSection).length;
51+
52+
test.equal(66, frsLength);
53+
test.ok(!fileRefSection[deletedFile.fileRef]);
54+
test.ok(!fileRefSection[deletedFile.fileRef + '_comment']);
55+
56+
test.done();
57+
},
58+
'should remove comment from the PBXFileReference correctly': function (test) {
59+
var newFile = proj.addHeaderFile('file.h'),
60+
fileRefSection = proj.pbxFileReferenceSection(),
61+
commentKey = newFile.fileRef + '_comment';
62+
63+
test.equal(fileRefSection[commentKey], 'file.h');
64+
65+
var deletedFile = proj.removeHeaderFile('file.h'),
66+
fileRefSection = proj.pbxFileReferenceSection(),
67+
commentKey = deletedFile.fileRef + '_comment';
68+
test.ok(!fileRefSection[commentKey]);
69+
70+
test.done();
71+
},
72+
'should remove the PBXFileReference object correctly': function (test) {
73+
var newFile = proj.addHeaderFile('Plugins/file.h'),
74+
fileRefSection = proj.pbxFileReferenceSection(),
75+
fileRefEntry = fileRefSection[newFile.fileRef];
76+
77+
test.equal(fileRefEntry.isa, 'PBXFileReference');
78+
test.equal(fileRefEntry.fileEncoding, 4);
79+
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h');
80+
test.equal(fileRefEntry.name, 'file.h');
81+
test.equal(fileRefEntry.path, 'file.h');
82+
test.equal(fileRefEntry.sourceTree, '"<group>"');
83+
84+
var deletedFile = proj.removeHeaderFile('Plugins/file.h'),
85+
fileRefSection = proj.pbxFileReferenceSection(),
86+
fileRefEntry = fileRefSection[deletedFile.fileRef];
87+
88+
test.ok(!fileRefEntry);
89+
90+
test.done();
91+
},
92+
'should remove from the Plugins PBXGroup group': function (test) {
93+
var newFile = proj.addHeaderFile('Plugins/file.h'),
94+
plugins = proj.pbxGroupByName('Plugins');
95+
96+
test.equal(plugins.children.length, 1);
97+
98+
var deletedFile = proj.removeHeaderFile('Plugins/file.h'),
99+
plugins = proj.pbxGroupByName('Plugins');
100+
101+
test.equal(plugins.children.length, 0);
102+
103+
test.done();
104+
},
105+
'should have the right values for the PBXGroup entry': function (test) {
106+
var newFile = proj.addHeaderFile('Plugins/file.h'),
107+
plugins = proj.pbxGroupByName('Plugins'),
108+
pluginObj = plugins.children[0];
109+
110+
test.equal(pluginObj.comment, 'file.h');
111+
test.equal(pluginObj.value, newFile.fileRef);
112+
113+
var deletedFile = proj.removeHeaderFile('Plugins/file.h'),
114+
plugins = proj.pbxGroupByName('Plugins'),
115+
pluginObj = plugins.children[0];
116+
117+
test.ok(!pluginObj);
118+
119+
test.done();
120+
}
121+
}

0 commit comments

Comments
 (0)