1 module plist.tests.boolean; 2 import plist; 3 import plist.types; 4 5 unittest { 6 /* Can we even parse? */ 7 { 8 string xml = `<?xml version="1.0" encoding="UTF-8"?> 9 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 10 <plist version="1.0"> 11 <true/> 12 </plist>`; 13 Plist parse = new Plist(); 14 parse.read(xml); 15 16 assert(parse.length == 1, "Expected length of 1"); 17 18 assert(parse.write() == xml, "Writing doesn't output the same what we put in"); 19 20 import std.stdio; 21 assert(parse[0].type() == "bool", "Expected boolean at index 0"); 22 23 PlistElementBoolean b = cast(PlistElementBoolean)parse[0]; 24 25 assert(b.value, "Expected boolean to be true"); 26 } 27 /* Since this is an empty tag, we will convert it to it's proper form */ 28 { 29 string xml = `<?xml version="1.0" encoding="UTF-8"?> 30 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 31 <plist version="1.0"> 32 <true> 33 </true> 34 </plist>`; 35 string expected = `<?xml version="1.0" encoding="UTF-8"?> 36 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 37 <plist version="1.0"> 38 <true/> 39 </plist>`; 40 41 Plist parse = new Plist(); 42 parse.read(xml); 43 44 assert(parse.length == 1, "Expected length of 1"); 45 46 assert(parse.write() == expected, "Writing doesn't output the same as what we expected"); 47 48 import std.stdio; 49 assert(parse[0].type() == "bool", "Expected boolean at index 0"); 50 51 PlistElementBoolean b = cast(PlistElementBoolean)parse[0]; 52 53 assert(b.value, "Expected boolean to be true"); 54 b.value = false; 55 assert(!b.value, "Expected boolean to be false"); 56 } 57 /* Test if it can be false, too */ 58 { 59 string xml = `<?xml version="1.0" encoding="UTF-8"?> 60 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 61 <plist version="1.0"> 62 <false/> 63 </plist>`; 64 Plist parse = new Plist(); 65 parse.read(xml); 66 67 assert(parse.length == 1, "Expected length of 1"); 68 69 assert(parse.write() == xml, "Writing doesn't output the same what we put in"); 70 71 import std.stdio; 72 assert(parse[0].type() == "bool", "Expected boolean at index 0"); 73 74 PlistElementBoolean b = cast(PlistElementBoolean)parse[0]; 75 76 assert(!b.value, "Expected boolean to be false"); 77 b.value = true; 78 assert(b.value, "Expected boolean to be true"); 79 } 80 /* Since this is an empty tag, we will convert it to it's proper form (same test, except with false)*/ 81 { 82 string xml = `<?xml version="1.0" encoding="UTF-8"?> 83 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 84 <plist version="1.0"> 85 <false> 86 </false> 87 </plist>`; 88 string expected = `<?xml version="1.0" encoding="UTF-8"?> 89 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 90 <plist version="1.0"> 91 <false/> 92 </plist>`; 93 94 Plist parse = new Plist(); 95 parse.read(xml); 96 97 assert(parse.length == 1, "Expected length of 1"); 98 99 assert(parse.write() == expected, "Writing doesn't output the same as what we expected"); 100 101 import std.stdio; 102 assert(parse[0].type() == "bool", "Expected boolean at index 0"); 103 104 PlistElementBoolean b = cast(PlistElementBoolean)parse[0]; 105 106 assert(!b.value, "Expected boolean to be false"); 107 b.value = true; 108 assert(b.value, "Expected boolean to be true"); 109 } 110 111 112 113 }