Network 10 changes
[bus.git] / spyc / tests / .svn / text-base / ParseTest.php.svn-base
maxious 1 <?php
2
3 require_once 'PHPUnit/Framework.php';
4 require_once ("../spyc.php");
5
6 class ParseTest extends PHPUnit_Framework_TestCase {
7
8 protected $yaml;
9
10 protected function setUp() {
11 $this->yaml = spyc_load_file('../spyc.yaml');
12 }
13
14 public function testMergeHashKeys() {
15 $Expected = array (
16 array ('step' => array('instrument' => 'Lasik 2000', 'pulseEnergy' => 5.4, 'pulseDuration' => 12, 'repetition' => 1000, 'spotSize' => '1mm')),
17 array ('step' => array('instrument' => 'Lasik 2000', 'pulseEnergy' => 5.4, 'pulseDuration' => 12, 'repetition' => 1000, 'spotSize' => '2mm')),
18 );
19 $Actual = spyc_load_file ('indent_1.yaml');
20 $this->assertEquals ($Expected, $Actual['steps']);
21 }
22
23 public function testDeathMasks() {
24 $Expected = array ('sad' => 2, 'magnificent' => 4);
25 $Actual = spyc_load_file ('indent_1.yaml');
26 $this->assertEquals ($Expected, $Actual['death masks are']);
27 }
28
29 public function testDevDb() {
30 $Expected = array ('adapter' => 'mysql', 'host' => 'localhost', 'database' => 'rails_dev');
31 $Actual = spyc_load_file ('indent_1.yaml');
32 $this->assertEquals ($Expected, $Actual['development']);
33 }
34
35 public function testNumericKey() {
36 $this->assertEquals ("Ooo, a numeric key!", $this->yaml[1040]);
37 }
38
39 public function testMappingsString() {
40 $this->assertEquals ("Anyone's name, really.", $this->yaml['String']);
41 }
42
43 public function testMappingsInt() {
44 $this->assertSame (13, $this->yaml['Int']);
45 }
46
47 public function testMappingsBooleanTrue() {
48 $this->assertSame (true, $this->yaml['True']);
49 }
50
51 public function testMappingsBooleanFalse() {
52 $this->assertSame (false, $this->yaml['False']);
53 }
54
55 public function testMappingsZero() {
56 $this->assertSame (0, $this->yaml['Zero']);
57 }
58
59 public function testMappingsNull() {
60 $this->assertSame (null, $this->yaml['Null']);
61 }
62
63 public function testMappingsFloat() {
64 $this->assertSame (5.34, $this->yaml['Float']);
65 }
66
67 public function testSeq0() {
68 $this->assertEquals ("PHP Class", $this->yaml[0]);
69 }
70
71 public function testSeq1() {
72 $this->assertEquals ("Basic YAML Loader", $this->yaml[1]);
73 }
74
75 public function testSeq2() {
76 $this->assertEquals ("Very Basic YAML Dumper", $this->yaml[2]);
77 }
78
79 public function testSeq3() {
80 $this->assertEquals (array("YAML is so easy to learn.",
81 "Your config files will never be the same."), $this->yaml[3]);
82 }
83
84 public function testSeqMap() {
85 $this->assertEquals (array("cpu" => "1.5ghz", "ram" => "1 gig",
86 "os" => "os x 10.4.1"), $this->yaml[4]);
87 }
88
89 public function testMappedSequence() {
90 $this->assertEquals (array("yaml.org", "php.net"), $this->yaml['domains']);
91 }
92
93 public function testAnotherSequence() {
94 $this->assertEquals (array("program" => "Adium", "platform" => "OS X",
95 "type" => "Chat Client"), $this->yaml[5]);
96 }
97
98 public function testFoldedBlock() {
99 $this->assertEquals ("There isn't any time for your tricks!\nDo you understand?", $this->yaml['no time']);
100 }
101
102 public function testLiteralAsMapped() {
103 $this->assertEquals ("There is nothing but time\nfor your tricks.", $this->yaml['some time']);
104 }
105
106 public function testCrazy() {
107 $this->assertEquals (array( array("name" => "spartan", "notes" =>
108 array( "Needs to be backed up",
109 "Needs to be normalized" ),
110 "type" => "mysql" )), $this->yaml['databases']);
111 }
112
113 public function testColons() {
114 $this->assertEquals ("like", $this->yaml["if: you'd"]);
115 }
116
117 public function testInline() {
118 $this->assertEquals (array("One", "Two", "Three", "Four"), $this->yaml[6]);
119 }
120
121 public function testNestedInline() {
122 $this->assertEquals (array("One", array("Two", "And", "Three"), "Four", "Five"), $this->yaml[7]);
123 }
124
125 public function testNestedNestedInline() {
126 $this->assertEquals (array( "This", array("Is", "Getting", array("Ridiculous", "Guys")),
127 "Seriously", array("Show", "Mercy")), $this->yaml[8]);
128 }
129
130 public function testInlineMappings() {
131 $this->assertEquals (array("name" => "chris", "age" => "young", "brand" => "lucky strike"), $this->yaml[9]);
132 }
133
134 public function testNestedInlineMappings() {
135 $this->assertEquals (array("name" => "mark", "age" => "older than chris",
136 "brand" => array("marlboro", "lucky strike")), $this->yaml[10]);
137 }
138
139 public function testReferences() {
140 $this->assertEquals (array('Perl', 'Python', 'PHP', 'Ruby'), $this->yaml['dynamic languages']);
141 }
142
143 public function testReferences2() {
144 $this->assertEquals (array('C/C++', 'Java'), $this->yaml['compiled languages']);
145 }
146
147 public function testReferences3() {
148 $this->assertEquals (array(
149 array('Perl', 'Python', 'PHP', 'Ruby'),
150 array('C/C++', 'Java')
151 ), $this->yaml['all languages']);
152 }
153
154 public function testEscapedQuotes() {
155 $this->assertEquals ("you know, this shouldn't work. but it does.", $this->yaml[11]);
156 }
157
158 public function testEscapedQuotes_2() {
159 $this->assertEquals ( "that's my value.", $this->yaml[12]);
160 }
161
162 public function testEscapedQuotes_3() {
163 $this->assertEquals ("again, that's my value.", $this->yaml[13]);
164 }
165
166 public function testQuotes() {
167 $this->assertEquals ("here's to \"quotes\", boss.", $this->yaml[14]);
168 }
169
170 public function testQuoteSequence() {
171 $this->assertEquals ( array( 'name' => "Foo, Bar's", 'age' => 20), $this->yaml[15]);
172 }
173
174 public function testShortSequence() {
175 $this->assertEquals (array( 0 => "a", 1 => array (0 => 1, 1 => 2), 2 => "b"), $this->yaml[16]);
176 }
177
178 public function testHash_1() {
179 $this->assertEquals ("Hash", $this->yaml['hash_1']);
180 }
181
182 public function testHash_2() {
183 $this->assertEquals ('Hash #and a comment', $this->yaml['hash_2']);
184 }
185
186 public function testHash_3() {
187 $this->assertEquals ('Hash (#) can appear in key too', $this->yaml['hash#3']);
188 }
189
190 public function testEndloop() {
191 $this->assertEquals ("Does this line in the end indeed make Spyc go to an infinite loop?", $this->yaml['endloop']);
192 }
193
194 public function testReallyLargeNumber() {
195 $this->assertEquals ('115792089237316195423570985008687907853269984665640564039457584007913129639936', $this->yaml['a_really_large_number']);
196 }
197
198 public function testFloatWithZeros() {
199 $this->assertSame ('1.0', $this->yaml['float_test']);
200 }
201
202 public function testFloatWithQuotes() {
203 $this->assertSame ('1.0', $this->yaml['float_test_with_quotes']);
204 }
205
206 public function testFloatInverse() {
207 $this->assertEquals ('001', $this->yaml['float_inverse_test']);
208 }
209
210 public function testIntArray() {
211 $this->assertEquals (array (1, 2, 3), $this->yaml['int array']);
212 }
213
214 public function testArrayOnSeveralLines() {
215 $this->assertEquals (array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19), $this->yaml['array on several lines']);
216 }
217
218 public function testmoreLessKey() {
219