blob: 3e707dfe87700d595738ed22402309b4407e0c8a [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2
3function roundTrip($a) { return Spyc::YAMLLoad(Spyc::YAMLDump(array('x' => $a))); }
4
5
6class RoundTripTest extends PHPUnit_Framework_TestCase {
7
8 protected function setUp() {
9 }
10
11 public function testNull() {
12 $this->assertEquals (array ('x' => null), roundTrip (null));
13 }
14
15 public function testY() {
16 $this->assertEquals (array ('x' => 'y'), roundTrip ('y'));
17 }
18
19 public function testExclam() {
20 $this->assertEquals (array ('x' => '!yeah'), roundTrip ('!yeah'));
21 }
22
23 public function test5() {
24 $this->assertEquals (array ('x' => '5'), roundTrip ('5'));
25 }
26
27 public function testSpaces() {
28 $this->assertEquals (array ('x' => 'x '), roundTrip ('x '));
29 }
30
31 public function testApostrophes() {
32 $this->assertEquals (array ('x' => "'biz'"), roundTrip ("'biz'"));
33 }
34
35 public function testNewLines() {
36 $this->assertEquals (array ('x' => "\n"), roundTrip ("\n"));
37 }
38
39 public function testHashes() {
40 $this->assertEquals (array ('x' => array ("#color" => '#fff')), roundTrip (array ("#color" => '#fff')));
41 }
42
43 public function testPreserveString() {
44 $result1 = roundTrip ('0');
45 $result2 = roundTrip ('true');
46 $this->assertTrue (is_string ($result1['x']));
47 $this->assertTrue (is_string ($result2['x']));
48 }
49
50 public function testPreserveBool() {
51 $result = roundTrip (true);
52 $this->assertTrue (is_bool ($result['x']));
53 }
54
55 public function testPreserveInteger() {
56 $result = roundTrip (0);
57 $this->assertTrue (is_int ($result['x']));
58 }
59
60 public function testWordWrap() {
61 $this->assertEquals (array ('x' => "aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), roundTrip ("aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
62 }
63
64 public function testABCD() {
65 $this->assertEquals (array ('a', 'b', 'c', 'd'), Spyc::YAMLLoad(Spyc::YAMLDump(array('a', 'b', 'c', 'd'))));
66 }
67
68 public function testABCD2() {
69 $a = array('a', 'b', 'c', 'd'); // Create a simple list
70 $b = Spyc::YAMLDump($a); // Dump the list as YAML
71 $c = Spyc::YAMLLoad($b); // Load the dumped YAML
72 $d = Spyc::YAMLDump($c); // Re-dump the data
73 $this->assertSame($b, $d);
74 }
75
76}