InlineTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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. namespace Symfony\Component\Yaml\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Yaml\Inline;
  13. class InlineTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider getTestsForParse
  17. */
  18. public function testParse($yaml, $value)
  19. {
  20. $this->assertSame($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
  21. }
  22. /**
  23. * @dataProvider getTestsForParseWithMapObjects
  24. */
  25. public function testParseWithMapObjects($yaml, $value)
  26. {
  27. $actual = Inline::parse($yaml, false, false, true);
  28. $this->assertSame(serialize($value), serialize($actual));
  29. }
  30. /**
  31. * @dataProvider getTestsForDump
  32. */
  33. public function testDump($yaml, $value)
  34. {
  35. $this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
  36. $this->assertSame($value, Inline::parse(Inline::dump($value)), 'check consistency');
  37. }
  38. public function testDumpNumericValueWithLocale()
  39. {
  40. $locale = setlocale(LC_NUMERIC, 0);
  41. if (false === $locale) {
  42. $this->markTestSkipped('Your platform does not support locales.');
  43. }
  44. try {
  45. $requiredLocales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252');
  46. if (false === setlocale(LC_NUMERIC, $requiredLocales)) {
  47. $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $requiredLocales));
  48. }
  49. $this->assertEquals('1.2', Inline::dump(1.2));
  50. $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
  51. setlocale(LC_NUMERIC, $locale);
  52. } catch (\Exception $e) {
  53. setlocale(LC_NUMERIC, $locale);
  54. throw $e;
  55. }
  56. }
  57. public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()
  58. {
  59. $value = '686e444';
  60. $this->assertSame($value, Inline::parse(Inline::dump($value)));
  61. }
  62. /**
  63. * @group legacy
  64. * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
  65. */
  66. public function testParseScalarWithNonEscapedBlackslashShouldThrowException()
  67. {
  68. $this->assertSame('Foo\Var', Inline::parse('"Foo\Var"'));
  69. }
  70. /**
  71. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  72. */
  73. public function testParseScalarWithNonEscapedBlackslashAtTheEndShouldThrowException()
  74. {
  75. Inline::parse('"Foo\\"');
  76. }
  77. /**
  78. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  79. */
  80. public function testParseScalarWithIncorrectlyQuotedStringShouldThrowException()
  81. {
  82. $value = "'don't do somthin' like that'";
  83. Inline::parse($value);
  84. }
  85. /**
  86. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  87. */
  88. public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowException()
  89. {
  90. $value = '"don"t do somthin" like that"';
  91. Inline::parse($value);
  92. }
  93. /**
  94. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  95. */
  96. public function testParseInvalidMappingKeyShouldThrowException()
  97. {
  98. $value = '{ "foo " bar": "bar" }';
  99. Inline::parse($value);
  100. }
  101. /**
  102. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  103. */
  104. public function testParseInvalidMappingShouldThrowException()
  105. {
  106. Inline::parse('[foo] bar');
  107. }
  108. /**
  109. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  110. */
  111. public function testParseInvalidSequenceShouldThrowException()
  112. {
  113. Inline::parse('{ foo: bar } bar');
  114. }
  115. public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
  116. {
  117. $value = "'don''t do somthin'' like that'";
  118. $expect = "don't do somthin' like that";
  119. $this->assertSame($expect, Inline::parseScalar($value));
  120. }
  121. /**
  122. * @dataProvider getDataForParseReferences
  123. */
  124. public function testParseReferences($yaml, $expected)
  125. {
  126. $this->assertSame($expected, Inline::parse($yaml, false, false, false, array('var' => 'var-value')));
  127. }
  128. public function getDataForParseReferences()
  129. {
  130. return array(
  131. 'scalar' => array('*var', 'var-value'),
  132. 'list' => array('[ *var ]', array('var-value')),
  133. 'list-in-list' => array('[[ *var ]]', array(array('var-value'))),
  134. 'map-in-list' => array('[ { key: *var } ]', array(array('key' => 'var-value'))),
  135. 'embedded-mapping-in-list' => array('[ key: *var ]', array(array('key' => 'var-value'))),
  136. 'map' => array('{ key: *var }', array('key' => 'var-value')),
  137. 'list-in-map' => array('{ key: [*var] }', array('key' => array('var-value'))),
  138. 'map-in-map' => array('{ foo: { bar: *var } }', array('foo' => array('bar' => 'var-value'))),
  139. );
  140. }
  141. public function testParseMapReferenceInSequence()
  142. {
  143. $foo = array(
  144. 'a' => 'Steve',
  145. 'b' => 'Clark',
  146. 'c' => 'Brian',
  147. );
  148. $this->assertSame(array($foo), Inline::parse('[*foo]', false, false, false, array('foo' => $foo)));
  149. }
  150. /**
  151. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  152. * @expectedExceptionMessage A reference must contain at least one character.
  153. */
  154. public function testParseUnquotedAsterisk()
  155. {
  156. Inline::parse('{ foo: * }');
  157. }
  158. /**
  159. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  160. * @expectedExceptionMessage A reference must contain at least one character.
  161. */
  162. public function testParseUnquotedAsteriskFollowedByAComment()
  163. {
  164. Inline::parse('{ foo: * #foo }');
  165. }
  166. /**
  167. * @group legacy
  168. * @expectedDeprecation Not quoting the scalar "@foo " starting with "@" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.
  169. * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
  170. */
  171. public function testParseUnquotedScalarStartingWithReservedAtIndicator()
  172. {
  173. Inline::parse('{ foo: @foo }');
  174. }
  175. /**
  176. * @group legacy
  177. * @expectedDeprecation Not quoting the scalar "`foo " starting with "`" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.
  178. * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
  179. */
  180. public function testParseUnquotedScalarStartingWithReservedBacktickIndicator()
  181. {
  182. Inline::parse('{ foo: `foo }');
  183. }
  184. /**
  185. * @group legacy
  186. * @expectedDeprecation Not quoting the scalar "|foo " starting with "|" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.
  187. * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
  188. */
  189. public function testParseUnquotedScalarStartingWithLiteralStyleIndicator()
  190. {
  191. Inline::parse('{ foo: |foo }');
  192. }
  193. /**
  194. * @group legacy
  195. * @expectedDeprecation Not quoting the scalar ">foo " starting with ">" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.
  196. * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
  197. */
  198. public function testParseUnquotedScalarStartingWithFoldedStyleIndicator()
  199. {
  200. Inline::parse('{ foo: >foo }');
  201. }
  202. public function getScalarIndicators()
  203. {
  204. return array(array('|'), array('>'));
  205. }
  206. /**
  207. * @dataProvider getDataForIsHash
  208. */
  209. public function testIsHash($array, $expected)
  210. {
  211. $this->assertSame($expected, Inline::isHash($array));
  212. }
  213. public function getDataForIsHash()
  214. {
  215. return array(
  216. array(array(), false),
  217. array(array(1, 2, 3), false),
  218. array(array(2 => 1, 1 => 2, 0 => 3), true),
  219. array(array('foo' => 1, 'bar' => 2), true),
  220. );
  221. }
  222. public function getTestsForParse()
  223. {
  224. return array(
  225. array('', ''),
  226. array('null', null),
  227. array('false', false),
  228. array('true', true),
  229. array('12', 12),
  230. array('-12', -12),
  231. array('"quoted string"', 'quoted string'),
  232. array("'quoted string'", 'quoted string'),
  233. array('12.30e+02', 12.30e+02),
  234. array('0x4D2', 0x4D2),
  235. array('02333', 02333),
  236. array('.Inf', -log(0)),
  237. array('-.Inf', log(0)),
  238. array("'686e444'", '686e444'),
  239. array('686e444', 646e444),
  240. array('123456789123456789123456789123456789', '123456789123456789123456789123456789'),
  241. array('"foo\r\nbar"', "foo\r\nbar"),
  242. array("'foo#bar'", 'foo#bar'),
  243. array("'foo # bar'", 'foo # bar'),
  244. array("'#cfcfcf'", '#cfcfcf'),
  245. array('::form_base.html.twig', '::form_base.html.twig'),
  246. // Pre-YAML-1.2 booleans
  247. array("'y'", 'y'),
  248. array("'n'", 'n'),
  249. array("'yes'", 'yes'),
  250. array("'no'", 'no'),
  251. array("'on'", 'on'),
  252. array("'off'", 'off'),
  253. array('2007-10-30', gmmktime(0, 0, 0, 10, 30, 2007)),
  254. array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)),
  255. array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)),
  256. array('1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)),
  257. array('1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)),
  258. array('"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''),
  259. array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''),
  260. // sequences
  261. // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon
  262. array('[foo, http://urls.are/no/mappings, false, null, 12]', array('foo', 'http://urls.are/no/mappings', false, null, 12)),
  263. array('[ foo , bar , false , null , 12 ]', array('foo', 'bar', false, null, 12)),
  264. array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
  265. // mappings
  266. array('{foo:bar,bar:foo,false:false,null:null,integer:12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
  267. array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
  268. array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
  269. array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
  270. array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
  271. array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
  272. // nested sequences and mappings
  273. array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
  274. array('[foo, {bar: foo}]', array('foo', array('bar' => 'foo'))),
  275. array('{ foo: {bar: foo} }', array('foo' => array('bar' => 'foo'))),
  276. array('{ foo: [bar, foo] }', array('foo' => array('bar', 'foo'))),
  277. array('[ foo, [ bar, foo ] ]', array('foo', array('bar', 'foo'))),
  278. array('[{ foo: {bar: foo} }]', array(array('foo' => array('bar' => 'foo')))),
  279. array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))),
  280. array('[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')))),
  281. array('[foo, bar: { foo: bar }]', array('foo', '1' => array('bar' => array('foo' => 'bar')))),
  282. array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
  283. );
  284. }
  285. public function getTestsForParseWithMapObjects()
  286. {
  287. return array(
  288. array('', ''),
  289. array('null', null),
  290. array('false', false),
  291. array('true', true),
  292. array('12', 12),
  293. array('-12', -12),
  294. array('"quoted string"', 'quoted string'),
  295. array("'quoted string'", 'quoted string'),
  296. array('12.30e+02', 12.30e+02),
  297. array('0x4D2', 0x4D2),
  298. array('02333', 02333),
  299. array('.Inf', -log(0)),
  300. array('-.Inf', log(0)),
  301. array("'686e444'", '686e444'),
  302. array('686e444', 646e444),
  303. array('123456789123456789123456789123456789', '123456789123456789123456789123456789'),
  304. array('"foo\r\nbar"', "foo\r\nbar"),
  305. array("'foo#bar'", 'foo#bar'),
  306. array("'foo # bar'", 'foo # bar'),
  307. array("'#cfcfcf'", '#cfcfcf'),
  308. array('::form_base.html.twig', '::form_base.html.twig'),
  309. array('2007-10-30', gmmktime(0, 0, 0, 10, 30, 2007)),
  310. array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)),
  311. array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)),
  312. array('1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)),
  313. array('1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)),
  314. array('"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''),
  315. array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''),
  316. // sequences
  317. // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon
  318. array('[foo, http://urls.are/no/mappings, false, null, 12]', array('foo', 'http://urls.are/no/mappings', false, null, 12)),
  319. array('[ foo , bar , false , null , 12 ]', array('foo', 'bar', false, null, 12)),
  320. array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
  321. // mappings
  322. array('{foo:bar,bar:foo,false:false,null:null,integer:12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
  323. array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
  324. array('{foo: \'bar\', bar: \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
  325. array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
  326. array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (object) array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
  327. array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', (object) array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
  328. // nested sequences and mappings
  329. array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
  330. array('[foo, {bar: foo}]', array('foo', (object) array('bar' => 'foo'))),
  331. array('{ foo: {bar: foo} }', (object) array('foo' => (object) array('bar' => 'foo'))),
  332. array('{ foo: [bar, foo] }', (object) array('foo' => array('bar', 'foo'))),
  333. array('[ foo, [ bar, foo ] ]', array('foo', array('bar', 'foo'))),
  334. array('[{ foo: {bar: foo} }]', array((object) array('foo' => (object) array('bar' => 'foo')))),
  335. array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))),
  336. array('[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]', array('foo', (object) array('bar' => 'foo', 'foo' => array('foo', (object) array('bar' => 'foo'))), array('foo', (object) array('bar' => 'foo')))),
  337. array('[foo, bar: { foo: bar }]', array('foo', '1' => (object) array('bar' => (object) array('foo' => 'bar')))),
  338. array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', (object) array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
  339. array('{}', new \stdClass()),
  340. array('{ foo : bar, bar : {} }', (object) array('foo' => 'bar', 'bar' => new \stdClass())),
  341. array('{ foo : [], bar : {} }', (object) array('foo' => array(), 'bar' => new \stdClass())),
  342. array('{foo: \'bar\', bar: {} }', (object) array('foo' => 'bar', 'bar' => new \stdClass())),
  343. array('{\'foo\': \'bar\', "bar": {}}', (object) array('foo' => 'bar', 'bar' => new \stdClass())),
  344. array('{\'foo\': \'bar\', "bar": \'{}\'}', (object) array('foo' => 'bar', 'bar' => '{}')),
  345. array('[foo, [{}, {}]]', array('foo', array(new \stdClass(), new \stdClass()))),
  346. array('[foo, [[], {}]]', array('foo', array(array(), new \stdClass()))),
  347. array('[foo, [[{}, {}], {}]]', array('foo', array(array(new \stdClass(), new \stdClass()), new \stdClass()))),
  348. array('[foo, {bar: {}}]', array('foo', '1' => (object) array('bar' => new \stdClass()))),
  349. );
  350. }
  351. public function getTestsForDump()
  352. {
  353. return array(
  354. array('null', null),
  355. array('false', false),
  356. array('true', true),
  357. array('12', 12),
  358. array("'quoted string'", 'quoted string'),
  359. array('!!float 1230', 12.30e+02),
  360. array('1234', 0x4D2),
  361. array('1243', 02333),
  362. array('.Inf', -log(0)),
  363. array('-.Inf', log(0)),
  364. array("'686e444'", '686e444'),
  365. array('"foo\r\nbar"', "foo\r\nbar"),
  366. array("'foo#bar'", 'foo#bar'),
  367. array("'foo # bar'", 'foo # bar'),
  368. array("'#cfcfcf'", '#cfcfcf'),
  369. array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''),
  370. array("'-dash'", '-dash'),
  371. array("'-'", '-'),
  372. // Pre-YAML-1.2 booleans
  373. array("'y'", 'y'),
  374. array("'n'", 'n'),
  375. array("'yes'", 'yes'),
  376. array("'no'", 'no'),
  377. array("'on'", 'on'),
  378. array("'off'", 'off'),
  379. // sequences
  380. array('[foo, bar, false, null, 12]', array('foo', 'bar', false, null, 12)),
  381. array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
  382. // mappings
  383. array('{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
  384. array('{ foo: bar, bar: \'foo: bar\' }', array('foo' => 'bar', 'bar' => 'foo: bar')),
  385. // nested sequences and mappings
  386. array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
  387. array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))),
  388. array('{ foo: { bar: foo } }', array('foo' => array('bar' => 'foo'))),
  389. array('[foo, { bar: foo }]', array('foo', array('bar' => 'foo'))),
  390. array('[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')))),
  391. array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
  392. array('{ foo: { bar: { 1: 2, baz: 3 } } }', array('foo' => array('bar' => array(1 => 2, 'baz' => 3)))),
  393. );
  394. }
  395. /**
  396. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  397. * @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}.
  398. */
  399. public function testNotSupportedMissingValue()
  400. {
  401. Inline::parse('{this, is not, supported}');
  402. }
  403. public function testVeryLongQuotedStrings()
  404. {
  405. $longStringWithQuotes = str_repeat("x\r\n\\\"x\"x", 1000);
  406. $yamlString = Inline::dump(array('longStringWithQuotes' => $longStringWithQuotes));
  407. $arrayFromYaml = Inline::parse($yamlString);
  408. $this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
  409. }
  410. public function testBooleanMappingKeysAreConvertedToStrings()
  411. {
  412. $this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}'));
  413. $this->assertSame(array('true' => 'foo'), Inline::parse('{true: foo}'));
  414. }
  415. public function testTheEmptyStringIsAValidMappingKey()
  416. {
  417. $this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }'));
  418. }
  419. /**
  420. * @expectedException \Symfony\Component\Yaml\Exception\ParseException
  421. * @expectedExceptionMessage Unexpected end of line, expected one of ",}".
  422. */
  423. public function testUnfinishedInlineMap()
  424. {
  425. Inline::parse("{abc: 'def'");
  426. }
  427. }