Less strtolower, more in_array()
[spyc.git] / tests / ParseTest.php
blob9a204d38fe90b9ee226ef4b8312b4a83402ab775
1 <?php
3 require_once 'PHPUnit/Framework.php';
4 require_once ("../spyc.php");
6 class ParseTest extends PHPUnit_Framework_TestCase {
8 protected $yaml;
10 protected function setUp() {
11 $this->yaml = Spyc::YAMLLoad('../spyc.yaml');
14 public function testNumericKey() {
15 $this->assertEquals ("Ooo, a numeric key!", $this->yaml[1040]);
18 public function testMappingsString() {
19 $this->assertEquals ("Anyone's name, really.", $this->yaml['String']);
22 public function testMappingsInt() {
23 $this->assertSame (13, $this->yaml['Int']);
26 public function testMappingsBooleanTrue() {
27 $this->assertSame (true, $this->yaml['True']);
30 public function testMappingsBooleanFalse() {
31 $this->assertSame (false, $this->yaml['False']);
34 public function testMappingsZero() {
35 $this->assertSame (0, $this->yaml['Zero']);
38 public function testMappingsNull() {
39 $this->assertSame (null, $this->yaml['Null']);
42 public function testMappingsFloat() {
43 $this->assertSame (5.34, $this->yaml['Float']);
46 public function testSeq0() {
47 $this->assertEquals ("PHP Class", $this->yaml[0]);
50 public function testSeq1() {
51 $this->assertEquals ("Basic YAML Loader", $this->yaml[1]);
54 public function testSeq2() {
55 $this->assertEquals ("Very Basic YAML Dumper", $this->yaml[2]);
58 public function testSeq3() {
59 $this->assertEquals (array("YAML is so easy to learn.",
60 "Your config files will never be the same."), $this->yaml[3]);
63 public function testSeqMap() {
64 $this->assertEquals (array("cpu" => "1.5ghz", "ram" => "1 gig",
65 "os" => "os x 10.4.1"), $this->yaml[4]);
68 public function testMappedSequence() {
69 $this->assertEquals (array("yaml.org", "php.net"), $this->yaml['domains']);
72 public function testAnotherSequence() {
73 $this->assertEquals (array("program" => "Adium", "platform" => "OS X",
74 "type" => "Chat Client"), $this->yaml[5]);
77 public function testFoldedBlock() {
78 $this->assertEquals ("There isn't any time for your tricks!\nDo you understand?", $this->yaml['no time']);
81 public function testLiteralAsMapped() {
82 $this->assertEquals ("There is nothing but time\nfor your tricks.", $this->yaml['some time']);
85 public function testCrazy() {
86 $this->assertEquals (array( array("name" => "spartan", "notes" =>
87 array( "Needs to be backed up",
88 "Needs to be normalized" ),
89 "type" => "mysql" )), $this->yaml['databases']);
92 public function testColons() {
93 $this->assertEquals ("like", $this->yaml["if: you'd"]);
96 public function testInline() {
97 $this->assertEquals (array("One", "Two", "Three", "Four"), $this->yaml[6]);
100 public function testNestedInline() {
101 $this->assertEquals (array("One", array("Two", "And", "Three"), "Four", "Five"), $this->yaml[7]);
104 public function testNestedNestedInline() {
105 $this->assertEquals (array( "This", array("Is", "Getting", array("Ridiculous", "Guys")),
106 "Seriously", array("Show", "Mercy")), $this->yaml[8]);
109 public function testInlineMappings() {
110 $this->assertEquals (array("name" => "chris", "age" => "young", "brand" => "lucky strike"), $this->yaml[9]);
113 public function testNestedInlineMappings() {
114 $this->assertEquals (array("name" => "mark", "age" => "older than chris",
115 "brand" => array("marlboro", "lucky strike")), $this->yaml[10]);
118 public function testReferences() {
119 $this->assertEquals (array('Perl', 'Python', 'PHP', 'Ruby'), $this->yaml['dynamic languages']);
122 public function testReferences2() {
123 $this->assertEquals (array('C/C++', 'Java'), $this->yaml['compiled languages']);
126 public function testReferences3() {
127 $this->assertEquals (array(
128 array('Perl', 'Python', 'PHP', 'Ruby'),
129 array('C/C++', 'Java')
130 ), $this->yaml['all languages']);
133 public function testEscapedQuotes() {
134 $this->assertEquals ("you know, this shouldn't work. but it does.", $this->yaml[11]);
137 public function testEscapedQuotes_2() {
138 $this->assertEquals ( "that's my value.", $this->yaml[12]);
141 public function testEscapedQuotes_3() {
142 $this->assertEquals ("again, that's my value.", $this->yaml[13]);
145 public function testQuotes() {
146 $this->assertEquals ("here's to \"quotes\", boss.", $this->yaml[14]);
149 public function testQuoteSequence() {
150 $this->assertEquals ( array( 'name' => "Foo, Bar's", 'age' => 20), $this->yaml[15]);
153 public function testShortSequence() {
154 $this->assertEquals (array( 0 => "a", 1 => array (0 => 1, 1 => 2), 2 => "b"), $this->yaml[16]);
157 public function testHash_1() {
158 $this->assertEquals ("Hash", $this->yaml['hash_1']);
161 public function testHash_2() {
162 $this->assertEquals ('Hash #and a comment', $this->yaml['hash_2']);
165 public function testHash_3() {
166 $this->assertEquals ('Hash (#) can appear in key too', $this->yaml['hash#3']);
169 public function testEndloop() {
170 $this->assertEquals ("Does this line in the end indeed make Spyc go to an infinite loop?", $this->yaml['endloop']);
173 public function testReallyLargeNumber() {
174 $this->assertEquals ('115792089237316195423570985008687907853269984665640564039457584007913129639936', $this->yaml['a_really_large_number']);
177 public function testFloatWithZeros() {
178 $this->assertSame ('1.0', $this->yaml['float_test']);
181 public function testFloatWithQuotes() {
182 $this->assertSame ('1.0', $this->yaml['float_test_with_quotes']);
185 public function testFloatInverse() {
186 $this->assertEquals ('001', $this->yaml['float_inverse_test']);
189 public function testIntArray() {
190 $this->assertEquals (array (1, 2, 3), $this->yaml['int array']);
193 public function testArrayOnSeveralLines() {
194 $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']);
197 public function testmoreLessKey() {
198 $this->assertEquals ('<value>', $this->yaml['morelesskey']);
201 public function testArrayOfZero() {
202 $this->assertSame (array(0), $this->yaml['array_of_zero']);
205 public function testSophisticatedArrayOfZero() {
206 $this->assertSame (array('rx' => array ('tx' => array (0))), $this->yaml['sophisticated_array_of_zero']);
209 public function testSwitches() {
210 $this->assertEquals (array (array ('row' => 0, 'col' => 0, 'func' => array ('tx' => array(0, 1)))), $this->yaml['switches']);