YtsSpecificationExamples.yml

drupal/core/vendor/symfony/yaml/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml

File

drupal/core/vendor/symfony/yaml/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml
View source
  1. --- %YAML:1.0
  2. test: Sequence of scalars
  3. spec: 2.1
  4. yaml: |
  5. - Mark McGwire
  6. - Sammy Sosa
  7. - Ken Griffey
  8. php: |
  9. array('Mark McGwire', 'Sammy Sosa', 'Ken Griffey')
  10. ---
  11. test: Mapping of scalars to scalars
  12. spec: 2.2
  13. yaml: |
  14. hr: 65
  15. avg: 0.278
  16. rbi: 147
  17. php: |
  18. array('hr' => 65, 'avg' => 0.278, 'rbi' => 147)
  19. ---
  20. test: Mapping of scalars to sequences
  21. spec: 2.3
  22. yaml: |
  23. american:
  24. - Boston Red Sox
  25. - Detroit Tigers
  26. - New York Yankees
  27. national:
  28. - New York Mets
  29. - Chicago Cubs
  30. - Atlanta Braves
  31. php: |
  32. array('american' =>
  33. array( 'Boston Red Sox', 'Detroit Tigers',
  34. 'New York Yankees' ),
  35. 'national' =>
  36. array( 'New York Mets', 'Chicago Cubs',
  37. 'Atlanta Braves' )
  38. )
  39. ---
  40. test: Sequence of mappings
  41. spec: 2.4
  42. yaml: |
  43. -
  44. name: Mark McGwire
  45. hr: 65
  46. avg: 0.278
  47. -
  48. name: Sammy Sosa
  49. hr: 63
  50. avg: 0.288
  51. php: |
  52. array(
  53. array('name' => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278),
  54. array('name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288)
  55. )
  56. ---
  57. test: Legacy A5
  58. todo: true
  59. spec: legacy_A5
  60. yaml: |
  61. ?
  62. - New York Yankees
  63. - Atlanta Braves
  64. :
  65. - 2001-07-02
  66. - 2001-08-12
  67. - 2001-08-14
  68. ?
  69. - Detroit Tigers
  70. - Chicago Cubs
  71. :
  72. - 2001-07-23
  73. perl-busted: >
  74. YAML.pm will be able to emulate this behavior soon. In this regard
  75. it may be somewhat more correct than Python's native behaviour which
  76. can only use tuples as mapping keys. PyYAML will also need to figure
  77. out some clever way to roundtrip structured keys.
  78. python: |
  79. [
  80. {
  81. ('New York Yankees', 'Atlanta Braves'):
  82. [yaml.timestamp('2001-07-02'),
  83. yaml.timestamp('2001-08-12'),
  84. yaml.timestamp('2001-08-14')],
  85. ('Detroit Tigers', 'Chicago Cubs'):
  86. [yaml.timestamp('2001-07-23')]
  87. }
  88. ]
  89. ruby: |
  90. {
  91. [ 'New York Yankees', 'Atlanta Braves' ] =>
  92. [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ],
  93. [ 'Detroit Tigers', 'Chicago Cubs' ] =>
  94. [ Date.new( 2001, 7, 23 ) ]
  95. }
  96. syck: |
  97. struct test_node seq1[] = {
  98. { T_STR, 0, "New York Yankees" },
  99. { T_STR, 0, "Atlanta Braves" },
  100. end_node
  101. };
  102. struct test_node seq2[] = {
  103. { T_STR, 0, "2001-07-02" },
  104. { T_STR, 0, "2001-08-12" },
  105. { T_STR, 0, "2001-08-14" },
  106. end_node
  107. };
  108. struct test_node seq3[] = {
  109. { T_STR, 0, "Detroit Tigers" },
  110. { T_STR, 0, "Chicago Cubs" },
  111. end_node
  112. };
  113. struct test_node seq4[] = {
  114. { T_STR, 0, "2001-07-23" },
  115. end_node
  116. };
  117. struct test_node map[] = {
  118. { T_SEQ, 0, 0, seq1 },
  119. { T_SEQ, 0, 0, seq2 },
  120. { T_SEQ, 0, 0, seq3 },
  121. { T_SEQ, 0, 0, seq4 },
  122. end_node
  123. };
  124. struct test_node stream[] = {
  125. { T_MAP, 0, 0, map },
  126. end_node
  127. };
  128. ---
  129. test: Sequence of sequences
  130. spec: 2.5
  131. yaml: |
  132. - [ name , hr , avg ]
  133. - [ Mark McGwire , 65 , 0.278 ]
  134. - [ Sammy Sosa , 63 , 0.288 ]
  135. php: |
  136. array(
  137. array( 'name', 'hr', 'avg' ),
  138. array( 'Mark McGwire', 65, 0.278 ),
  139. array( 'Sammy Sosa', 63, 0.288 )
  140. )
  141. ---
  142. test: Mapping of mappings
  143. todo: true
  144. spec: 2.6
  145. yaml: |
  146. Mark McGwire: {hr: 65, avg: 0.278}
  147. Sammy Sosa: {
  148. hr: 63,
  149. avg: 0.288
  150. }
  151. php: |
  152. array(
  153. 'Mark McGwire' =>
  154. array( 'hr' => 65, 'avg' => 0.278 ),
  155. 'Sammy Sosa' =>
  156. array( 'hr' => 63, 'avg' => 0.288 )
  157. )
  158. ---
  159. test: Two documents in a stream each with a leading comment
  160. todo: true
  161. spec: 2.7
  162. yaml: |
  163. # Ranking of 1998 home runs
  164. ---
  165. - Mark McGwire
  166. - Sammy Sosa
  167. - Ken Griffey
  168. # Team ranking
  169. ---
  170. - Chicago Cubs
  171. - St Louis Cardinals
  172. ruby: |
  173. y = YAML::Stream.new
  174. y.add( [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] )
  175. y.add( [ 'Chicago Cubs', 'St Louis Cardinals' ] )
  176. documents: 2
  177. ---
  178. test: Play by play feed from a game
  179. todo: true
  180. spec: 2.8
  181. yaml: |
  182. ---
  183. time: 20:03:20
  184. player: Sammy Sosa
  185. action: strike (miss)
  186. ...
  187. ---
  188. time: 20:03:47
  189. player: Sammy Sosa
  190. action: grand slam
  191. ...
  192. perl: |
  193. [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ]
  194. documents: 2
  195. ---
  196. test: Single document with two comments
  197. spec: 2.9
  198. yaml: |
  199. hr: # 1998 hr ranking
  200. - Mark McGwire
  201. - Sammy Sosa
  202. rbi:
  203. # 1998 rbi ranking
  204. - Sammy Sosa
  205. - Ken Griffey
  206. php: |
  207. array(
  208. 'hr' => array( 'Mark McGwire', 'Sammy Sosa' ),
  209. 'rbi' => array( 'Sammy Sosa', 'Ken Griffey' )
  210. )
  211. ---
  212. test: Node for Sammy Sosa appears twice in this document
  213. spec: 2.10
  214. yaml: |
  215. ---
  216. hr:
  217. - Mark McGwire
  218. # Following node labeled SS
  219. - &SS Sammy Sosa
  220. rbi:
  221. - *SS # Subsequent occurance
  222. - Ken Griffey
  223. php: |
  224. array(
  225. 'hr' =>
  226. array('Mark McGwire', 'Sammy Sosa'),
  227. 'rbi' =>
  228. array('Sammy Sosa', 'Ken Griffey')
  229. )
  230. ---
  231. test: Mapping between sequences
  232. todo: true
  233. spec: 2.11
  234. yaml: |
  235. ? # PLAY SCHEDULE
  236. - Detroit Tigers
  237. - Chicago Cubs
  238. :
  239. - 2001-07-23
  240. ? [ New York Yankees,
  241. Atlanta Braves ]
  242. : [ 2001-07-02, 2001-08-12,
  243. 2001-08-14 ]
  244. ruby: |
  245. {
  246. [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ],
  247. [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ]
  248. }
  249. syck: |
  250. struct test_node seq1[] = {
  251. { T_STR, 0, "New York Yankees" },
  252. { T_STR, 0, "Atlanta Braves" },
  253. end_node
  254. };
  255. struct test_node seq2[] = {
  256. { T_STR, 0, "2001-07-02" },
  257. { T_STR, 0, "2001-08-12" },
  258. { T_STR, 0, "2001-08-14" },
  259. end_node
  260. };
  261. struct test_node seq3[] = {
  262. { T_STR, 0, "Detroit Tigers" },
  263. { T_STR, 0, "Chicago Cubs" },
  264. end_node
  265. };
  266. struct test_node seq4[] = {
  267. { T_STR, 0, "2001-07-23" },
  268. end_node
  269. };
  270. struct test_node map[] = {
  271. { T_SEQ, 0, 0, seq3 },
  272. { T_SEQ, 0, 0, seq4 },
  273. { T_SEQ, 0, 0, seq1 },
  274. { T_SEQ, 0, 0, seq2 },
  275. end_node
  276. };
  277. struct test_node stream[] = {
  278. { T_MAP, 0, 0, map },
  279. end_node
  280. };
  281. ---
  282. test: Sequence key shortcut
  283. spec: 2.12
  284. yaml: |
  285. ---
  286. # products purchased
  287. - item : Super Hoop
  288. quantity: 1
  289. - item : Basketball
  290. quantity: 4
  291. - item : Big Shoes
  292. quantity: 1
  293. php: |
  294. array (
  295. array (
  296. 'item' => 'Super Hoop',
  297. 'quantity' => 1,
  298. ),
  299. array (
  300. 'item' => 'Basketball',
  301. 'quantity' => 4,
  302. ),
  303. array (
  304. 'item' => 'Big Shoes',
  305. 'quantity' => 1,
  306. )
  307. )
  308. perl: |
  309. [
  310. { item => 'Super Hoop', quantity => 1 },
  311. { item => 'Basketball', quantity => 4 },
  312. { item => 'Big Shoes', quantity => 1 }
  313. ]
  314. ruby: |
  315. [
  316. { 'item' => 'Super Hoop', 'quantity' => 1 },
  317. { 'item' => 'Basketball', 'quantity' => 4 },
  318. { 'item' => 'Big Shoes', 'quantity' => 1 }
  319. ]
  320. python: |
  321. [
  322. { 'item': 'Super Hoop', 'quantity': 1 },
  323. { 'item': 'Basketball', 'quantity': 4 },
  324. { 'item': 'Big Shoes', 'quantity': 1 }
  325. ]
  326. syck: |
  327. struct test_node map1[] = {
  328. { T_STR, 0, "item" },
  329. { T_STR, 0, "Super Hoop" },
  330. { T_STR, 0, "quantity" },
  331. { T_STR, 0, "1" },
  332. end_node
  333. };
  334. struct test_node map2[] = {
  335. { T_STR, 0, "item" },
  336. { T_STR, 0, "Basketball" },
  337. { T_STR, 0, "quantity" },
  338. { T_STR, 0, "4" },
  339. end_node
  340. };
  341. struct test_node map3[] = {
  342. { T_STR, 0, "item" },
  343. { T_STR, 0, "Big Shoes" },
  344. { T_STR, 0, "quantity" },
  345. { T_STR, 0, "1" },
  346. end_node
  347. };
  348. struct test_node seq[] = {
  349. { T_MAP, 0, 0, map1 },
  350. { T_MAP, 0, 0, map2 },
  351. { T_MAP, 0, 0, map3 },
  352. end_node
  353. };
  354. struct test_node stream[] = {
  355. { T_SEQ, 0, 0, seq },
  356. end_node
  357. };
  358. ---
  359. test: Literal perserves newlines
  360. todo: true
  361. spec: 2.13
  362. yaml: |
  363. # ASCII Art
  364. --- |
  365. \//||\/||
  366. // || ||_
  367. perl: |
  368. "\\//||\\/||\n// || ||_\n"
  369. ruby: |
  370. "\\//||\\/||\n// || ||_\n"
  371. python: |
  372. [
  373. flushLeft(
  374. """
  375. \//||\/||
  376. // || ||_
  377. """
  378. )
  379. ]
  380. syck: |
  381. struct test_node stream[] = {
  382. { T_STR, 0, "\\//||\\/||\n// || ||_\n" },
  383. end_node
  384. };
  385. ---
  386. test: Folded treats newlines as a space
  387. todo: true
  388. spec: 2.14
  389. yaml: |
  390. ---
  391. Mark McGwire's
  392. year was crippled
  393. by a knee injury.
  394. perl: |
  395. "Mark McGwire's year was crippled by a knee injury."
  396. ruby: |
  397. "Mark McGwire's year was crippled by a knee injury."
  398. python: |
  399. [ "Mark McGwire's year was crippled by a knee injury." ]
  400. syck: |
  401. struct test_node stream[] = {
  402. { T_STR, 0, "Mark McGwire's year was crippled by a knee injury." },
  403. end_node
  404. };
  405. ---
  406. test: Newlines preserved for indented and blank lines
  407. todo: true
  408. spec: 2.15
  409. yaml: |
  410. --- >
  411. Sammy Sosa completed another
  412. fine season with great stats.
  413. 63 Home Runs
  414. 0.288 Batting Average
  415. What a year!
  416. perl: |
  417. "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n"
  418. ruby: |
  419. "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n"
  420. python: |
  421. [
  422. flushLeft(
  423. """
  424. Sammy Sosa completed another fine season with great stats.
  425. 63 Home Runs
  426. 0.288 Batting Average
  427. What a year!
  428. """
  429. )
  430. ]
  431. syck: |
  432. struct test_node stream[] = {
  433. { T_STR, 0, "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" },
  434. end_node
  435. };
  436. ---
  437. test: Indentation determines scope
  438. spec: 2.16
  439. yaml: |
  440. name: Mark McGwire
  441. accomplishment: >
  442. Mark set a major league
  443. home run record in 1998.
  444. stats: |
  445. 65 Home Runs
  446. 0.278 Batting Average
  447. php: |
  448. array(
  449. 'name' => 'Mark McGwire',
  450. 'accomplishment' => "Mark set a major league home run record in 1998.\n",
  451. 'stats' => "65 Home Runs\n0.278 Batting Average\n"
  452. )
  453. ---
  454. test: Quoted scalars
  455. todo: true
  456. spec: 2.17
  457. yaml: |
  458. unicode: "Sosa did fine.\u263A"
  459. control: "\b1998\t1999\t2000\n"
  460. hexesc: "\x0D\x0A is \r\n"
  461. single: '"Howdy!" he cried.'
  462. quoted: ' # not a ''comment''.'
  463. tie-fighter: '|\-*-/|'
  464. ruby: |
  465. {
  466. "tie-fighter" => "|\\-*-/|",
  467. "control"=>"\0101998\t1999\t2000\n",
  468. "unicode"=>"Sosa did fine." + ["263A".hex ].pack('U*'),
  469. "quoted"=>" # not a 'comment'.",
  470. "single"=>"\"Howdy!\" he cried.",
  471. "hexesc"=>"\r\n is \r\n"
  472. }
  473. ---
  474. test: Multiline flow scalars
  475. todo: true
  476. spec: 2.18
  477. yaml: |
  478. plain:
  479. This unquoted scalar
  480. spans many lines.
  481. quoted: "So does this
  482. quoted scalar.\n"
  483. ruby: |
  484. {
  485. 'plain' => 'This unquoted scalar spans many lines.',
  486. 'quoted' => "So does this quoted scalar.\n"
  487. }
  488. ---
  489. test: Integers
  490. spec: 2.19
  491. yaml: |
  492. canonical: 12345
  493. decimal: +12,345
  494. octal: 014
  495. hexadecimal: 0xC
  496. php: |
  497. array(
  498. 'canonical' => 12345,
  499. 'decimal' => 12345,
  500. 'octal' => 014,
  501. 'hexadecimal' => 0xC
  502. )
  503. ---
  504. # FIX: spec shows parens around -inf and NaN
  505. test: Floating point
  506. spec: 2.20
  507. yaml: |
  508. canonical: 1.23015e+3
  509. exponential: 12.3015e+02
  510. fixed: 1,230.15
  511. negative infinity: -.inf
  512. not a number: .NaN
  513. php: |
  514. array(
  515. 'canonical' => 1230.15,
  516. 'exponential' => 1230.15,
  517. 'fixed' => 1230.15,
  518. 'negative infinity' => log(0),
  519. 'not a number' => -log(0),
  520. )
  521. ---
  522. test: Miscellaneous
  523. spec: 2.21
  524. yaml: |
  525. null: ~
  526. true: true
  527. false: false
  528. string: '12345'
  529. php: |
  530. array(
  531. '' => null,
  532. 1 => true,
  533. 0 => false,
  534. 'string' => '12345'
  535. )
  536. ---
  537. test: Timestamps
  538. todo: true
  539. spec: 2.22
  540. yaml: |
  541. canonical: 2001-12-15T02:59:43.1Z
  542. iso8601: 2001-12-14t21:59:43.10-05:00
  543. spaced: 2001-12-14 21:59:43.10 -05:00
  544. date: 2002-12-14 # Time is noon UTC
  545. php: |
  546. array(
  547. 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ),
  548. 'iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  549. 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  550. 'date' => Date.new( 2002, 12, 14 )
  551. )
  552. ---
  553. test: legacy Timestamps test
  554. todo: true
  555. spec: legacy D4
  556. yaml: |
  557. canonical: 2001-12-15T02:59:43.00Z
  558. iso8601: 2001-02-28t21:59:43.00-05:00
  559. spaced: 2001-12-14 21:59:43.00 -05:00
  560. date: 2002-12-14
  561. php: |
  562. array(
  563. 'canonical' => Time::utc( 2001, 12, 15, 2, 59, 43, 0 ),
  564. 'iso8601' => YAML::mktime( 2001, 2, 28, 21, 59, 43, 0, "-05:00" ),
  565. 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0, "-05:00" ),
  566. 'date' => Date.new( 2002, 12, 14 )
  567. )
  568. ---
  569. test: Various explicit families
  570. todo: true
  571. spec: 2.23
  572. yaml: |
  573. not-date: !str 2002-04-28
  574. picture: !binary |
  575. R0lGODlhDAAMAIQAAP//9/X
  576. 17unp5WZmZgAAAOfn515eXv
  577. Pz7Y6OjuDg4J+fn5OTk6enp
  578. 56enmleECcgggoBADs=
  579. application specific tag: !!something |
  580. The semantics of the tag
  581. above may be different for
  582. different documents.
  583. ruby-setup: |
  584. YAML.add_private_type( "something" ) do |type, val|
  585. "SOMETHING: #{val}"
  586. end
  587. ruby: |
  588. {
  589. 'not-date' => '2002-04-28',
  590. 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;",
  591. 'application specific tag' => "SOMETHING: The semantics of the tag\nabove may be different for\ndifferent documents.\n"
  592. }
  593. ---
  594. test: Application specific family
  595. todo: true
  596. spec: 2.24
  597. yaml: |
  598. # Establish a tag prefix
  599. --- !clarkevans.com,2002/graph/^shape
  600. # Use the prefix: shorthand for
  601. # !clarkevans.com,2002/graph/circle
  602. - !^circle
  603. center: &ORIGIN {x: 73, 'y': 129}
  604. radius: 7
  605. - !^line # !clarkevans.com,2002/graph/line
  606. start: *ORIGIN
  607. finish: { x: 89, 'y': 102 }
  608. - !^label
  609. start: *ORIGIN
  610. color: 0xFFEEBB
  611. value: Pretty vector drawing.
  612. ruby-setup: |
  613. YAML.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val|
  614. if Array === val
  615. val << "Shape Container"
  616. val
  617. else
  618. raise YAML::Error, "Invalid graph of class #{ val.class }: " + val.inspect
  619. end
  620. }
  621. one_shape_proc = Proc.new { |type, val|
  622. scheme, domain, type = type.split( /:/, 3 )
  623. if val.is_a? ::Hash
  624. val['TYPE'] = "Shape: #{type}"
  625. val
  626. else
  627. raise YAML::Error, "Invalid graph of class #{ val.class }: " + val.inspect
  628. end
  629. }
  630. YAML.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc )
  631. YAML.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc )
  632. YAML.add_domain_type( "clarkevans.com,2002", 'graph/label', &one_shape_proc )
  633. ruby: |
  634. [
  635. {
  636. "radius" => 7,
  637. "center"=>
  638. {
  639. "x" => 73,
  640. "y" => 129
  641. },
  642. "TYPE" => "Shape: graph/circle"
  643. }, {
  644. "finish" =>
  645. {
  646. "x" => 89,
  647. "y" => 102
  648. },
  649. "TYPE" => "Shape: graph/line",
  650. "start" =>
  651. {
  652. "x" => 73,
  653. "y" => 129
  654. }
  655. }, {
  656. "TYPE" => "Shape: graph/label",
  657. "value" => "Pretty vector drawing.",
  658. "start" =>
  659. {
  660. "x" => 73,
  661. "y" => 129
  662. },
  663. "color" => 16772795
  664. },
  665. "Shape Container"
  666. ]
  667. # ---
  668. # test: Unordered set
  669. # spec: 2.25
  670. # yaml: |
  671. # # sets are represented as a
  672. # # mapping where each key is
  673. # # associated with the empty string
  674. # --- !set
  675. # ? Mark McGwire
  676. # ? Sammy Sosa
  677. # ? Ken Griff
  678. ---
  679. test: Ordered mappings
  680. todo: true
  681. spec: 2.26
  682. yaml: |
  683. # ordered maps are represented as
  684. # a sequence of mappings, with
  685. # each mapping having one key
  686. --- !omap
  687. - Mark McGwire: 65
  688. - Sammy Sosa: 63
  689. - Ken Griffy: 58
  690. ruby: |
  691. YAML::Omap[
  692. 'Mark McGwire', 65,
  693. 'Sammy Sosa', 63,
  694. 'Ken Griffy', 58
  695. ]
  696. ---
  697. test: Invoice
  698. dump_skip: true
  699. spec: 2.27
  700. yaml: |
  701. --- !clarkevans.com,2002/^invoice
  702. invoice: 34843
  703. date : 2001-01-23
  704. bill-to: &id001
  705. given : Chris
  706. family : Dumars
  707. address:
  708. lines: |
  709. 458 Walkman Dr.
  710. Suite #292
  711. city : Royal Oak
  712. state : MI
  713. postal : 48046
  714. ship-to: *id001
  715. product:
  716. -
  717. sku : BL394D
  718. quantity : 4
  719. description : Basketball
  720. price : 450.00
  721. -
  722. sku : BL4438H
  723. quantity : 1
  724. description : Super Hoop
  725. price : 2392.00
  726. tax : 251.42
  727. total: 4443.52
  728. comments: >
  729. Late afternoon is best.
  730. Backup contact is Nancy
  731. Billsmer @ 338-4338.
  732. php: |
  733. array(
  734. 'invoice' => 34843, 'date' => mktime(0, 0, 0, 1, 23, 2001),
  735. 'bill-to' =>
  736. array( 'given' => 'Chris', 'family' => 'Dumars', 'address' => array( 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ) )
  737. , 'ship-to' =>
  738. array( 'given' => 'Chris', 'family' => 'Dumars', 'address' => array( 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ) )
  739. , 'product' =>
  740. array(
  741. array( 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 ),
  742. array( 'sku' => 'BL4438H', 'quantity' => 1, 'description' => 'Super Hoop', 'price' => 2392.00 )
  743. ),
  744. 'tax' => 251.42, 'total' => 4443.52,
  745. 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n"
  746. )
  747. ---
  748. test: Log file
  749. todo: true
  750. spec: 2.28
  751. yaml: |
  752. ---
  753. Time: 2001-11-23 15:01:42 -05:00
  754. User: ed
  755. Warning: >
  756. This is an error message
  757. for the log file
  758. ---
  759. Time: 2001-11-23 15:02:31 -05:00
  760. User: ed
  761. Warning: >
  762. A slightly different error
  763. message.
  764. ---
  765. Date: 2001-11-23 15:03:17 -05:00
  766. User: ed
  767. Fatal: >
  768. Unknown variable "bar"
  769. Stack:
  770. - file: TopClass.py
  771. line: 23
  772. code: |
  773. x = MoreObject("345\n")
  774. - file: MoreClass.py
  775. line: 58
  776. code: |-
  777. foo = bar
  778. ruby: |
  779. y = YAML::Stream.new
  780. y.add( { 'Time' => YAML::mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ),
  781. 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } )
  782. y.add( { 'Time' => YAML::mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ),
  783. 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } )
  784. y.add( { 'Date' => YAML::mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ),
  785. 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n",
  786. 'Stack' => [
  787. { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" },
  788. { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } )
  789. documents: 3
  790. ---
  791. test: Throwaway comments
  792. yaml: |
  793. ### These are four throwaway comment ###
  794. ### lines (the second line is empty). ###
  795. this: | # Comments may trail lines.
  796. contains three lines of text.
  797. The third one starts with a
  798. # character. This isn't a comment.
  799. # These are three throwaway comment
  800. # lines (the first line is empty).
  801. php: |
  802. array(
  803. 'this' => "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"
  804. )
  805. ---
  806. test: Document with a single value
  807. todo: true
  808. yaml: |
  809. --- >
  810. This YAML stream contains a single text value.
  811. The next stream is a log file - a sequence of
  812. log entries. Adding an entry to the log is a
  813. simple matter of appending it at the end.
  814. ruby: |
  815. "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n"
  816. ---
  817. test: Document stream
  818. todo: true
  819. yaml: |
  820. ---
  821. at: 2001-08-12 09:25:00.00 Z
  822. type: GET
  823. HTTP: '1.0'
  824. url: '/index.html'
  825. ---
  826. at: 2001-08-12 09:25:10.00 Z
  827. type: GET
  828. HTTP: '1.0'
  829. url: '/toc.html'
  830. ruby: |
  831. y = YAML::Stream.new
  832. y.add( {
  833. 'at' => Time::utc( 2001, 8, 12, 9, 25, 00 ),
  834. 'type' => 'GET',
  835. 'HTTP' => '1.0',
  836. 'url' => '/index.html'
  837. } )
  838. y.add( {
  839. 'at' => Time::utc( 2001, 8, 12, 9, 25, 10 ),
  840. 'type' => 'GET',
  841. 'HTTP' => '1.0',
  842. 'url' => '/toc.html'
  843. } )
  844. documents: 2
  845. ---
  846. test: Top level mapping
  847. yaml: |
  848. # This stream is an example of a top-level mapping.
  849. invoice : 34843
  850. date : 2001-01-23
  851. total : 4443.52
  852. php: |
  853. array(
  854. 'invoice' => 34843,
  855. 'date' => mktime(0, 0, 0, 1, 23, 2001),
  856. 'total' => 4443.52
  857. )
  858. ---
  859. test: Single-line documents
  860. todo: true
  861. yaml: |
  862. # The following is a sequence of three documents.
  863. # The first contains an empty mapping, the second
  864. # an empty sequence, and the last an empty string.
  865. --- {}
  866. --- [ ]
  867. --- ''
  868. ruby: |
  869. y = YAML::Stream.new
  870. y.add( {} )
  871. y.add( [] )
  872. y.add( '' )
  873. documents: 3
  874. ---
  875. test: Document with pause
  876. todo: true
  877. yaml: |
  878. # A communication channel based on a YAML stream.
  879. ---
  880. sent at: 2002-06-06 11:46:25.10 Z
  881. payload: Whatever
  882. # Receiver can process this as soon as the following is sent:
  883. ...
  884. # Even if the next message is sent long after:
  885. ---
  886. sent at: 2002-06-06 12:05:53.47 Z
  887. payload: Whatever
  888. ...
  889. ruby: |
  890. y = YAML::Stream.new
  891. y.add(
  892. { 'sent at' => YAML::mktime( 2002, 6, 6, 11, 46, 25, 0.10 ),
  893. 'payload' => 'Whatever' }
  894. )
  895. y.add(
  896. { "payload" => "Whatever", "sent at" => YAML::mktime( 2002, 6, 6, 12, 5, 53, 0.47 ) }
  897. )
  898. documents: 2
  899. ---
  900. test: Explicit typing
  901. yaml: |
  902. integer: 12
  903. also int: ! "12"
  904. string: !str 12
  905. php: |
  906. array( 'integer' => 12, 'also int' => 12, 'string' => '12' )
  907. ---
  908. test: Private types
  909. todo: true
  910. yaml: |
  911. # Both examples below make use of the 'x-private:ball'
  912. # type family URI, but with different semantics.
  913. ---
  914. pool: !!ball
  915. number: 8
  916. color: black
  917. ---
  918. bearing: !!ball
  919. material: steel
  920. ruby: |
  921. y = YAML::Stream.new
  922. y.add( { 'pool' =>
  923. YAML::PrivateType.new( 'ball',
  924. { 'number' => 8, 'color' => 'black' } ) }
  925. )
  926. y.add( { 'bearing' =>
  927. YAML::PrivateType.new( 'ball',
  928. { 'material' => 'steel' } ) }
  929. )
  930. documents: 2
  931. ---
  932. test: Type family under yaml.org
  933. yaml: |
  934. # The URI is 'tag:yaml.org,2002:str'
  935. - !str a Unicode string
  936. php: |
  937. array( 'a Unicode string' )
  938. ---
  939. test: Type family under perl.yaml.org
  940. todo: true
  941. yaml: |
  942. # The URI is 'tag:perl.yaml.org,2002:Text::Tabs'
  943. - !perl/Text::Tabs {}
  944. ruby: |
  945. [ YAML::DomainType.new( 'perl.yaml.org,2002', 'Text::Tabs', {} ) ]
  946. ---
  947. test: Type family under clarkevans.com
  948. todo: true
  949. yaml: |
  950. # The URI is 'tag:clarkevans.com,2003-02:timesheet'
  951. - !clarkevans.com,2003-02/timesheet {}
  952. ruby: |
  953. [ YAML::DomainType.new( 'clarkevans.com,2003-02', 'timesheet', {} ) ]
  954. ---
  955. test: URI Escaping
  956. todo: true
  957. yaml: |
  958. same:
  959. - !domain.tld,2002/type\x30 value
  960. - !domain.tld,2002/type0 value
  961. different: # As far as the YAML parser is concerned
  962. - !domain.tld,2002/type%30 value
  963. - !domain.tld,2002/type0 value
  964. ruby-setup: |
  965. YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
  966. "ONE: #{val}"
  967. }
  968. YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
  969. "TWO: #{val}"
  970. }
  971. ruby: |
  972. { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value', 'ONE: value' ] }
  973. ---
  974. test: URI Prefixing
  975. todo: true
  976. yaml: |
  977. # 'tag:domain.tld,2002:invoice' is some type family.
  978. invoice: !domain.tld,2002/^invoice
  979. # 'seq' is shorthand for 'tag:yaml.org,2002:seq'.
  980. # This does not effect '^customer' below
  981. # because it is does not specify a prefix.
  982. customers: !seq
  983. # '^customer' is shorthand for the full
  984. # notation 'tag:domain.tld,2002:customer'.
  985. - !^customer
  986. given : Chris
  987. family : Dumars
  988. ruby-setup: |
  989. YAML.add_domain_type( "domain.tld,2002", /(invoice|customer)/ ) { |type, val|
  990. if val.is_a? ::Hash
  991. scheme, domain, type = type.split( /:/, 3 )
  992. val['type'] = "domain #{type}"
  993. val
  994. else
  995. raise YAML::Error, "Not a Hash in domain.tld/invoice: " + val.inspect
  996. end
  997. }
  998. ruby: |
  999. { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }
  1000. ---
  1001. test: Overriding anchors
  1002. yaml: |
  1003. anchor : &A001 This scalar has an anchor.
  1004. override : &A001 >
  1005. The alias node below is a
  1006. repeated use of this value.
  1007. alias : *A001
  1008. php: |
  1009. array( 'anchor' => 'This scalar has an anchor.',
  1010. 'override' => "The alias node below is a repeated use of this value.\n",
  1011. 'alias' => "The alias node below is a repeated use of this value.\n" )
  1012. ---
  1013. test: Flow and block formatting
  1014. todo: true
  1015. yaml: |
  1016. empty: []
  1017. flow: [ one, two, three # May span lines,
  1018. , four, # indentation is
  1019. five ] # mostly ignored.
  1020. block:
  1021. - First item in top sequence
  1022. -
  1023. - Subordinate sequence entry
  1024. - >
  1025. A folded sequence entry
  1026. - Sixth item in top sequence
  1027. ruby: |
  1028. { 'empty' => [], 'flow' => [ 'one', 'two', 'three', 'four', 'five' ],
  1029. 'block' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ],
  1030. "A folded sequence entry\n", 'Sixth item in top sequence' ] }
  1031. ---
  1032. test: Complete mapping test
  1033. todo: true
  1034. yaml: |
  1035. empty: {}
  1036. flow: { one: 1, two: 2 }
  1037. spanning: { one: 1,
  1038. two: 2 }
  1039. block:
  1040. first : First entry
  1041. second:
  1042. key: Subordinate mapping
  1043. third:
  1044. - Subordinate sequence
  1045. - { }
  1046. - Previous mapping is empty.
  1047. - A key: value pair in a sequence.
  1048. A second: key:value pair.
  1049. - The previous entry is equal to the following one.
  1050. -
  1051. A key: value pair in a sequence.
  1052. A second: key:value pair.
  1053. !float 12 : This key is a float.
  1054. ? >
  1055. ?
  1056. : This key had to be protected.
  1057. "\a" : This key had to be escaped.
  1058. ? >
  1059. This is a
  1060. multi-line
  1061. folded key
  1062. : Whose value is
  1063. also multi-line.
  1064. ? this also works as a key
  1065. : with a value at the next line.
  1066. ?
  1067. - This key
  1068. - is a sequence
  1069. :
  1070. - With a sequence value.
  1071. ?
  1072. This: key
  1073. is a: mapping
  1074. :
  1075. with a: mapping value.
  1076. ruby: |
  1077. { 'empty' => {}, 'flow' => { 'one' => 1, 'two' => 2 },
  1078. 'spanning' => { 'one' => 1, 'two' => 2 },
  1079. 'block' => { 'first' => 'First entry', 'second' =>
  1080. { 'key' => 'Subordinate mapping' }, 'third' =>
  1081. [ 'Subordinate sequence', {}, 'Previous mapping is empty.',
  1082. { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' },
  1083. 'The previous entry is equal to the following one.',
  1084. { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ],
  1085. 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.',
  1086. "\a" => 'This key had to be escaped.',
  1087. "This is a multi-line folded key\n" => "Whose value is also multi-line.",
  1088. 'this also works as a key' => 'with a value at the next line.',
  1089. [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }
  1090. # Couldn't recreate map exactly, so we'll do a detailed check to be sure it's entact
  1091. obj_y['block'].keys.each { |k|
  1092. if Hash === k
  1093. v = obj_y['block'][k]
  1094. if k['This'] == 'key' and k['is a'] == 'mapping' and v['with a'] == 'mapping value.'
  1095. obj_r['block'][k] = v
  1096. end
  1097. end
  1098. }
  1099. ---
  1100. test: Literal explicit indentation
  1101. yaml: |
  1102. # Explicit indentation must
  1103. # be given in all the three
  1104. # following cases.
  1105. leading spaces: |2
  1106. This value starts with four spaces.
  1107. leading line break: |2
  1108. This value starts with a line break.
  1109. leading comment indicator: |2
  1110. # first line starts with a
  1111. # character.
  1112. # Explicit indentation may
  1113. # also be given when it is
  1114. # not required.
  1115. redundant: |2
  1116. This value is indented 2 spaces.
  1117. php: |
  1118. array(
  1119. 'leading spaces' => " This value starts with four spaces.\n",
  1120. 'leading line break' => "\nThis value starts with a line break.\n",
  1121. 'leading comment indicator' => "# first line starts with a\n# character.\n",
  1122. 'redundant' => "This value is indented 2 spaces.\n"
  1123. )
  1124. ---
  1125. test: Chomping and keep modifiers
  1126. yaml: |
  1127. clipped: |
  1128. This has one newline.
  1129. same as "clipped" above: "This has one newline.\n"
  1130. stripped: |-
  1131. This has no newline.
  1132. same as "stripped" above: "This has no newline."
  1133. kept: |+
  1134. This has two newlines.
  1135. same as "kept" above: "This has two newlines.\n\n"
  1136. php: |
  1137. array(
  1138. 'clipped' => "This has one newline.\n",
  1139. 'same as "clipped" above' => "This has one newline.\n",
  1140. 'stripped' => 'This has no newline.',
  1141. 'same as "stripped" above' => 'This has no newline.',
  1142. 'kept' => "This has two newlines.\n\n",
  1143. 'same as "kept" above' => "This has two newlines.\n\n"
  1144. )
  1145. ---
  1146. test: Literal combinations
  1147. todo: true
  1148. yaml: |
  1149. empty: |
  1150. literal: |
  1151. The \ ' " characters may be
  1152. freely used. Leading white
  1153. space is significant.
  1154. Line breaks are significant.
  1155. Thus this value contains one
  1156. empty line and ends with a
  1157. single line break, but does
  1158. not start with one.
  1159. is equal to: "The \\ ' \" characters may \
  1160. be\nfreely used. Leading white\n space \
  1161. is significant.\n\nLine breaks are \
  1162. significant.\nThus this value contains \
  1163. one\nempty line and ends with a\nsingle \
  1164. line break, but does\nnot start with one.\n"
  1165. # Comments may follow a block
  1166. # scalar value. They must be
  1167. # less indented.
  1168. # Modifiers may be combined in any order.
  1169. indented and chomped: |2-
  1170. This has no newline.
  1171. also written as: |-2
  1172. This has no newline.
  1173. both are equal to: " This has no newline."
  1174. php: |
  1175. array(
  1176. 'empty' => '',
  1177. 'literal' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " +
  1178. "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" +
  1179. "empty line and ends with a\nsingle line break, but does\nnot start with one.\n",
  1180. 'is equal to' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " +
  1181. "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" +
  1182. "empty line and ends with a\nsingle line break, but does\nnot start with one.\n",
  1183. 'indented and chomped' => ' This has no newline.',
  1184. 'also written as' => ' This has no newline.',
  1185. 'both are equal to' => ' This has no newline.'
  1186. )
  1187. ---
  1188. test: Folded combinations
  1189. todo: true
  1190. yaml: |
  1191. empty: >
  1192. one paragraph: >
  1193. Line feeds are converted
  1194. to spaces, so this value
  1195. contains no line breaks
  1196. except for the final one.
  1197. multiple paragraphs: >2
  1198. An empty line, either
  1199. at the start or in
  1200. the value:
  1201. Is interpreted as a
  1202. line break. Thus this
  1203. value contains three
  1204. line breaks.
  1205. indented text: >
  1206. This is a folded
  1207. paragraph followed
  1208. by a list:
  1209. * first entry
  1210. * second entry
  1211. Followed by another
  1212. folded paragraph,
  1213. another list:
  1214. * first entry
  1215. * second entry
  1216. And a final folded
  1217. paragraph.
  1218. above is equal to: |
  1219. This is a folded paragraph followed by a list:
  1220. * first entry
  1221. * second entry
  1222. Followed by another folded paragraph, another list:
  1223. * first entry
  1224. * second entry
  1225. And a final folded paragraph.
  1226. # Explicit comments may follow
  1227. # but must be less indented.
  1228. php: |
  1229. array(
  1230. 'empty' => '',
  1231. 'one paragraph' => 'Line feeds are converted to spaces, so this value'.
  1232. " contains no line breaks except for the final one.\n",
  1233. 'multiple paragraphs' => "\nAn empty line, either at the start or in the value:\n".
  1234. "Is interpreted as a line break. Thus this value contains three line breaks.\n",
  1235. 'indented text' => "This is a folded paragraph followed by a list:\n".
  1236. " * first entry\n * second entry\nFollowed by another folded paragraph, ".
  1237. "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n",
  1238. 'above is equal to' => "This is a folded paragraph followed by a list:\n".
  1239. " * first entry\n * second entry\nFollowed by another folded paragraph, ".
  1240. "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n"
  1241. )
  1242. ---
  1243. test: Single quotes
  1244. todo: true
  1245. yaml: |
  1246. empty: ''
  1247. second: '! : \ etc. can be used freely.'
  1248. third: 'a single quote '' must be escaped.'
  1249. span: 'this contains
  1250. six spaces
  1251. and one
  1252. line break'
  1253. is same as: "this contains six spaces\nand one line break"
  1254. php: |
  1255. array(
  1256. 'empty' => '',
  1257. 'second' => '! : \\ etc. can be used freely.',
  1258. 'third' => "a single quote ' must be escaped.",
  1259. 'span' => "this contains six spaces\nand one line break",
  1260. 'is same as' => "this contains six spaces\nand one line break"
  1261. )
  1262. ---
  1263. test: Double quotes
  1264. todo: true
  1265. yaml: |
  1266. empty: ""
  1267. second: "! : etc. can be used freely."
  1268. third: "a \" or a \\ must be escaped."
  1269. fourth: "this value ends with an LF.\n"
  1270. span: "this contains
  1271. four \
  1272. spaces"
  1273. is equal to: "this contains four spaces"
  1274. php: |
  1275. array(
  1276. 'empty' => '',
  1277. 'second' => '! : etc. can be used freely.',
  1278. 'third' => 'a " or a \\ must be escaped.',
  1279. 'fourth' => "this value ends with an LF.\n",
  1280. 'span' => "this contains four spaces",
  1281. 'is equal to' => "this contains four spaces"
  1282. )
  1283. ---
  1284. test: Unquoted strings
  1285. todo: true
  1286. yaml: |
  1287. first: There is no unquoted empty string.
  1288. second: 12 ## This is an integer.
  1289. third: !str 12 ## This is a string.
  1290. span: this contains
  1291. six spaces
  1292. and one
  1293. line break
  1294. indicators: this has no comments.
  1295. #:foo and bar# are
  1296. both text.
  1297. flow: [ can span
  1298. lines, # comment
  1299. like
  1300. this ]
  1301. note: { one-line keys: but multi-line values }
  1302. php: |
  1303. array(
  1304. 'first' => 'There is no unquoted empty string.',
  1305. 'second' => 12,
  1306. 'third' => '12',
  1307. 'span' => "this contains six spaces\nand one line break",
  1308. 'indicators' => "this has no comments. #:foo and bar# are both text.",
  1309. 'flow' => [ 'can span lines', 'like this' ],
  1310. 'note' => { 'one-line keys' => 'but multi-line values' }
  1311. )
  1312. ---
  1313. test: Spanning sequences
  1314. todo: true
  1315. yaml: |
  1316. # The following are equal seqs
  1317. # with different identities.
  1318. flow: [ one, two ]
  1319. spanning: [ one,
  1320. two ]
  1321. block:
  1322. - one
  1323. - two
  1324. php: |
  1325. array(
  1326. 'flow' => [ 'one', 'two' ],
  1327. 'spanning' => [ 'one', 'two' ],
  1328. 'block' => [ 'one', 'two' ]
  1329. )
  1330. ---
  1331. test: Flow mappings
  1332. yaml: |
  1333. # The following are equal maps
  1334. # with different identities.
  1335. flow: { one: 1, two: 2 }
  1336. block:
  1337. one: 1
  1338. two: 2
  1339. php: |
  1340. array(
  1341. 'flow' => array( 'one' => 1, 'two' => 2 ),
  1342. 'block' => array( 'one' => 1, 'two' => 2 )
  1343. )
  1344. ---
  1345. test: Representations of 12
  1346. todo: true
  1347. yaml: |
  1348. - 12 # An integer
  1349. # The following scalars
  1350. # are loaded to the
  1351. # string value '1' '2'.
  1352. - !str 12
  1353. - '12'
  1354. - "12"
  1355. - "\
  1356. 1\
  1357. 2\
  1358. "
  1359. # Strings containing paths and regexps can be unquoted:
  1360. - /foo/bar
  1361. - d:/foo/bar
  1362. - foo/bar
  1363. - /a.*b/
  1364. php: |
  1365. array( 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' )
  1366. ---
  1367. test: "Null"
  1368. todo: true
  1369. yaml: |
  1370. canonical: ~
  1371. english: null
  1372. # This sequence has five
  1373. # entries, two with values.
  1374. sparse:
  1375. - ~
  1376. - 2nd entry
  1377. - Null
  1378. - 4th entry
  1379. -
  1380. four: This mapping has five keys,
  1381. only two with values.
  1382. php: |
  1383. array (
  1384. 'canonical' => null,
  1385. 'english' => null,
  1386. 'sparse' => array( null, '2nd entry', null, '4th entry', null ]),
  1387. 'four' => 'This mapping has five keys, only two with values.'
  1388. )
  1389. ---
  1390. test: Omap
  1391. todo: true
  1392. yaml: |
  1393. # Explicitly typed dictionary.
  1394. Bestiary: !omap
  1395. - aardvark: African pig-like ant eater. Ugly.
  1396. - anteater: South-American ant eater. Two species.
  1397. - anaconda: South-American constrictor snake. Scary.
  1398. # Etc.
  1399. ruby: |
  1400. {
  1401. 'Bestiary' => YAML::Omap[
  1402. 'aardvark', 'African pig-like ant eater. Ugly.',
  1403. 'anteater', 'South-American ant eater. Two species.',
  1404. 'anaconda', 'South-American constrictor snake. Scary.'
  1405. ]
  1406. }
  1407. ---
  1408. test: Pairs
  1409. todo: true
  1410. yaml: |
  1411. # Explicitly typed pairs.
  1412. tasks: !pairs
  1413. - meeting: with team.
  1414. - meeting: with boss.
  1415. - break: lunch.
  1416. - meeting: with client.
  1417. ruby: |
  1418. {
  1419. 'tasks' => YAML::Pairs[
  1420. 'meeting', 'with team.',
  1421. 'meeting', 'with boss.',
  1422. 'break', 'lunch.',
  1423. 'meeting', 'with client.'
  1424. ]
  1425. }
  1426. ---
  1427. test: Set
  1428. todo: true
  1429. yaml: |
  1430. # Explicitly typed set.
  1431. baseball players: !set
  1432. Mark McGwire:
  1433. Sammy Sosa:
  1434. Ken Griffey:
  1435. ruby: |
  1436. {
  1437. 'baseball players' => YAML::Set[
  1438. 'Mark McGwire', nil,
  1439. 'Sammy Sosa', nil,
  1440. 'Ken Griffey', nil
  1441. ]
  1442. }
  1443. ---
  1444. test: Boolean
  1445. yaml: |
  1446. false: used as key
  1447. logical: true
  1448. answer: false
  1449. php: |
  1450. array(
  1451. false => 'used as key',
  1452. 'logical' => true,
  1453. 'answer' => false
  1454. )
  1455. ---
  1456. test: Integer
  1457. yaml: |
  1458. canonical: 12345
  1459. decimal: +12,345
  1460. octal: 014
  1461. hexadecimal: 0xC
  1462. php: |
  1463. array(
  1464. 'canonical' => 12345,
  1465. 'decimal' => 12345,
  1466. 'octal' => 12,
  1467. 'hexadecimal' => 12
  1468. )
  1469. ---
  1470. test: Float
  1471. yaml: |
  1472. canonical: 1.23015e+3
  1473. exponential: 12.3015e+02
  1474. fixed: 1,230.15
  1475. negative infinity: -.inf
  1476. not a number: .NaN
  1477. php: |
  1478. array(
  1479. 'canonical' => 1230.15,
  1480. 'exponential' => 1230.15,
  1481. 'fixed' => 1230.15,
  1482. 'negative infinity' => log(0),
  1483. 'not a number' => -log(0)
  1484. )
  1485. ---
  1486. test: Timestamp
  1487. todo: true
  1488. yaml: |
  1489. canonical: 2001-12-15T02:59:43.1Z
  1490. valid iso8601: 2001-12-14t21:59:43.10-05:00
  1491. space separated: 2001-12-14 21:59:43.10 -05:00
  1492. date (noon UTC): 2002-12-14
  1493. ruby: |
  1494. array(
  1495. 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ),
  1496. 'valid iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  1497. 'space separated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  1498. 'date (noon UTC)' => Date.new( 2002, 12, 14 )
  1499. )
  1500. ---
  1501. test: Binary
  1502. todo: true
  1503. yaml: |
  1504. canonical: !binary "\
  1505. R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
  1506. OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
  1507. +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
  1508. AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
  1509. base64: !binary |
  1510. R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
  1511. OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
  1512. +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
  1513. AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
  1514. description: >
  1515. The binary value above is a tiny arrow
  1516. encoded as a gif image.
  1517. ruby-setup: |
  1518. arrow_gif = "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236iiiccc\243\243\243\204\204\204\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371!\376\016Made with GIMP\000,\000\000\000\000\f\000\f\000\000\005, \216\2010\236\343@\024\350i\020\304\321\212\010\034\317\200M$z\357\3770\205p\270\2601f\r\e\316\001\303\001\036\020' \202\n\001\000;"
  1519. ruby: |
  1520. {
  1521. 'canonical' => arrow_gif,
  1522. 'base64' => arrow_gif,
  1523. 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n"
  1524. }
  1525. ---
  1526. test: Merge key
  1527. todo: true
  1528. yaml: |
  1529. ---
  1530. - &CENTER { x: 1, y: 2 }
  1531. - &LEFT { x: 0, y: 2 }
  1532. - &BIG { r: 10 }
  1533. - &SMALL { r: 1 }
  1534. # All the following maps are equal:
  1535. - # Explicit keys
  1536. x: 1
  1537. y: 2
  1538. r: 10
  1539. label: center/big
  1540. - # Merge one map
  1541. << : *CENTER
  1542. r: 10
  1543. label: center/big
  1544. - # Merge multiple maps
  1545. << : [ *CENTER, *BIG ]
  1546. label: center/big
  1547. - # Override
  1548. << : [ *BIG, *LEFT, *SMALL ]
  1549. x: 1
  1550. label: center/big
  1551. ruby-setup: |
  1552. center = { 'x' => 1, 'y' => 2 }
  1553. left = { 'x' => 0, 'y' => 2 }
  1554. big = { 'r' => 10 }
  1555. small = { 'r' => 1 }
  1556. node1 = { 'x' => 1, 'y' => 2, 'r' => 10, 'label' => 'center/big' }
  1557. node2 = center.dup
  1558. node2.update( { 'r' => 10, 'label' => 'center/big' } )
  1559. node3 = big.dup
  1560. node3.update( center )
  1561. node3.update( { 'label' => 'center/big' } )
  1562. node4 = small.dup
  1563. node4.update( left )
  1564. node4.update( big )
  1565. node4.update( { 'x' => 1, 'label' => 'center/big' } )
  1566. ruby: |
  1567. [
  1568. center, left, big, small, node1, node2, node3, node4
  1569. ]
  1570. ---
  1571. test: Default key
  1572. todo: true
  1573. yaml: |
  1574. --- # Old schema
  1575. link with:
  1576. - library1.dll
  1577. - library2.dll
  1578. --- # New schema
  1579. link with:
  1580. - = : library1.dll
  1581. version: 1.2
  1582. - = : library2.dll
  1583. version: 2.3
  1584. ruby: |
  1585. y = YAML::Stream.new
  1586. y.add( { 'link with' => [ 'library1.dll', 'library2.dll' ] } )
  1587. obj_h = Hash[ 'version' => 1.2 ]
  1588. obj_h.default = 'library1.dll'
  1589. obj_h2 = Hash[ 'version' => 2.3 ]
  1590. obj_h2.default = 'library2.dll'
  1591. y.add( { 'link with' => [ obj_h, obj_h2 ] } )
  1592. documents: 2
  1593. ---
  1594. test: Special keys
  1595. todo: true
  1596. yaml: |
  1597. "!": These three keys
  1598. "&": had to be quoted
  1599. "=": and are normal strings.
  1600. # NOTE: the following node should NOT be serialized this way.
  1601. encoded node :
  1602. !special '!' : '!type'
  1603. !special|canonical '&' : 12
  1604. = : value
  1605. # The proper way to serialize the above node is as follows:
  1606. node : !!type &12 value
  1607. ruby: |
  1608. { '!' => 'These three keys', '&' => 'had to be quoted',
  1609. '=' => 'and are normal strings.',
  1610. 'encoded node' => YAML::PrivateType.new( 'type', 'value' ),
  1611. 'node' => YAML::PrivateType.new( 'type', 'value' ) }