1<?php 2# 3# S P Y C 4# a simple php yaml class 5# v0.3 6# 7# author: [chris wanstrath, chris@ozmm.org] 8# websites: [http://www.yaml.org, http://spyc.sourceforge.net/] 9# license: [MIT License, http://www.opensource.org/licenses/mit-license.php] 10# copyright: (c) 2005-2006 Chris Wanstrath 11# 12# We're gonna load a file into memory and see if we get what we expect. 13# If not, we're gonna complain. 14# 15# Pretty lo-fi. Let's see if we can't get some unit testing going in the next, 16# I dunno, 20 months? Alright. Go team. 17# 18 19error_reporting(E_ALL); 20 21include('spyc.php4'); 22 23$yaml = Spyc::YAMLLoad('../spyc.yaml'); 24 25// print_r ($yaml); 26 27# Added in .2 28if ($yaml[1040] != "Ooo, a numeric key!") 29 die('Key: 1040 failed'); 30 31# Test mappings / types 32if ($yaml['String'] != "Anyone's name, really.") 33 die('Key: String failed'); 34 35if ($yaml['Int'] !== 13) 36 die('Key: Int failed'); 37 38if ($yaml['True'] !== true) 39 die('Key: True failed'); 40 41if ($yaml['False'] !== false) 42 die('Key: False failed'); 43 44if ($yaml['Zero'] !== 0) 45 die('Key: Zero failed'); 46 47if (isset($yaml['Null'])) 48 die('Key: Null failed'); 49 50if ($yaml['Float'] !== 5.34) 51 die('Key: Float failed'); 52 53 54# Test sequences 55if ($yaml[0] != "PHP Class") 56 die('Sequence 0 failed'); 57 58if ($yaml[1] != "Basic YAML Loader") 59 die('Sequence 1 failed'); 60 61if ($yaml[2] != "Very Basic YAML Dumper") 62 die('Sequence 2 failed'); 63 64# A sequence of a sequence 65if ($yaml[3] != array("YAML is so easy to learn.", 66 "Your config files will never be the same.")) 67 die('Sequence 3 failed'); 68 69# Sequence of mappings 70if ($yaml[4] != array("cpu" => "1.5ghz", "ram" => "1 gig", 71 "os" => "os x 10.4.1")) 72 die('Sequence 4 failed'); 73 74# Mapped sequence 75if ($yaml['domains'] != array("yaml.org", "php.net")) 76 die("Key: 'domains' failed"); 77 78# A sequence like this. 79if ($yaml[5] != array("program" => "Adium", "platform" => "OS X", 80 "type" => "Chat Client")) 81 die('Sequence 5 failed'); 82 83# A folded block as a mapped value 84if ($yaml['no time'] != "There isn't any time for your tricks!\nDo you understand?") 85 die("Key: 'no time' failed"); 86 87# A literal block as a mapped value 88if ($yaml['some time'] != "There is nothing but time\nfor your tricks.") 89 die("Key: 'some time' failed"); 90 91# Crazy combinations 92if ($yaml['databases'] != array( array("name" => "spartan", "notes" => 93 array( "Needs to be backed up", 94 "Needs to be normalized" ), 95 "type" => "mysql" ))) 96 die("Key: 'databases' failed"); 97 98# You can be a bit tricky 99if ($yaml["if: you'd"] != "like") 100 die("Key: 'if: you\'d' failed"); 101 102# Inline sequences 103if ($yaml[6] != array("One", "Two", "Three", "Four")) 104 die("Sequence 6 failed"); 105 106# Nested Inline Sequences 107if ($yaml[7] != array("One", array("Two", "And", "Three"), "Four", "Five")) 108 die("Sequence 7 failed"); 109 110# Nested Nested Inline Sequences 111if ($yaml[8] != array( "This", array("Is", "Getting", array("Ridiculous", "Guys")), 112 "Seriously", array("Show", "Mercy"))) 113 die("Sequence 8 failed"); 114 115# Inline mappings 116if ($yaml[9] != array("name" => "chris", "age" => "young", "brand" => "lucky strike")) 117 die("Sequence 9 failed"); 118 119# Nested inline mappings 120if ($yaml[10] != array("name" => "mark", "age" => "older than chris", 121 "brand" => array("marlboro", "lucky strike"))) 122 die("Sequence 10 failed"); 123 124# References -- they're shaky, but functional 125if ($yaml['dynamic languages'] != array('Perl', 'Python', 'PHP', 'Ruby')) 126 die("Key: 'dynamic languages' failed"); 127 128if ($yaml['compiled languages'] != array('C/C++', 'Java')) 129 die("Key: 'compiled languages' failed"); 130 131if ($yaml['all languages'] != array( 132 array('Perl', 'Python', 'PHP', 'Ruby'), 133 array('C/C++', 'Java') 134 )) 135 die("Key: 'all languages' failed"); 136 137# Added in .2.2: Escaped quotes 138if ($yaml[11] != "you know, this shouldn't work. but it does.") 139 die("Sequence 11 failed."); 140 141if ($yaml[12] != "that's my value.") 142 die("Sequence 12 failed."); 143 144if ($yaml[13] != "again, that's my value.") 145 die("Sequence 13 failed."); 146 147if ($yaml[14] != "here's to \"quotes\", boss.") 148 die("Sequence 14 failed."); 149 150if ($yaml[15] != array( 'name' => "Foo, Bar's", 'age' => 20)) 151 die("Sequence 15 failed."); 152 153if ($yaml[16] != array( 0 => "a", 1 => array (0 => 1, 1 => 2), 2 => "b")) 154 die("Sequence 16 failed."); 155 156if ($yaml['endloop'] != "Does this line in the end indeed make Spyc go to an infinite loop?") 157 die("[endloop] failed."); 158 159 160print "spyc.yaml parsed correctly\n"; 161 162?>