YtsSpecificationExamples.yml 40 KB

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