@global module
var FILE = require("file"),
FileList = require("jake").FileList;
@implementation CFPropertyListTest : OJTestCase
- (void)testFormatSniffing
{
var XMLPropertyLists = new FileList(FILE.join(FILE.dirname(module.path), "PropertyLists", "XML-*.plist"));
XMLPropertyLists.forEach(function(/*String*/ aPath)
{
[self assert:CFPropertyList.FormatXML_v1_0 equals:CFPropertyList.sniffedFormatOfString(FILE.read(aPath))];
});
}
- (void)testDateDeserialization
{
var path = FILE.join(FILE.dirname(module.path), "PropertyLists/XMLDate.plist"),
object = CFPropertyList.readPropertyListFromFile(path),
date = [object objectForKey:@"date"];
[self assert:[CPDate class] equals:[date class]];
[self assert:[[CPDate alloc] initWithString:"2012-01-01 10:00:00 +0100"] equals:date];
}
- (void)testPropertyListFromXMLShouldHandleEmptyXMLGracefully {
// rhino can't parse empty XML documents
if (system.engine !== "rhino") {
var XML = "",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:object equals:null];
}
}
- (void)testPropertyListFromXMLShouldHandleEmptierXMLGracefully {
// rhino can't parse empty XML documents
if (system.engine !== "rhino") {
var XML = "",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:object equals:null];
}
}
- (void)testPropertyListFromXMLShouldHandleEmptiestXMLGracefully {
// rhino can't parse empty XML documents
if (system.engine !== "rhino") {
var XML = "",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:object equals:null];
}
}
- (void)testPropertyListFromXMLShouldParseNiceAndCleanXML {
var XML = "Main cib file base nameMainMenu.cibCPBundleNameCopyAndPasteCPBundleVersion1.0CPHumanReadableCopyrightCopyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:[object valueForKey:"Main cib file base name"] equals:"MainMenu.cib"];
[self assert:[object valueForKey:"CPBundleName"] equals:"CopyAndPaste"];
[self assert:[object valueForKey:"CPBundleVersion"] equals:"1.0"];
[self assert:[object valueForKey:"CPHumanReadableCopyright"] equals:"Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved."];
[self assert:[object count] equals:4];
}
- (void)testPropertyListFromXMLShouldIgnoreWhiteSpace{
var XML = "\n \n \n\n\tMain cib file base name\n\tMainMenu.cib\n\t CPBundleName\n\tCopyAndPaste\n CPBundleVersion\n 1.0\n CPHumanReadableCopyright\n Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.\n\n\n",
// feed in preparsed XML to ensure we preserve whitespace for purposes of this test
object = CFPropertyList.propertyListFromXML(new window.DOMParser().parseFromString(XML, "text/xml"));
[self assert:[object valueForKey:"Main cib file base name"] equals:"MainMenu.cib"];
[self assert:[object valueForKey:"CPBundleName"] equals:"CopyAndPaste"];
[self assert:[object valueForKey:"CPBundleVersion"] equals:"1.0"];
[self assert:[object valueForKey:"CPHumanReadableCopyright"] equals:"Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved."];
[self assert:[object count] equals:4];
}
@end