package net.wotonomy.foundation;
import static org.junit.Assert.*;
import org.junit.Test;
public class NSXMLPropertyListTest {
@Test
public void testStringParse() {
var res = NSXMLPropertyList.propertyListFromString("abc");
if (res.isLeft()) {
NSPropertyList val = res.forceLeft();
if (val.type != NSPropertyList.Type.STRING) {
fail("property list parsed incorrectly - got " + val.type.name() + " instead of string");
}
NSPropertyList.String castVal = (NSPropertyList.String) val;
assertEquals("abc", castVal.getContents());
} else {
NSError err = res.forceRight();
fail("failed to parse property list - " + err.getDescription());
}
}
@Test
public void testArrayParse() {
var res = NSXMLPropertyList.propertyListFromString("abcdef");
if (res.isLeft()) {
NSPropertyList val = res.forceLeft();
if (val.type != NSPropertyList.Type.ARRAY) {
fail("property list parsed incorrectly - got " + val.type.name() + " instead of array");
}
NSPropertyList.Array castVal = (NSPropertyList.Array) val;
NSArray contents = castVal.getContents();
assertEquals(2, contents.size());
assertEquals(NSPropertyList.Type.STRING, contents.get(0).type);
assertEquals(NSPropertyList.Type.STRING, contents.get(1).type);
assertEquals("abc", ((NSPropertyList.String)contents.get(0)).getContents());
assertEquals("def", ((NSPropertyList.String)contents.get(1)).getContents());
} else {
NSError err = res.forceRight();
fail("failed to parse property list - " + err.getDescription());
}
}
@Test
public void testDictParse() {
var res = NSXMLPropertyList.propertyListFromString("abc5");
if (res.isLeft()) {
NSPropertyList val = res.forceLeft();
if (val.type != NSPropertyList.Type.DICTIONARY) {
fail("property list parsed incorrectly - got " + val.type.name() + " instead of dictionary");
}
NSPropertyList.Dictionary castVal = (NSPropertyList.Dictionary) val;
NSDictionary contents = castVal.getContents();
assertEquals(1, contents.size());
assertEquals(NSPropertyList.Type.INTEGER, contents.get("abc").type);
assertEquals(5, ((NSPropertyList.Integer)contents.get("abc")).getContents());
} else {
NSError err = res.forceRight();
StringBuilder underlyingErrors = new StringBuilder();
for (NSError underlyingError : err.getUnderlyingErrors()) {
underlyingErrors.append(underlyingError.getDescription());
underlyingErrors.append(", ");
}
fail("failed to parse property list - " + err.getDescription() + "\n - " + underlyingErrors.toString());
}
}
}