Added Canvas 1.1.0, originally not under SCM so no historical development records...
[canvas.git] / library / YAML / test.php
blobb6473b2f04045925b35161b84a4ffd24c30383c9
1 <?php
3 # S P Y C
4 # a simple php yaml class
5 # v0.2(.2)
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
12 # We're gonna load a file into memory and see if we get what we expect.
13 # If not, we're gonna complain.
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.
19 error_reporting(E_STRICT);
21 include('spyc.php');
23 $yaml = Spyc::YAMLLoad('spyc.yml');
26 # Added in .2
27 if ($yaml[1040] != "Ooo, a numeric key!")
28 die('Key: 1040 failed');
30 # Test mappings / types
31 if ($yaml['String'] != "Anyone's name, really.")
32 die('Key: String failed');
34 if ($yaml['Int'] !== 13)
35 die('Key: Int failed');
37 if ($yaml['True'] !== true)
38 die('Key: True failed');
40 if ($yaml['False'] !== false)
41 die('Key: False failed');
43 if ($yaml['Zero'] !== 0)
44 die('Key: Zero failed');
46 if ($yaml['Null'] !== NULL)
47 die('Key: Null failed');
49 if ($yaml['Float'] !== 5.34)
50 die('Key: Float failed');
53 # Test sequences
54 if ($yaml[0] != "PHP Class")
55 die('Sequence 0 failed');
57 if ($yaml[1] != "Basic YAML Loader")
58 die('Sequence 1 failed');
60 if ($yaml[2] != "Very Basic YAML Dumper")
61 die('Sequence 2 failed');
63 # A sequence of a sequence
64 if ($yaml[3] != array("YAML is so easy to learn.",
65 "Your config files will never be the same."))
66 die('Sequence 3 failed');
68 # Sequence of mappings
69 if ($yaml[4] != array("cpu" => "1.5ghz", "ram" => "1 gig",
70 "os" => "os x 10.4.1"))
71 die('Sequence 4 failed');
73 # Mapped sequence
74 if ($yaml['domains'] != array("yaml.org", "php.net"))
75 die("Key: 'domains' failed");
77 # A sequence like this.
78 if ($yaml[5] != array("program" => "Adium", "platform" => "OS X",
79 "type" => "Chat Client"))
80 die('Sequence 5 failed');
82 # A folded block as a mapped value
83 if ($yaml['no time'] != "There isn't any time for your tricks! \nDo you understand?")
84 die("Key: 'no time' failed");
86 # A literal block as a mapped value
87 if ($yaml['some time'] != "There is nothing but time\nfor your tricks.")
88 die("Key: 'some time' failed");
90 # Crazy combinations
91 if ($yaml['databases'] != array( array("name" => "spartan", "notes" =>
92 array( "Needs to be backed up",
93 "Needs to be normalized" ),
94 "type" => "mysql" )))
95 die("Key: 'databases' failed");
97 # You can be a bit tricky
98 if ($yaml["if: you'd"] != "like")
99 die("Key: 'if: you\'d' failed");
101 # Inline sequences
102 if ($yaml[6] != array("One", "Two", "Three", "Four"))
103 die("Sequence 6 failed");
105 # Nested Inline Sequences
106 if ($yaml[7] != array("One", array("Two", "And", "Three"), "Four", "Five"))
107 die("Sequence 7 failed");
109 # Nested Nested Inline Sequences
110 if ($yaml[8] != array( "This", array("Is", "Getting", array("Ridiculous", "Guys")),
111 "Seriously", array("Show", "Mercy")))
112 die("Sequence 8 failed");
114 # Inline mappings
115 if ($yaml[9] != array("name" => "chris", "age" => "young", "brand" => "lucky strike"))
116 die("Sequence 9 failed");
118 # Nested inline mappings
119 if ($yaml[10] != array("name" => "mark", "age" => "older than chris",
120 "brand" => array("marlboro", "lucky strike")))
121 die("Sequence 10 failed");
123 # References -- they're shaky, but functional
124 if ($yaml['dynamic languages'] != array('Perl', 'Python', 'PHP', 'Ruby'))
125 die("Key: 'dynamic languages' failed");
127 if ($yaml['compiled languages'] != array('C/C++', 'Java'))
128 die("Key: 'compiled languages' failed");
130 if ($yaml['all languages'] != array(
131 array('Perl', 'Python', 'PHP', 'Ruby'),
132 array('C/C++', 'Java')
134 die("Key: 'all languages' failed");
136 # Added in .2.2: Escaped quotes
137 if ($yaml[11] != "you know, this shouldn't work. but it does.")
138 die("Sequence 11 failed.");
140 if ($yaml[12] != "that's my value.")
141 die("Sequence 12 failed.");
143 if ($yaml[13] != "again, that's my value.")
144 die("Sequence 13 failed.");
146 if ($yaml[14] != "here's to \"quotes\", boss.")
147 die("Sequence 14 failed.");
150 print "spyc.yml parsed correctly\n";