Skip to content

Commit 9e1ebed

Browse files
committed
adding removeSourceFile.js
1 parent 6c8604c commit 9e1ebed

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

test/removeSourceFile.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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.removeSourceFile = {
17+
'should return a pbxFile': function (test) {
18+
proj.addSourceFile('file.m');
19+
var newFile = proj.removeSourceFile('file.m');
20+
21+
test.equal(newFile.constructor, pbxFile);
22+
test.done()
23+
},
24+
'should set a uuid on the pbxFile': function (test) {
25+
proj.addSourceFile('file.m');
26+
var newFile = proj.removeSourceFile('file.m');
27+
28+
test.ok(newFile.uuid);
29+
test.done()
30+
},
31+
'should set a fileRef on the pbxFile': function (test) {
32+
proj.addSourceFile('file.m');
33+
var newFile = proj.removeSourceFile('file.m');
34+
35+
test.ok(newFile.fileRef);
36+
test.done()
37+
},
38+
'should remove 2 fields from the PBXBuildFile section': function (test) {
39+
proj.addSourceFile('file.m');
40+
var newFile = proj.removeSourceFile('file.m'),
41+
buildFileSection = proj.pbxBuildFileSection(),
42+
bfsLength = Object.keys(buildFileSection).length;
43+
44+
test.equal(58, bfsLength);
45+
test.ok(!buildFileSection[newFile.uuid]);
46+
test.ok(!buildFileSection[newFile.uuid + '_comment']);
47+
48+
test.done();
49+
},
50+
'should remove comment from the PBXBuildFile correctly': function (test) {
51+
proj.addSourceFile('file.m');
52+
var newFile = proj.removeSourceFile('file.m'),
53+
commentKey = newFile.uuid + '_comment',
54+
buildFileSection = proj.pbxBuildFileSection();
55+
test.notEqual(!buildFileSection[commentKey], 'file.m in Sources');
56+
test.done();
57+
},
58+
'should remove the PBXBuildFile object correctly': function (test) {
59+
proj.addSourceFile('file.m');
60+
var newFile = proj.removeSourceFile('file.m'),
61+
buildFileSection = proj.pbxBuildFileSection(),
62+
buildFileEntry = buildFileSection[newFile.uuid];
63+
64+
test.equal(buildFileEntry, undefined);
65+
66+
test.done();
67+
},
68+
'should remove 2 fields from the PBXFileReference section': function (test) {
69+
proj.addSourceFile('file.m');
70+
var newFile = proj.removeSourceFile('file.m'),
71+
fileRefSection = proj.pbxFileReferenceSection(),
72+
frsLength = Object.keys(fileRefSection).length;
73+
74+
test.equal(66, frsLength);
75+
test.ok(!fileRefSection[newFile.fileRef]);
76+
test.ok(!fileRefSection[newFile.fileRef + '_comment']);
77+
78+
test.done();
79+
},
80+
'should remove the PBXFileReference comment correctly': function (test) {
81+
proj.addSourceFile('file.m');
82+
var newFile = proj.removeSourceFile('file.m'),
83+
fileRefSection = proj.pbxFileReferenceSection(),
84+
commentKey = newFile.fileRef + '_comment';
85+
86+
test.ok(!fileRefSection[commentKey]);
87+
test.done();
88+
},
89+
'should remove the PBXFileReference object correctly': function (test) {
90+
proj.addSourceFile('file.m');
91+
var newFile = proj.removeSourceFile('Plugins/file.m'),
92+
fileRefSection = proj.pbxFileReferenceSection(),
93+
fileRefEntry = fileRefSection[newFile.fileRef];
94+
test.ok(!fileRefEntry);
95+
test.done();
96+
},
97+
'should remove from the Plugins PBXGroup group': function (test) {
98+
proj.addSourceFile('Plugins/file.m');
99+
var newFile = proj.removeSourceFile('Plugins/file.m'),
100+
plugins = proj.pbxGroupByName('Plugins');
101+
test.equal(plugins.children.length, 0);
102+
test.done();
103+
},
104+
'should have the right values for the PBXGroup entry': function (test) {
105+
proj.addSourceFile('Plugins/file.m');
106+
var newFile = proj.removeSourceFile('Plugins/file.m'),
107+
plugins = proj.pbxGroupByName('Plugins'),
108+
pluginObj = plugins.children[0];
109+
110+
test.ok(!pluginObj);
111+
test.done();
112+
},
113+
'should remove from the PBXSourcesBuildPhase': function (test) {
114+
proj.addSourceFile('Plugins/file.m');
115+
var newFile = proj.removeSourceFile('Plugins/file.m'),
116+
sources = proj.pbxSourcesBuildPhaseObj();
117+
118+
test.equal(sources.files.length, 2);
119+
test.done();
120+
},
121+
'should have the right values for the Sources entry': function (test) {
122+
proj.addSourceFile('Plugins/file.m');
123+
var newFile = proj.removeSourceFile('Plugins/file.m'),
124+
sources = proj.pbxSourcesBuildPhaseObj(),
125+
sourceObj = sources.files[2];
126+
127+
test.ok(!sourceObj);
128+
test.done();
129+
}
130+
}
131+

0 commit comments

Comments
 (0)