YtsSpecificationExamples.yml 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  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. ['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. ['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. ['american' =>
  33. [ 'Boston Red Sox', 'Detroit Tigers',
  34. 'New York Yankees' ],
  35. 'national' =>
  36. [ '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. [
  53. ['name' => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278],
  54. ['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 behavior 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. [
  137. [ 'name', 'hr', 'avg' ],
  138. [ 'Mark McGwire', 65, 0.278 ],
  139. [ '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. [
  153. 'Mark McGwire' =>
  154. [ 'hr' => 65, 'avg' => 0.278 ],
  155. 'Sammy Sosa' =>
  156. [ '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. [
  208. 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ],
  209. 'rbi' => [ '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 occurrence
  222. - Ken Griffey
  223. php: |
  224. [
  225. 'hr' =>
  226. ['Mark McGwire', 'Sammy Sosa'],
  227. 'rbi' =>
  228. ['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. [
  295. [
  296. 'item' => 'Super Hoop',
  297. 'quantity' => 1,
  298. ],
  299. [
  300. 'item' => 'Basketball',
  301. 'quantity' => 4,
  302. ],
  303. [
  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. [
  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. octal: 014
  494. hexadecimal: 0xC
  495. php: |
  496. [
  497. 'canonical' => 12345,
  498. 'octal' => 014,
  499. 'hexadecimal' => 0xC
  500. ]
  501. ---
  502. # FIX: spec shows parens around -inf and NaN
  503. test: Floating point
  504. spec: 2.20
  505. yaml: |
  506. canonical: 1.23015e+3
  507. exponential: 12.3015e+02
  508. negative infinity: -.inf
  509. not a number: .NaN
  510. float as whole number: !!float 1
  511. php: |
  512. [
  513. 'canonical' => 1230.15,
  514. 'exponential' => 1230.15,
  515. 'negative infinity' => log(0),
  516. 'not a number' => -log(0),
  517. 'float as whole number' => (float) 1
  518. ]
  519. ---
  520. test: Timestamps
  521. todo: true
  522. spec: 2.22
  523. yaml: |
  524. canonical: 2001-12-15T02:59:43.1Z
  525. iso8601: 2001-12-14t21:59:43.10-05:00
  526. spaced: 2001-12-14 21:59:43.10 -05:00
  527. date: 2002-12-14 # Time is noon UTC
  528. php: |
  529. [
  530. 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ),
  531. 'iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  532. 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  533. 'date' => Date.new( 2002, 12, 14 )
  534. ]
  535. ---
  536. test: legacy Timestamps test
  537. todo: true
  538. spec: legacy D4
  539. yaml: |
  540. canonical: 2001-12-15T02:59:43.00Z
  541. iso8601: 2001-02-28t21:59:43.00-05:00
  542. spaced: 2001-12-14 21:59:43.00 -05:00
  543. date: 2002-12-14
  544. php: |
  545. [
  546. 'canonical' => Time::utc( 2001, 12, 15, 2, 59, 43, 0 ),
  547. 'iso8601' => YAML::mktime( 2001, 2, 28, 21, 59, 43, 0, "-05:00" ),
  548. 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0, "-05:00" ),
  549. 'date' => Date.new( 2002, 12, 14 )
  550. ]
  551. ---
  552. test: Various explicit families
  553. todo: true
  554. spec: 2.23
  555. yaml: |
  556. not-date: !!str 2002-04-28
  557. picture: !binary |
  558. R0lGODlhDAAMAIQAAP//9/X
  559. 17unp5WZmZgAAAOfn515eXv
  560. Pz7Y6OjuDg4J+fn5OTk6enp
  561. 56enmleECcgggoBADs=
  562. application specific tag: !!something |
  563. The semantics of the tag
  564. above may be different for
  565. different documents.
  566. ruby-setup: |
  567. YAML.add_private_type( "something" ) do |type, val|
  568. "SOMETHING: #{val}"
  569. end
  570. ruby: |
  571. {
  572. 'not-date' => '2002-04-28',
  573. '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;",
  574. 'application specific tag' => "SOMETHING: The semantics of the tag\nabove may be different for\ndifferent documents.\n"
  575. }
  576. ---
  577. test: Application specific family
  578. todo: true
  579. spec: 2.24
  580. yaml: |
  581. # Establish a tag prefix
  582. --- !clarkevans.com,2002/graph/^shape
  583. # Use the prefix: shorthand for
  584. # !clarkevans.com,2002/graph/circle
  585. - !^circle
  586. center: &ORIGIN {x: 73, 'y': 129}
  587. radius: 7
  588. - !^line # !clarkevans.com,2002/graph/line
  589. start: *ORIGIN
  590. finish: { x: 89, 'y': 102 }
  591. - !^label
  592. start: *ORIGIN
  593. color: 0xFFEEBB
  594. value: Pretty vector drawing.
  595. ruby-setup: |
  596. YAML.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val|
  597. if Array === val
  598. val << "Shape Container"
  599. val
  600. else
  601. raise YAML::Error, "Invalid graph of class #{ val.class }: " + val.inspect
  602. end
  603. }
  604. one_shape_proc = Proc.new { |type, val|
  605. scheme, domain, type = type.split( /:/, 3 )
  606. if val.is_a? ::Hash
  607. val['TYPE'] = "Shape: #{type}"
  608. val
  609. else
  610. raise YAML::Error, "Invalid graph of class #{ val.class }: " + val.inspect
  611. end
  612. }
  613. YAML.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc )
  614. YAML.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc )
  615. YAML.add_domain_type( "clarkevans.com,2002", 'graph/label', &one_shape_proc )
  616. ruby: |
  617. [
  618. {
  619. "radius" => 7,
  620. "center"=>
  621. {
  622. "x" => 73,
  623. "y" => 129
  624. },
  625. "TYPE" => "Shape: graph/circle"
  626. }, {
  627. "finish" =>
  628. {
  629. "x" => 89,
  630. "y" => 102
  631. },
  632. "TYPE" => "Shape: graph/line",
  633. "start" =>
  634. {
  635. "x" => 73,
  636. "y" => 129
  637. }
  638. }, {
  639. "TYPE" => "Shape: graph/label",
  640. "value" => "Pretty vector drawing.",
  641. "start" =>
  642. {
  643. "x" => 73,
  644. "y" => 129
  645. },
  646. "color" => 16772795
  647. },
  648. "Shape Container"
  649. ]
  650. # ---
  651. # test: Unordered set
  652. # spec: 2.25
  653. # yaml: |
  654. # # sets are represented as a
  655. # # mapping where each key is
  656. # # associated with the empty string
  657. # --- !set
  658. # ? Mark McGwire
  659. # ? Sammy Sosa
  660. # ? Ken Griff
  661. ---
  662. test: Ordered mappings
  663. todo: true
  664. spec: 2.26
  665. yaml: |
  666. # ordered maps are represented as
  667. # a sequence of mappings, with
  668. # each mapping having one key
  669. --- !omap
  670. - Mark McGwire: 65
  671. - Sammy Sosa: 63
  672. - Ken Griffy: 58
  673. ruby: |
  674. YAML::Omap[
  675. 'Mark McGwire', 65,
  676. 'Sammy Sosa', 63,
  677. 'Ken Griffy', 58
  678. ]
  679. ---
  680. test: Invoice
  681. dump_skip: true
  682. spec: 2.27
  683. yaml: |
  684. --- !clarkevans.com,2002/^invoice
  685. invoice: 34843
  686. date : 2001-01-23
  687. bill-to: &id001
  688. given : Chris
  689. family : Dumars
  690. address:
  691. lines: |
  692. 458 Walkman Dr.
  693. Suite #292
  694. city : Royal Oak
  695. state : MI
  696. postal : 48046
  697. ship-to: *id001
  698. product:
  699. -
  700. sku : BL394D
  701. quantity : 4
  702. description : Basketball
  703. price : 450.00
  704. -
  705. sku : BL4438H
  706. quantity : 1
  707. description : Super Hoop
  708. price : 2392.00
  709. tax : 251.42
  710. total: 4443.52
  711. comments: >
  712. Late afternoon is best.
  713. Backup contact is Nancy
  714. Billsmer @ 338-4338.
  715. php: |
  716. [
  717. 'invoice' => 34843, 'date' => gmmktime(0, 0, 0, 1, 23, 2001),
  718. 'bill-to' =>
  719. [ 'given' => 'Chris', 'family' => 'Dumars', 'address' => [ 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ]]
  720. , 'ship-to' =>
  721. [ 'given' => 'Chris', 'family' => 'Dumars', 'address' => [ 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ]]
  722. , 'product' =>
  723. [
  724. [ 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 ],
  725. [ 'sku' => 'BL4438H', 'quantity' => 1, 'description' => 'Super Hoop', 'price' => 2392.00 ]
  726. ],
  727. 'tax' => 251.42, 'total' => 4443.52,
  728. 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n"
  729. ]
  730. ---
  731. test: Log file
  732. todo: true
  733. spec: 2.28
  734. yaml: |
  735. ---
  736. Time: 2001-11-23 15:01:42 -05:00
  737. User: ed
  738. Warning: >
  739. This is an error message
  740. for the log file
  741. ---
  742. Time: 2001-11-23 15:02:31 -05:00
  743. User: ed
  744. Warning: >
  745. A slightly different error
  746. message.
  747. ---
  748. Date: 2001-11-23 15:03:17 -05:00
  749. User: ed
  750. Fatal: >
  751. Unknown variable "bar"
  752. Stack:
  753. - file: TopClass.py
  754. line: 23
  755. code: |
  756. x = MoreObject("345\n")
  757. - file: MoreClass.py
  758. line: 58
  759. code: |-
  760. foo = bar
  761. ruby: |
  762. y = YAML::Stream.new
  763. y.add( { 'Time' => YAML::mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ),
  764. 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } )
  765. y.add( { 'Time' => YAML::mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ),
  766. 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } )
  767. y.add( { 'Date' => YAML::mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ),
  768. 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n",
  769. 'Stack' => [
  770. { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" },
  771. { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } )
  772. documents: 3
  773. ---
  774. test: Throwaway comments
  775. yaml: |
  776. ### These are four throwaway comment ###
  777. ### lines (the second line is empty). ###
  778. this: | # Comments may trail lines.
  779. contains three lines of text.
  780. The third one starts with a
  781. # character. This isn't a comment.
  782. # These are three throwaway comment
  783. # lines (the first line is empty).
  784. php: |
  785. [
  786. 'this' => "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"
  787. ]
  788. ---
  789. test: Document with a single value
  790. todo: true
  791. yaml: |
  792. --- >
  793. This YAML stream contains a single text value.
  794. The next stream is a log file - a sequence of
  795. log entries. Adding an entry to the log is a
  796. simple matter of appending it at the end.
  797. ruby: |
  798. "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"
  799. ---
  800. test: Document stream
  801. todo: true
  802. yaml: |
  803. ---
  804. at: 2001-08-12 09:25:00.00 Z
  805. type: GET
  806. HTTP: '1.0'
  807. url: '/index.html'
  808. ---
  809. at: 2001-08-12 09:25:10.00 Z
  810. type: GET
  811. HTTP: '1.0'
  812. url: '/toc.html'
  813. ruby: |
  814. y = YAML::Stream.new
  815. y.add( {
  816. 'at' => Time::utc( 2001, 8, 12, 9, 25, 00 ),
  817. 'type' => 'GET',
  818. 'HTTP' => '1.0',
  819. 'url' => '/index.html'
  820. } )
  821. y.add( {
  822. 'at' => Time::utc( 2001, 8, 12, 9, 25, 10 ),
  823. 'type' => 'GET',
  824. 'HTTP' => '1.0',
  825. 'url' => '/toc.html'
  826. } )
  827. documents: 2
  828. ---
  829. test: Top level mapping
  830. yaml: |
  831. # This stream is an example of a top-level mapping.
  832. invoice : 34843
  833. date : 2001-01-23
  834. total : 4443.52
  835. php: |
  836. [
  837. 'invoice' => 34843,
  838. 'date' => gmmktime(0, 0, 0, 1, 23, 2001),
  839. 'total' => 4443.52
  840. ]
  841. ---
  842. test: Single-line documents
  843. todo: true
  844. yaml: |
  845. # The following is a sequence of three documents.
  846. # The first contains an empty mapping, the second
  847. # an empty sequence, and the last an empty string.
  848. --- {}
  849. --- [ ]
  850. --- ''
  851. ruby: |
  852. y = YAML::Stream.new
  853. y.add( {} )
  854. y.add( [] )
  855. y.add( '' )
  856. documents: 3
  857. ---
  858. test: Document with pause
  859. todo: true
  860. yaml: |
  861. # A communication channel based on a YAML stream.
  862. ---
  863. sent at: 2002-06-06 11:46:25.10 Z
  864. payload: Whatever
  865. # Receiver can process this as soon as the following is sent:
  866. ...
  867. # Even if the next message is sent long after:
  868. ---
  869. sent at: 2002-06-06 12:05:53.47 Z
  870. payload: Whatever
  871. ...
  872. ruby: |
  873. y = YAML::Stream.new
  874. y.add(
  875. { 'sent at' => YAML::mktime( 2002, 6, 6, 11, 46, 25, 0.10 ),
  876. 'payload' => 'Whatever' }
  877. )
  878. y.add(
  879. { "payload" => "Whatever", "sent at" => YAML::mktime( 2002, 6, 6, 12, 5, 53, 0.47 ) }
  880. )
  881. documents: 2
  882. ---
  883. test: Explicit typing
  884. yaml: |
  885. integer: 12
  886. no int: ! 12
  887. string: !!str 12
  888. php: |
  889. [ 'integer' => 12, 'no int' => '12', 'string' => '12' ]
  890. ---
  891. test: Private types
  892. todo: true
  893. yaml: |
  894. # Both examples below make use of the 'x-private:ball'
  895. # type family URI, but with different semantics.
  896. ---
  897. pool: !!ball
  898. number: 8
  899. color: black
  900. ---
  901. bearing: !!ball
  902. material: steel
  903. ruby: |
  904. y = YAML::Stream.new
  905. y.add( { 'pool' =>
  906. YAML::PrivateType.new( 'ball',
  907. { 'number' => 8, 'color' => 'black' } ) }
  908. )
  909. y.add( { 'bearing' =>
  910. YAML::PrivateType.new( 'ball',
  911. { 'material' => 'steel' } ) }
  912. )
  913. documents: 2
  914. ---
  915. test: Type family under yaml.org
  916. yaml: |
  917. # The URI is 'tag:yaml.org,2002:str'
  918. - !!str a Unicode string
  919. php: |
  920. [ 'a Unicode string' ]
  921. ---
  922. test: Type family under perl.yaml.org
  923. todo: true
  924. yaml: |
  925. # The URI is 'tag:perl.yaml.org,2002:Text::Tabs'
  926. - !perl/Text::Tabs {}
  927. ruby: |
  928. [ YAML::DomainType.new( 'perl.yaml.org,2002', 'Text::Tabs', {} ) ]
  929. ---
  930. test: Type family under clarkevans.com
  931. todo: true
  932. yaml: |
  933. # The URI is 'tag:clarkevans.com,2003-02:timesheet'
  934. - !clarkevans.com,2003-02/timesheet {}
  935. ruby: |
  936. [ YAML::DomainType.new( 'clarkevans.com,2003-02', 'timesheet', {} ) ]
  937. ---
  938. test: URI Escaping
  939. todo: true
  940. yaml: |
  941. same:
  942. - !domain.tld,2002/type\x30 value
  943. - !domain.tld,2002/type0 value
  944. different: # As far as the YAML parser is concerned
  945. - !domain.tld,2002/type%30 value
  946. - !domain.tld,2002/type0 value
  947. ruby-setup: |
  948. YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
  949. "ONE: #{val}"
  950. }
  951. YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
  952. "TWO: #{val}"
  953. }
  954. ruby: |
  955. { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value', 'ONE: value' ] }
  956. ---
  957. test: URI Prefixing
  958. todo: true
  959. yaml: |
  960. # 'tag:domain.tld,2002:invoice' is some type family.
  961. invoice: !domain.tld,2002/^invoice
  962. # 'seq' is shorthand for 'tag:yaml.org,2002:seq'.
  963. # This does not effect '^customer' below
  964. # because it is does not specify a prefix.
  965. customers: !seq
  966. # '^customer' is shorthand for the full
  967. # notation 'tag:domain.tld,2002:customer'.
  968. - !^customer
  969. given : Chris
  970. family : Dumars
  971. ruby-setup: |
  972. YAML.add_domain_type( "domain.tld,2002", /(invoice|customer)/ ) { |type, val|
  973. if val.is_a? ::Hash
  974. scheme, domain, type = type.split( /:/, 3 )
  975. val['type'] = "domain #{type}"
  976. val
  977. else
  978. raise YAML::Error, "Not a Hash in domain.tld/invoice: " + val.inspect
  979. end
  980. }
  981. ruby: |
  982. { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }
  983. ---
  984. test: Overriding anchors
  985. yaml: |
  986. anchor : &A001 This scalar has an anchor.
  987. override : &A001 >
  988. The alias node below is a
  989. repeated use of this value.
  990. alias : *A001
  991. php: |
  992. [ 'anchor' => 'This scalar has an anchor.',
  993. 'override' => "The alias node below is a repeated use of this value.\n",
  994. 'alias' => "The alias node below is a repeated use of this value.\n" ]
  995. ---
  996. test: Flow and block formatting
  997. todo: true
  998. yaml: |
  999. empty: []
  1000. flow: [ one, two, three # May span lines,
  1001. , four, # indentation is
  1002. five ] # mostly ignored.
  1003. block:
  1004. - First item in top sequence
  1005. -
  1006. - Subordinate sequence entry
  1007. - >
  1008. A folded sequence entry
  1009. - Sixth item in top sequence
  1010. ruby: |
  1011. { 'empty' => [], 'flow' => [ 'one', 'two', 'three', 'four', 'five' ],
  1012. 'block' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ],
  1013. "A folded sequence entry\n", 'Sixth item in top sequence' ] }
  1014. ---
  1015. test: Complete mapping test
  1016. todo: true
  1017. yaml: |
  1018. empty: {}
  1019. flow: { one: 1, two: 2 }
  1020. spanning: { one: 1,
  1021. two: 2 }
  1022. block:
  1023. first : First entry
  1024. second:
  1025. key: Subordinate mapping
  1026. third:
  1027. - Subordinate sequence
  1028. - { }
  1029. - Previous mapping is empty.
  1030. - A key: value pair in a sequence.
  1031. A second: key:value pair.
  1032. - The previous entry is equal to the following one.
  1033. -
  1034. A key: value pair in a sequence.
  1035. A second: key:value pair.
  1036. !float 12 : This key is a float.
  1037. ? >
  1038. ?
  1039. : This key had to be protected.
  1040. "\a" : This key had to be escaped.
  1041. ? >
  1042. This is a
  1043. multi-line
  1044. folded key
  1045. : Whose value is
  1046. also multi-line.
  1047. ? this also works as a key
  1048. : with a value at the next line.
  1049. ?
  1050. - This key
  1051. - is a sequence
  1052. :
  1053. - With a sequence value.
  1054. ?
  1055. This: key
  1056. is a: mapping
  1057. :
  1058. with a: mapping value.
  1059. ruby: |
  1060. { 'empty' => {}, 'flow' => { 'one' => 1, 'two' => 2 },
  1061. 'spanning' => { 'one' => 1, 'two' => 2 },
  1062. 'block' => { 'first' => 'First entry', 'second' =>
  1063. { 'key' => 'Subordinate mapping' }, 'third' =>
  1064. [ 'Subordinate sequence', {}, 'Previous mapping is empty.',
  1065. { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' },
  1066. 'The previous entry is equal to the following one.',
  1067. { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ],
  1068. 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.',
  1069. "\a" => 'This key had to be escaped.',
  1070. "This is a multi-line folded key\n" => "Whose value is also multi-line.",
  1071. 'this also works as a key' => 'with a value at the next line.',
  1072. [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }
  1073. # Couldn't recreate map exactly, so we'll do a detailed check to be sure it's entact
  1074. obj_y['block'].keys.each { |k|
  1075. if Hash === k
  1076. v = obj_y['block'][k]
  1077. if k['This'] == 'key' and k['is a'] == 'mapping' and v['with a'] == 'mapping value.'
  1078. obj_r['block'][k] = v
  1079. end
  1080. end
  1081. }
  1082. ---
  1083. test: Literal explicit indentation
  1084. yaml: |
  1085. # Explicit indentation must
  1086. # be given in all the three
  1087. # following cases.
  1088. leading spaces: |2
  1089. This value starts with four spaces.
  1090. leading line break: |2
  1091. This value starts with a line break.
  1092. leading comment indicator: |2
  1093. # first line starts with a
  1094. # character.
  1095. # Explicit indentation may
  1096. # also be given when it is
  1097. # not required.
  1098. redundant: |2
  1099. This value is indented 2 spaces.
  1100. php: |
  1101. [
  1102. 'leading spaces' => " This value starts with four spaces.\n",
  1103. 'leading line break' => "\nThis value starts with a line break.\n",
  1104. 'leading comment indicator' => "# first line starts with a\n# character.\n",
  1105. 'redundant' => "This value is indented 2 spaces.\n"
  1106. ]
  1107. ---
  1108. test: Chomping and keep modifiers
  1109. yaml: |
  1110. clipped: |
  1111. This has one newline.
  1112. same as "clipped" above: "This has one newline.\n"
  1113. stripped: |-
  1114. This has no newline.
  1115. same as "stripped" above: "This has no newline."
  1116. kept: |+
  1117. This has two newlines.
  1118. same as "kept" above: "This has two newlines.\n\n"
  1119. php: |
  1120. [
  1121. 'clipped' => "This has one newline.\n",
  1122. 'same as "clipped" above' => "This has one newline.\n",
  1123. 'stripped' => 'This has no newline.',
  1124. 'same as "stripped" above' => 'This has no newline.',
  1125. 'kept' => "This has two newlines.\n\n",
  1126. 'same as "kept" above' => "This has two newlines.\n\n"
  1127. ]
  1128. ---
  1129. test: Literal combinations
  1130. todo: true
  1131. yaml: |
  1132. empty: |
  1133. literal: |
  1134. The \ ' " characters may be
  1135. freely used. Leading white
  1136. space is significant.
  1137. Line breaks are significant.
  1138. Thus this value contains one
  1139. empty line and ends with a
  1140. single line break, but does
  1141. not start with one.
  1142. is equal to: "The \\ ' \" characters may \
  1143. be\nfreely used. Leading white\n space \
  1144. is significant.\n\nLine breaks are \
  1145. significant.\nThus this value contains \
  1146. one\nempty line and ends with a\nsingle \
  1147. line break, but does\nnot start with one.\n"
  1148. # Comments may follow a block
  1149. # scalar value. They must be
  1150. # less indented.
  1151. # Modifiers may be combined in any order.
  1152. indented and chomped: |2-
  1153. This has no newline.
  1154. also written as: |-2
  1155. This has no newline.
  1156. both are equal to: " This has no newline."
  1157. php: |
  1158. [
  1159. 'empty' => '',
  1160. 'literal' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " +
  1161. "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" +
  1162. "empty line and ends with a\nsingle line break, but does\nnot start with one.\n",
  1163. 'is equal to' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " +
  1164. "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" +
  1165. "empty line and ends with a\nsingle line break, but does\nnot start with one.\n",
  1166. 'indented and chomped' => ' This has no newline.',
  1167. 'also written as' => ' This has no newline.',
  1168. 'both are equal to' => ' This has no newline.'
  1169. ]
  1170. ---
  1171. test: Folded combinations
  1172. todo: true
  1173. yaml: |
  1174. empty: >
  1175. one paragraph: >
  1176. Line feeds are converted
  1177. to spaces, so this value
  1178. contains no line breaks
  1179. except for the final one.
  1180. multiple paragraphs: >2
  1181. An empty line, either
  1182. at the start or in
  1183. the value:
  1184. Is interpreted as a
  1185. line break. Thus this
  1186. value contains three
  1187. line breaks.
  1188. indented text: >
  1189. This is a folded
  1190. paragraph followed
  1191. by a list:
  1192. * first entry
  1193. * second entry
  1194. Followed by another
  1195. folded paragraph,
  1196. another list:
  1197. * first entry
  1198. * second entry
  1199. And a final folded
  1200. paragraph.
  1201. above is equal to: |
  1202. This is a folded paragraph followed by a list:
  1203. * first entry
  1204. * second entry
  1205. Followed by another folded paragraph, another list:
  1206. * first entry
  1207. * second entry
  1208. And a final folded paragraph.
  1209. # Explicit comments may follow
  1210. # but must be less indented.
  1211. php: |
  1212. [
  1213. 'empty' => '',
  1214. 'one paragraph' => 'Line feeds are converted to spaces, so this value'.
  1215. " contains no line breaks except for the final one.\n",
  1216. 'multiple paragraphs' => "\nAn empty line, either at the start or in the value:\n".
  1217. "Is interpreted as a line break. Thus this value contains three line breaks.\n",
  1218. 'indented text' => "This is a folded paragraph followed by a list:\n".
  1219. " * first entry\n * second entry\nFollowed by another folded paragraph, ".
  1220. "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n",
  1221. 'above is equal to' => "This is a folded paragraph followed by a list:\n".
  1222. " * first entry\n * second entry\nFollowed by another folded paragraph, ".
  1223. "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n"
  1224. ]
  1225. ---
  1226. test: Single quotes
  1227. todo: true
  1228. yaml: |
  1229. empty: ''
  1230. second: '! : \ etc. can be used freely.'
  1231. third: 'a single quote '' must be escaped.'
  1232. span: 'this contains
  1233. six spaces
  1234. and one
  1235. line break'
  1236. is same as: "this contains six spaces\nand one line break"
  1237. php: |
  1238. [
  1239. 'empty' => '',
  1240. 'second' => '! : \\ etc. can be used freely.',
  1241. 'third' => "a single quote ' must be escaped.",
  1242. 'span' => "this contains six spaces\nand one line break",
  1243. 'is same as' => "this contains six spaces\nand one line break"
  1244. ]
  1245. ---
  1246. test: Double quotes
  1247. todo: true
  1248. yaml: |
  1249. empty: ""
  1250. second: "! : etc. can be used freely."
  1251. third: "a \" or a \\ must be escaped."
  1252. fourth: "this value ends with an LF.\n"
  1253. span: "this contains
  1254. four \
  1255. spaces"
  1256. is equal to: "this contains four spaces"
  1257. php: |
  1258. [
  1259. 'empty' => '',
  1260. 'second' => '! : etc. can be used freely.',
  1261. 'third' => 'a " or a \\ must be escaped.',
  1262. 'fourth' => "this value ends with an LF.\n",
  1263. 'span' => "this contains four spaces",
  1264. 'is equal to' => "this contains four spaces"
  1265. ]
  1266. ---
  1267. test: Unquoted strings
  1268. todo: true
  1269. yaml: |
  1270. first: There is no unquoted empty string.
  1271. second: 12 ## This is an integer.
  1272. third: !!str 12 ## This is a string.
  1273. span: this contains
  1274. six spaces
  1275. and one
  1276. line break
  1277. indicators: this has no comments.
  1278. #:foo and bar# are
  1279. both text.
  1280. flow: [ can span
  1281. lines, # comment
  1282. like
  1283. this ]
  1284. note: { one-line keys: but multi-line values }
  1285. php: |
  1286. [
  1287. 'first' => 'There is no unquoted empty string.',
  1288. 'second' => 12,
  1289. 'third' => '12',
  1290. 'span' => "this contains six spaces\nand one line break",
  1291. 'indicators' => "this has no comments. #:foo and bar# are both text.",
  1292. 'flow' => [ 'can span lines', 'like this' ],
  1293. 'note' => { 'one-line keys' => 'but multi-line values' }
  1294. ]
  1295. ---
  1296. test: Spanning sequences
  1297. todo: true
  1298. yaml: |
  1299. # The following are equal seqs
  1300. # with different identities.
  1301. flow: [ one, two ]
  1302. spanning: [ one,
  1303. two ]
  1304. block:
  1305. - one
  1306. - two
  1307. php: |
  1308. [
  1309. 'flow' => [ 'one', 'two' ],
  1310. 'spanning' => [ 'one', 'two' ],
  1311. 'block' => [ 'one', 'two' ]
  1312. ]
  1313. ---
  1314. test: Flow mappings
  1315. yaml: |
  1316. # The following are equal maps
  1317. # with different identities.
  1318. flow: { one: 1, two: 2 }
  1319. block:
  1320. one: 1
  1321. two: 2
  1322. php: |
  1323. [
  1324. 'flow' => [ 'one' => 1, 'two' => 2 ],
  1325. 'block' => [ 'one' => 1, 'two' => 2 ]
  1326. ]
  1327. ---
  1328. test: Representations of 12
  1329. todo: true
  1330. yaml: |
  1331. - 12 # An integer
  1332. # The following scalars
  1333. # are loaded to the
  1334. # string value '1' '2'.
  1335. - !!str 12
  1336. - '12'
  1337. - "12"
  1338. - "\
  1339. 1\
  1340. 2\
  1341. "
  1342. # Strings containing paths and regexps can be unquoted:
  1343. - /foo/bar
  1344. - d:/foo/bar
  1345. - foo/bar
  1346. - /a.*b/
  1347. php: |
  1348. [ 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' ]
  1349. ---
  1350. test: "Null"
  1351. todo: true
  1352. yaml: |
  1353. canonical: ~
  1354. english: null
  1355. # This sequence has five
  1356. # entries, two with values.
  1357. sparse:
  1358. - ~
  1359. - 2nd entry
  1360. - Null
  1361. - 4th entry
  1362. -
  1363. four: This mapping has five keys,
  1364. only two with values.
  1365. php: |
  1366. [
  1367. 'canonical' => null,
  1368. 'english' => null,
  1369. 'sparse' => [ null, '2nd entry', null, '4th entry', null ]],
  1370. 'four' => 'This mapping has five keys, only two with values.'
  1371. ]
  1372. ---
  1373. test: Omap
  1374. todo: true
  1375. yaml: |
  1376. # Explicitly typed dictionary.
  1377. Bestiary: !omap
  1378. - aardvark: African pig-like ant eater. Ugly.
  1379. - anteater: South-American ant eater. Two species.
  1380. - anaconda: South-American constrictor snake. Scary.
  1381. # Etc.
  1382. ruby: |
  1383. {
  1384. 'Bestiary' => YAML::Omap[
  1385. 'aardvark', 'African pig-like ant eater. Ugly.',
  1386. 'anteater', 'South-American ant eater. Two species.',
  1387. 'anaconda', 'South-American constrictor snake. Scary.'
  1388. ]
  1389. }
  1390. ---
  1391. test: Pairs
  1392. todo: true
  1393. yaml: |
  1394. # Explicitly typed pairs.
  1395. tasks: !pairs
  1396. - meeting: with team.
  1397. - meeting: with boss.
  1398. - break: lunch.
  1399. - meeting: with client.
  1400. ruby: |
  1401. {
  1402. 'tasks' => YAML::Pairs[
  1403. 'meeting', 'with team.',
  1404. 'meeting', 'with boss.',
  1405. 'break', 'lunch.',
  1406. 'meeting', 'with client.'
  1407. ]
  1408. }
  1409. ---
  1410. test: Set
  1411. todo: true
  1412. yaml: |
  1413. # Explicitly typed set.
  1414. baseball players: !set
  1415. Mark McGwire:
  1416. Sammy Sosa:
  1417. Ken Griffey:
  1418. ruby: |
  1419. {
  1420. 'baseball players' => YAML::Set[
  1421. 'Mark McGwire', nil,
  1422. 'Sammy Sosa', nil,
  1423. 'Ken Griffey', nil
  1424. ]
  1425. }
  1426. ---
  1427. test: Integer
  1428. yaml: |
  1429. canonical: 12345
  1430. octal: 014
  1431. hexadecimal: 0xC
  1432. php: |
  1433. [
  1434. 'canonical' => 12345,
  1435. 'octal' => 12,
  1436. 'hexadecimal' => 12
  1437. ]
  1438. ---
  1439. test: Float
  1440. yaml: |
  1441. canonical: 1.23015e+3
  1442. exponential: 12.3015e+02
  1443. negative infinity: -.inf
  1444. not a number: .NaN
  1445. php: |
  1446. [
  1447. 'canonical' => 1230.15,
  1448. 'exponential' => 1230.15,
  1449. 'negative infinity' => log(0),
  1450. 'not a number' => -log(0)
  1451. ]
  1452. ---
  1453. test: Timestamp
  1454. todo: true
  1455. yaml: |
  1456. canonical: 2001-12-15T02:59:43.1Z
  1457. valid iso8601: 2001-12-14t21:59:43.10-05:00
  1458. space separated: 2001-12-14 21:59:43.10 -05:00
  1459. date (noon UTC): 2002-12-14
  1460. ruby: |
  1461. [
  1462. 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ),
  1463. 'valid iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  1464. 'space separated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  1465. 'date (noon UTC)' => Date.new( 2002, 12, 14 )
  1466. ]
  1467. ---
  1468. test: Binary
  1469. todo: true
  1470. yaml: |
  1471. canonical: !binary "\
  1472. R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
  1473. OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
  1474. +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
  1475. AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
  1476. base64: !binary |
  1477. R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
  1478. OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
  1479. +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
  1480. AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
  1481. description: >
  1482. The binary value above is a tiny arrow
  1483. encoded as a gif image.
  1484. ruby-setup: |
  1485. 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;"
  1486. ruby: |
  1487. {
  1488. 'canonical' => arrow_gif,
  1489. 'base64' => arrow_gif,
  1490. 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n"
  1491. }
  1492. ---
  1493. test: Merge key
  1494. todo: true
  1495. yaml: |
  1496. ---
  1497. - &CENTER { x: 1, y: 2 }
  1498. - &LEFT { x: 0, y: 2 }
  1499. - &BIG { r: 10 }
  1500. - &SMALL { r: 1 }
  1501. # All the following maps are equal:
  1502. - # Explicit keys
  1503. x: 1
  1504. y: 2
  1505. r: 10
  1506. label: center/big
  1507. - # Merge one map
  1508. << : *CENTER
  1509. r: 10
  1510. label: center/big
  1511. - # Merge multiple maps
  1512. << : [ *CENTER, *BIG ]
  1513. label: center/big
  1514. - # Override
  1515. << : [ *BIG, *LEFT, *SMALL ]
  1516. x: 1
  1517. label: center/big
  1518. ruby-setup: |
  1519. center = { 'x' => 1, 'y' => 2 }
  1520. left = { 'x' => 0, 'y' => 2 }
  1521. big = { 'r' => 10 }
  1522. small = { 'r' => 1 }
  1523. node1 = { 'x' => 1, 'y' => 2, 'r' => 10, 'label' => 'center/big' }
  1524. node2 = center.dup
  1525. node2.update( { 'r' => 10, 'label' => 'center/big' } )
  1526. node3 = big.dup
  1527. node3.update( center )
  1528. node3.update( { 'label' => 'center/big' } )
  1529. node4 = small.dup
  1530. node4.update( left )
  1531. node4.update( big )
  1532. node4.update( { 'x' => 1, 'label' => 'center/big' } )
  1533. ruby: |
  1534. [
  1535. center, left, big, small, node1, node2, node3, node4
  1536. ]
  1537. ---
  1538. test: Default key
  1539. todo: true
  1540. yaml: |
  1541. --- # Old schema
  1542. link with:
  1543. - library1.dll
  1544. - library2.dll
  1545. --- # New schema
  1546. link with:
  1547. - = : library1.dll
  1548. version: 1.2
  1549. - = : library2.dll
  1550. version: 2.3
  1551. ruby: |
  1552. y = YAML::Stream.new
  1553. y.add( { 'link with' => [ 'library1.dll', 'library2.dll' ] } )
  1554. obj_h = Hash[ 'version' => 1.2 ]
  1555. obj_h.default = 'library1.dll'
  1556. obj_h2 = Hash[ 'version' => 2.3 ]
  1557. obj_h2.default = 'library2.dll'
  1558. y.add( { 'link with' => [ obj_h, obj_h2 ] } )
  1559. documents: 2
  1560. ---
  1561. test: Special keys
  1562. todo: true
  1563. yaml: |
  1564. "!": These three keys
  1565. "&": had to be quoted
  1566. "=": and are normal strings.
  1567. # NOTE: the following node should NOT be serialized this way.
  1568. encoded node :
  1569. !special '!' : '!type'
  1570. !special|canonical '&' : 12
  1571. = : value
  1572. # The proper way to serialize the above node is as follows:
  1573. node : !!type &12 value
  1574. ruby: |
  1575. { '!' => 'These three keys', '&' => 'had to be quoted',
  1576. '=' => 'and are normal strings.',
  1577. 'encoded node' => YAML::PrivateType.new( 'type', 'value' ),
  1578. 'node' => YAML::PrivateType.new( 'type', 'value' ) }