/[web]/fidd/lib/fabpot-yaml/test/sfYamlInlineTest.php
ViewVC logotype

Contents of /fidd/lib/fabpot-yaml/test/sfYamlInlineTest.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1081 - (show annotations) (download)
Mon May 14 09:16:32 2012 UTC (11 years, 11 months ago) by rda
File size: 5479 byte(s)
add library and var dir
1 <?php
2
3 /*
4 * This file is part of the symfony package.
5 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 require_once(dirname(__FILE__).'/lime/lime.php');
12 require_once(dirname(__FILE__).'/../lib/sfYaml.php');
13 require_once(dirname(__FILE__).'/../lib/sfYamlInline.php');
14
15 sfYaml::setSpecVersion('1.1');
16
17 $t = new lime_test(124);
18
19 // ::load()
20 $t->diag('::load()');
21
22 $testsForLoad = array(
23 '' => '',
24 'null' => null,
25 'false' => false,
26 'true' => true,
27 '12' => 12,
28 '"quoted string"' => 'quoted string',
29 "'quoted string'" => 'quoted string',
30 '12.30e+02' => 12.30e+02,
31 '0x4D2' => 0x4D2,
32 '02333' => 02333,
33 '.Inf' => -log(0),
34 '-.Inf' => log(0),
35 '123456789123456789' => '123456789123456789',
36 '"foo\r\nbar"' => "foo\r\nbar",
37 "'foo#bar'" => 'foo#bar',
38 "'foo # bar'" => 'foo # bar',
39 "'#cfcfcf'" => '#cfcfcf',
40
41 '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007),
42 '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007),
43 '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007),
44
45 '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'',
46 "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'',
47
48 // sequences
49 // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon
50 '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12),
51 '[ foo , bar , false , null , 12 ]' => array('foo', 'bar', false, null, 12),
52 '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'),
53
54 // mappings
55 '{foo:bar,bar:foo,false:false,null:null,integer:12}' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12),
56 '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12),
57 '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'),
58 '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'),
59 '{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'),
60 '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'),
61
62 // nested sequences and mappings
63 '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')),
64 '[foo, {bar: foo}]' => array('foo', array('bar' => 'foo')),
65 '{ foo: {bar: foo} }' => array('foo' => array('bar' => 'foo')),
66 '{ foo: [bar, foo] }' => array('foo' => array('bar', 'foo')),
67
68 '[ foo, [ bar, foo ] ]' => array('foo', array('bar', 'foo')),
69
70 '[{ foo: {bar: foo} }]' => array(array('foo' => array('bar' => 'foo'))),
71
72 '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')),
73
74 '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))),
75
76 '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar'))),
77 );
78
79 foreach ($testsForLoad as $yaml => $value)
80 {
81 $t->is_deeply(sfYamlInline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
82 }
83
84 $testsForDump = array(
85 'null' => null,
86 'false' => false,
87 'true' => true,
88 '12' => 12,
89 "'quoted string'" => 'quoted string',
90 '12.30e+02' => 12.30e+02,
91 '1234' => 0x4D2,
92 '1243' => 02333,
93 '.Inf' => -log(0),
94 '-.Inf' => log(0),
95 '"foo\r\nbar"' => "foo\r\nbar",
96 "'foo#bar'" => 'foo#bar',
97 "'foo # bar'" => 'foo # bar',
98 "'#cfcfcf'" => '#cfcfcf',
99
100 "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'',
101
102 // sequences
103 '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12),
104 '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'),
105
106 // mappings
107 '{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12),
108 '{ foo: bar, bar: \'foo: bar\' }' => array('foo' => 'bar', 'bar' => 'foo: bar'),
109
110 // nested sequences and mappings
111 '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')),
112
113 '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')),
114
115 '{ foo: { bar: foo } }' => array('foo' => array('bar' => 'foo')),
116
117 '[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')),
118
119 '[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))),
120 );
121
122 // ::dump()
123 $t->diag('::dump()');
124 foreach ($testsForDump as $yaml => $value)
125 {
126 $t->is(sfYamlInline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
127 }
128
129 foreach ($testsForLoad as $yaml => $value)
130 {
131 if ($value == 1230)
132 {
133 continue;
134 }
135
136 $t->is_deeply(sfYamlInline::load(sfYamlInline::dump($value)), $value, 'check consistency');
137 }
138
139 foreach ($testsForDump as $yaml => $value)
140 {
141 if ($value == 1230)
142 {
143 continue;
144 }
145
146 $t->is_deeply(sfYamlInline::load(sfYamlInline::dump($value)), $value, 'check consistency');
147 }

  ViewVC Help
Powered by ViewVC 1.1.30