YtsSpecificationExamples.yml 41 KB

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