var fullProject = require('./fixtures/full-project')
fullProjectStr = JSON.stringify(fullProject),
pbx = require('../lib/pbxProject'),
pbxFile = require('../lib/pbxFile'),
proj = new pbx('.');
function cleanHash() {
return JSON.parse(fullProjectStr);
}
function nonComments(obj) {
var keys = Object.keys(obj),
newObj = {}, i = 0;
for (i; i < keys.length; i++) {
if (!/_comment$/.test(keys[i])) {
newObj[keys[i]] = obj[keys[i]];
}
}
return newObj;
}
function librarySearchPaths(proj) {
var configs = nonComments(proj.pbxXCBuildConfigurationSection()),
allPaths = [],
ids = Object.keys(configs), i, buildSettings;
for (i = 0; i< ids.length; i++) {
buildSettings = configs[ids[i]].buildSettings;
if (buildSettings['LIBRARY_SEARCH_PATHS']) {
allPaths.push(buildSettings['LIBRARY_SEARCH_PATHS']);
}
}
return allPaths;
}
exports.setUp = function (callback) {
proj.hash = cleanHash();
callback();
}
exports.addStaticLibrary = {
'should return a pbxFile': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
test.equal(newFile.constructor, pbxFile);
test.done()
},
'should set a fileRef on the pbxFile': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
test.ok(newFile.fileRef);
test.done()
},
'should populate the PBXBuildFile section with 2 fields': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
buildFileSection = proj.pbxBuildFileSection(),
bfsLength = Object.keys(buildFileSection).length;
test.equal(60, bfsLength);
test.ok(buildFileSection[newFile.uuid]);
test.ok(buildFileSection[newFile.uuid + '_comment']);
test.done();
},
'should populate the PBXBuildFile section with 2 fields as plugin': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a',
{ plugin: true });
buildFileSection = proj.pbxBuildFileSection(),
bfsLength = Object.keys(buildFileSection).length;
test.equal(60, bfsLength);
test.ok(buildFileSection[newFile.uuid]);
test.ok(buildFileSection[newFile.uuid + '_comment']);
test.done();
},
'should add the PBXBuildFile comment correctly': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
commentKey = newFile.uuid + '_comment',
buildFileSection = proj.pbxBuildFileSection();
test.equal(buildFileSection[commentKey], 'libGoogleAnalytics.a in Frameworks');
test.done();
},
'should add the PBXBuildFile object correctly': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
buildFileSection = proj.pbxBuildFileSection(),
buildFileEntry = buildFileSection[newFile.uuid];
test.equal(buildFileEntry.isa, 'PBXBuildFile');
test.equal(buildFileEntry.fileRef, newFile.fileRef);
test.equal(buildFileEntry.fileRef_comment, 'libGoogleAnalytics.a');
test.done();
},
'should populate the PBXFileReference section with 2 fields': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
fileRefSection = proj.pbxFileReferenceSection(),
frsLength = Object.keys(fileRefSection).length;
test.equal(68, frsLength);
test.ok(fileRefSection[newFile.fileRef]);
test.ok(fileRefSection[newFile.fileRef + '_comment']);
test.done();
},
'should populate the PBXFileReference comment correctly': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a');
fileRefSection = proj.pbxFileReferenceSection(),
commentKey = newFile.fileRef + '_comment';
test.equal(fileRefSection[commentKey], 'libGoogleAnalytics.a');
test.done();
},
'should add the PBXFileReference object correctly': function (test) {
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'),
fileRefSection = proj.pbxFileReferenceSection(),
fileRefEntry = fileRefSection[newFile.fileRef];
test.equal(fileRefEntry.isa, 'PBXFileReference');
test.equal(fileRefEntry.lastKnownFileType, 'archive.ar');
test.equal(fileRefEntry.name, '"libGoogleAnalytics.a"');
test.equal(fileRefEntry.path, '"libGoogleAnalytics.a"');
test.equal(fileRefEntry.sourceTree, '"