blob: d3b49e871bf36d6b0553395a5bcc47534f358879 [file] [log] [blame]
var pbx = require('../lib/pbxProject'),
fs = require('fs'),
myProj;
function testProjectContents(filename, test, expectedFilename) {
var myProj = new pbx(filename);
var content;
if (expectedFilename) {
content = fs.readFileSync(expectedFilename, 'utf-8');
} else {
content = fs.readFileSync(filename, 'utf-8');
}
// normalize tabs vs strings
content = content.replace(/ /g, '\t');
myProj.parse(function (err, projHash) {
var written = myProj.writeSync();
test.equal(content, written);
test.done();
});
}
// for debugging failing tests
function testContentsInDepth(filename, test) {
var myProj = new pbx(filename),
content = fs.readFileSync(filename, 'utf-8');
// normalize tabs vs strings
content = content.replace(/ /g, '\t');
myProj.parse(function (err, projHash) {
var written = myProj.writeSync(),
writtenLines = written.split('\n')
contentLines = content.split('\n')
test.equal(writtenLines.length, contentLines.length);
for (var i=0; i<writtenLines.length; i++) {
test.equal(writtenLines[i], contentLines[i],
'match failed on line ' + (i+1))
}
test.done();
});
}
exports.writeSync = {
'should write out the "hash" test': function (test) {
testProjectContents('test/parser/projects/hash.pbxproj', test);
},
'should write out the "with_array" test': function (test) {
// Special case in that the originating project does not have a trailing comma for all of its array entries.
// This is definitely possibly.
// But when we write/read it out again during testing, the trailing commas are introduced by our library.
testProjectContents('test/parser/projects/with_array.pbxproj', test, 'test/parser/projects/expected/with_array_expected.pbxproj');
},
'should write out the "section" test': function (test) {
testProjectContents('test/parser/projects/section.pbxproj', test);
},
'should write out the "two-sections" test': function (test) {
testProjectContents('test/parser/projects/two-sections.pbxproj', test);
},
'should write out the "section-entries" test': function (test) {
testProjectContents('test/parser/projects/section-entries.pbxproj', test);
},
'should write out the "build-config" test': function (test) {
testProjectContents('test/parser/projects/build-config.pbxproj', test);
},
'should write out the "header-search" test': function (test) {
testProjectContents('test/parser/projects/header-search.pbxproj', test);
},
'should write out the "nested-object" test': function (test) {
testProjectContents('test/parser/projects/nested-object.pbxproj', test);
},
'should write out the "build-files" test': function (test) {
testProjectContents('test/parser/projects/build-files.pbxproj', test);
},
'should write out the "file-references" test': function (test) {
testProjectContents('test/parser/projects/file-references.pbxproj', test);
}
}