YtsSpecificationExamples.yml 41 KB

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