YtsSpecificationExamples.yml 41 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. 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: 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. array(
  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. array(
  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. array(
  737. 'invoice' => 34843, 'date' => gmmktime(0, 0, 0, 1, 23, 2001),
  738. 'bill-to' =>
  739. array( 'given' => 'Chris', 'family' => 'Dumars', 'address' => array( 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ) )
  740. , 'ship-to' =>
  741. array( 'given' => 'Chris', 'family' => 'Dumars', 'address' => array( 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ) )
  742. , 'product' =>
  743. array(
  744. array( 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 ),
  745. array( '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. array(
  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. array(
  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. yaml: |
  905. integer: 12
  906. also int: ! "12"
  907. string: !str 12
  908. php: |
  909. array( 'integer' => 12, 'also int' => 12, 'string' => '12' )
  910. ---
  911. test: Private types
  912. todo: true
  913. yaml: |
  914. # Both examples below make use of the 'x-private:ball'
  915. # type family URI, but with different semantics.
  916. ---
  917. pool: !!ball
  918. number: 8
  919. color: black
  920. ---
  921. bearing: !!ball
  922. material: steel
  923. ruby: |
  924. y = YAML::Stream.new
  925. y.add( { 'pool' =>
  926. YAML::PrivateType.new( 'ball',
  927. { 'number' => 8, 'color' => 'black' } ) }
  928. )
  929. y.add( { 'bearing' =>
  930. YAML::PrivateType.new( 'ball',
  931. { 'material' => 'steel' } ) }
  932. )
  933. documents: 2
  934. ---
  935. test: Type family under yaml.org
  936. yaml: |
  937. # The URI is 'tag:yaml.org,2002:str'
  938. - !str a Unicode string
  939. php: |
  940. array( 'a Unicode string' )
  941. ---
  942. test: Type family under perl.yaml.org
  943. todo: true
  944. yaml: |
  945. # The URI is 'tag:perl.yaml.org,2002:Text::Tabs'
  946. - !perl/Text::Tabs {}
  947. ruby: |
  948. [ YAML::DomainType.new( 'perl.yaml.org,2002', 'Text::Tabs', {} ) ]
  949. ---
  950. test: Type family under clarkevans.com
  951. todo: true
  952. yaml: |
  953. # The URI is 'tag:clarkevans.com,2003-02:timesheet'
  954. - !clarkevans.com,2003-02/timesheet {}
  955. ruby: |
  956. [ YAML::DomainType.new( 'clarkevans.com,2003-02', 'timesheet', {} ) ]
  957. ---
  958. test: URI Escaping
  959. todo: true
  960. yaml: |
  961. same:
  962. - !domain.tld,2002/type\x30 value
  963. - !domain.tld,2002/type0 value
  964. different: # As far as the YAML parser is concerned
  965. - !domain.tld,2002/type%30 value
  966. - !domain.tld,2002/type0 value
  967. ruby-setup: |
  968. YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
  969. "ONE: #{val}"
  970. }
  971. YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
  972. "TWO: #{val}"
  973. }
  974. ruby: |
  975. { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value', 'ONE: value' ] }
  976. ---
  977. test: URI Prefixing
  978. todo: true
  979. yaml: |
  980. # 'tag:domain.tld,2002:invoice' is some type family.
  981. invoice: !domain.tld,2002/^invoice
  982. # 'seq' is shorthand for 'tag:yaml.org,2002:seq'.
  983. # This does not effect '^customer' below
  984. # because it is does not specify a prefix.
  985. customers: !seq
  986. # '^customer' is shorthand for the full
  987. # notation 'tag:domain.tld,2002:customer'.
  988. - !^customer
  989. given : Chris
  990. family : Dumars
  991. ruby-setup: |
  992. YAML.add_domain_type( "domain.tld,2002", /(invoice|customer)/ ) { |type, val|
  993. if val.is_a? ::Hash
  994. scheme, domain, type = type.split( /:/, 3 )
  995. val['type'] = "domain #{type}"
  996. val
  997. else
  998. raise YAML::Error, "Not a Hash in domain.tld/invoice: " + val.inspect
  999. end
  1000. }
  1001. ruby: |
  1002. { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }
  1003. ---
  1004. test: Overriding anchors
  1005. yaml: |
  1006. anchor : &A001 This scalar has an anchor.
  1007. override : &A001 >
  1008. The alias node below is a
  1009. repeated use of this value.
  1010. alias : *A001
  1011. php: |
  1012. array( 'anchor' => 'This scalar has an anchor.',
  1013. 'override' => "The alias node below is a repeated use of this value.\n",
  1014. 'alias' => "The alias node below is a repeated use of this value.\n" )
  1015. ---
  1016. test: Flow and block formatting
  1017. todo: true
  1018. yaml: |
  1019. empty: []
  1020. flow: [ one, two, three # May span lines,
  1021. , four, # indentation is
  1022. five ] # mostly ignored.
  1023. block:
  1024. - First item in top sequence
  1025. -
  1026. - Subordinate sequence entry
  1027. - >
  1028. A folded sequence entry
  1029. - Sixth item in top sequence
  1030. ruby: |
  1031. { 'empty' => [], 'flow' => [ 'one', 'two', 'three', 'four', 'five' ],
  1032. 'block' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ],
  1033. "A folded sequence entry\n", 'Sixth item in top sequence' ] }
  1034. ---
  1035. test: Complete mapping test
  1036. todo: true
  1037. yaml: |
  1038. empty: {}
  1039. flow: { one: 1, two: 2 }
  1040. spanning: { one: 1,
  1041. two: 2 }
  1042. block:
  1043. first : First entry
  1044. second:
  1045. key: Subordinate mapping
  1046. third:
  1047. - Subordinate sequence
  1048. - { }
  1049. - Previous mapping is empty.
  1050. - A key: value pair in a sequence.
  1051. A second: key:value pair.
  1052. - The previous entry is equal to the following one.
  1053. -
  1054. A key: value pair in a sequence.
  1055. A second: key:value pair.
  1056. !float 12 : This key is a float.
  1057. ? >
  1058. ?
  1059. : This key had to be protected.
  1060. "\a" : This key had to be escaped.
  1061. ? >
  1062. This is a
  1063. multi-line
  1064. folded key
  1065. : Whose value is
  1066. also multi-line.
  1067. ? this also works as a key
  1068. : with a value at the next line.
  1069. ?
  1070. - This key
  1071. - is a sequence
  1072. :
  1073. - With a sequence value.
  1074. ?
  1075. This: key
  1076. is a: mapping
  1077. :
  1078. with a: mapping value.
  1079. ruby: |
  1080. { 'empty' => {}, 'flow' => { 'one' => 1, 'two' => 2 },
  1081. 'spanning' => { 'one' => 1, 'two' => 2 },
  1082. 'block' => { 'first' => 'First entry', 'second' =>
  1083. { 'key' => 'Subordinate mapping' }, 'third' =>
  1084. [ 'Subordinate sequence', {}, 'Previous mapping is empty.',
  1085. { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' },
  1086. 'The previous entry is equal to the following one.',
  1087. { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ],
  1088. 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.',
  1089. "\a" => 'This key had to be escaped.',
  1090. "This is a multi-line folded key\n" => "Whose value is also multi-line.",
  1091. 'this also works as a key' => 'with a value at the next line.',
  1092. [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }
  1093. # Couldn't recreate map exactly, so we'll do a detailed check to be sure it's entact
  1094. obj_y['block'].keys.each { |k|
  1095. if Hash === k
  1096. v = obj_y['block'][k]
  1097. if k['This'] == 'key' and k['is a'] == 'mapping' and v['with a'] == 'mapping value.'
  1098. obj_r['block'][k] = v
  1099. end
  1100. end
  1101. }
  1102. ---
  1103. test: Literal explicit indentation
  1104. yaml: |
  1105. # Explicit indentation must
  1106. # be given in all the three
  1107. # following cases.
  1108. leading spaces: |2
  1109. This value starts with four spaces.
  1110. leading line break: |2
  1111. This value starts with a line break.
  1112. leading comment indicator: |2
  1113. # first line starts with a
  1114. # character.
  1115. # Explicit indentation may
  1116. # also be given when it is
  1117. # not required.
  1118. redundant: |2
  1119. This value is indented 2 spaces.
  1120. php: |
  1121. array(
  1122. 'leading spaces' => " This value starts with four spaces.\n",
  1123. 'leading line break' => "\nThis value starts with a line break.\n",
  1124. 'leading comment indicator' => "# first line starts with a\n# character.\n",
  1125. 'redundant' => "This value is indented 2 spaces.\n"
  1126. )
  1127. ---
  1128. test: Chomping and keep modifiers
  1129. yaml: |
  1130. clipped: |
  1131. This has one newline.
  1132. same as "clipped" above: "This has one newline.\n"
  1133. stripped: |-
  1134. This has no newline.
  1135. same as "stripped" above: "This has no newline."
  1136. kept: |+
  1137. This has two newlines.
  1138. same as "kept" above: "This has two newlines.\n\n"
  1139. php: |
  1140. array(
  1141. 'clipped' => "This has one newline.\n",
  1142. 'same as "clipped" above' => "This has one newline.\n",
  1143. 'stripped' => 'This has no newline.',
  1144. 'same as "stripped" above' => 'This has no newline.',
  1145. 'kept' => "This has two newlines.\n\n",
  1146. 'same as "kept" above' => "This has two newlines.\n\n"
  1147. )
  1148. ---
  1149. test: Literal combinations
  1150. todo: true
  1151. yaml: |
  1152. empty: |
  1153. literal: |
  1154. The \ ' " characters may be
  1155. freely used. Leading white
  1156. space is significant.
  1157. Line breaks are significant.
  1158. Thus this value contains one
  1159. empty line and ends with a
  1160. single line break, but does
  1161. not start with one.
  1162. is equal to: "The \\ ' \" characters may \
  1163. be\nfreely used. Leading white\n space \
  1164. is significant.\n\nLine breaks are \
  1165. significant.\nThus this value contains \
  1166. one\nempty line and ends with a\nsingle \
  1167. line break, but does\nnot start with one.\n"
  1168. # Comments may follow a block
  1169. # scalar value. They must be
  1170. # less indented.
  1171. # Modifiers may be combined in any order.
  1172. indented and chomped: |2-
  1173. This has no newline.
  1174. also written as: |-2
  1175. This has no newline.
  1176. both are equal to: " This has no newline."
  1177. php: |
  1178. array(
  1179. 'empty' => '',
  1180. 'literal' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " +
  1181. "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" +
  1182. "empty line and ends with a\nsingle line break, but does\nnot start with one.\n",
  1183. 'is equal to' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " +
  1184. "is significant.\n\nLine breaks are significant.\nThus this value contains one\n" +
  1185. "empty line and ends with a\nsingle line break, but does\nnot start with one.\n",
  1186. 'indented and chomped' => ' This has no newline.',
  1187. 'also written as' => ' This has no newline.',
  1188. 'both are equal to' => ' This has no newline.'
  1189. )
  1190. ---
  1191. test: Folded combinations
  1192. todo: true
  1193. yaml: |
  1194. empty: >
  1195. one paragraph: >
  1196. Line feeds are converted
  1197. to spaces, so this value
  1198. contains no line breaks
  1199. except for the final one.
  1200. multiple paragraphs: >2
  1201. An empty line, either
  1202. at the start or in
  1203. the value:
  1204. Is interpreted as a
  1205. line break. Thus this
  1206. value contains three
  1207. line breaks.
  1208. indented text: >
  1209. This is a folded
  1210. paragraph followed
  1211. by a list:
  1212. * first entry
  1213. * second entry
  1214. Followed by another
  1215. folded paragraph,
  1216. another list:
  1217. * first entry
  1218. * second entry
  1219. And a final folded
  1220. paragraph.
  1221. above is equal to: |
  1222. This is a folded paragraph followed by a list:
  1223. * first entry
  1224. * second entry
  1225. Followed by another folded paragraph, another list:
  1226. * first entry
  1227. * second entry
  1228. And a final folded paragraph.
  1229. # Explicit comments may follow
  1230. # but must be less indented.
  1231. php: |
  1232. array(
  1233. 'empty' => '',
  1234. 'one paragraph' => 'Line feeds are converted to spaces, so this value'.
  1235. " contains no line breaks except for the final one.\n",
  1236. 'multiple paragraphs' => "\nAn empty line, either at the start or in the value:\n".
  1237. "Is interpreted as a line break. Thus this value contains three line breaks.\n",
  1238. 'indented text' => "This is a folded paragraph followed by a list:\n".
  1239. " * first entry\n * second entry\nFollowed by another folded paragraph, ".
  1240. "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n",
  1241. 'above is equal to' => "This is a folded paragraph followed by a list:\n".
  1242. " * first entry\n * second entry\nFollowed by another folded paragraph, ".
  1243. "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n"
  1244. )
  1245. ---
  1246. test: Single quotes
  1247. todo: true
  1248. yaml: |
  1249. empty: ''
  1250. second: '! : \ etc. can be used freely.'
  1251. third: 'a single quote '' must be escaped.'
  1252. span: 'this contains
  1253. six spaces
  1254. and one
  1255. line break'
  1256. is same as: "this contains six spaces\nand one line break"
  1257. php: |
  1258. array(
  1259. 'empty' => '',
  1260. 'second' => '! : \\ etc. can be used freely.',
  1261. 'third' => "a single quote ' must be escaped.",
  1262. 'span' => "this contains six spaces\nand one line break",
  1263. 'is same as' => "this contains six spaces\nand one line break"
  1264. )
  1265. ---
  1266. test: Double quotes
  1267. todo: true
  1268. yaml: |
  1269. empty: ""
  1270. second: "! : etc. can be used freely."
  1271. third: "a \" or a \\ must be escaped."
  1272. fourth: "this value ends with an LF.\n"
  1273. span: "this contains
  1274. four \
  1275. spaces"
  1276. is equal to: "this contains four spaces"
  1277. php: |
  1278. array(
  1279. 'empty' => '',
  1280. 'second' => '! : etc. can be used freely.',
  1281. 'third' => 'a " or a \\ must be escaped.',
  1282. 'fourth' => "this value ends with an LF.\n",
  1283. 'span' => "this contains four spaces",
  1284. 'is equal to' => "this contains four spaces"
  1285. )
  1286. ---
  1287. test: Unquoted strings
  1288. todo: true
  1289. yaml: |
  1290. first: There is no unquoted empty string.
  1291. second: 12 ## This is an integer.
  1292. third: !str 12 ## This is a string.
  1293. span: this contains
  1294. six spaces
  1295. and one
  1296. line break
  1297. indicators: this has no comments.
  1298. #:foo and bar# are
  1299. both text.
  1300. flow: [ can span
  1301. lines, # comment
  1302. like
  1303. this ]
  1304. note: { one-line keys: but multi-line values }
  1305. php: |
  1306. array(
  1307. 'first' => 'There is no unquoted empty string.',
  1308. 'second' => 12,
  1309. 'third' => '12',
  1310. 'span' => "this contains six spaces\nand one line break",
  1311. 'indicators' => "this has no comments. #:foo and bar# are both text.",
  1312. 'flow' => [ 'can span lines', 'like this' ],
  1313. 'note' => { 'one-line keys' => 'but multi-line values' }
  1314. )
  1315. ---
  1316. test: Spanning sequences
  1317. todo: true
  1318. yaml: |
  1319. # The following are equal seqs
  1320. # with different identities.
  1321. flow: [ one, two ]
  1322. spanning: [ one,
  1323. two ]
  1324. block:
  1325. - one
  1326. - two
  1327. php: |
  1328. array(
  1329. 'flow' => [ 'one', 'two' ],
  1330. 'spanning' => [ 'one', 'two' ],
  1331. 'block' => [ 'one', 'two' ]
  1332. )
  1333. ---
  1334. test: Flow mappings
  1335. yaml: |
  1336. # The following are equal maps
  1337. # with different identities.
  1338. flow: { one: 1, two: 2 }
  1339. block:
  1340. one: 1
  1341. two: 2
  1342. php: |
  1343. array(
  1344. 'flow' => array( 'one' => 1, 'two' => 2 ),
  1345. 'block' => array( 'one' => 1, 'two' => 2 )
  1346. )
  1347. ---
  1348. test: Representations of 12
  1349. todo: true
  1350. yaml: |
  1351. - 12 # An integer
  1352. # The following scalars
  1353. # are loaded to the
  1354. # string value '1' '2'.
  1355. - !str 12
  1356. - '12'
  1357. - "12"
  1358. - "\
  1359. 1\
  1360. 2\
  1361. "
  1362. # Strings containing paths and regexps can be unquoted:
  1363. - /foo/bar
  1364. - d:/foo/bar
  1365. - foo/bar
  1366. - /a.*b/
  1367. php: |
  1368. array( 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' )
  1369. ---
  1370. test: "Null"
  1371. todo: true
  1372. yaml: |
  1373. canonical: ~
  1374. english: null
  1375. # This sequence has five
  1376. # entries, two with values.
  1377. sparse:
  1378. - ~
  1379. - 2nd entry
  1380. - Null
  1381. - 4th entry
  1382. -
  1383. four: This mapping has five keys,
  1384. only two with values.
  1385. php: |
  1386. array (
  1387. 'canonical' => null,
  1388. 'english' => null,
  1389. 'sparse' => array( null, '2nd entry', null, '4th entry', null ]),
  1390. 'four' => 'This mapping has five keys, only two with values.'
  1391. )
  1392. ---
  1393. test: Omap
  1394. todo: true
  1395. yaml: |
  1396. # Explicitly typed dictionary.
  1397. Bestiary: !omap
  1398. - aardvark: African pig-like ant eater. Ugly.
  1399. - anteater: South-American ant eater. Two species.
  1400. - anaconda: South-American constrictor snake. Scary.
  1401. # Etc.
  1402. ruby: |
  1403. {
  1404. 'Bestiary' => YAML::Omap[
  1405. 'aardvark', 'African pig-like ant eater. Ugly.',
  1406. 'anteater', 'South-American ant eater. Two species.',
  1407. 'anaconda', 'South-American constrictor snake. Scary.'
  1408. ]
  1409. }
  1410. ---
  1411. test: Pairs
  1412. todo: true
  1413. yaml: |
  1414. # Explicitly typed pairs.
  1415. tasks: !pairs
  1416. - meeting: with team.
  1417. - meeting: with boss.
  1418. - break: lunch.
  1419. - meeting: with client.
  1420. ruby: |
  1421. {
  1422. 'tasks' => YAML::Pairs[
  1423. 'meeting', 'with team.',
  1424. 'meeting', 'with boss.',
  1425. 'break', 'lunch.',
  1426. 'meeting', 'with client.'
  1427. ]
  1428. }
  1429. ---
  1430. test: Set
  1431. todo: true
  1432. yaml: |
  1433. # Explicitly typed set.
  1434. baseball players: !set
  1435. Mark McGwire:
  1436. Sammy Sosa:
  1437. Ken Griffey:
  1438. ruby: |
  1439. {
  1440. 'baseball players' => YAML::Set[
  1441. 'Mark McGwire', nil,
  1442. 'Sammy Sosa', nil,
  1443. 'Ken Griffey', nil
  1444. ]
  1445. }
  1446. ---
  1447. test: Integer
  1448. yaml: |
  1449. canonical: 12345
  1450. octal: 014
  1451. hexadecimal: 0xC
  1452. php: |
  1453. array(
  1454. 'canonical' => 12345,
  1455. 'octal' => 12,
  1456. 'hexadecimal' => 12
  1457. )
  1458. ---
  1459. test: Decimal
  1460. deprecated: true
  1461. yaml: |
  1462. decimal: +12,345
  1463. php: |
  1464. array(
  1465. 'decimal' => 12345.0,
  1466. )
  1467. ---
  1468. test: Fixed Float
  1469. deprecated: true
  1470. yaml: |
  1471. fixed: 1,230.15
  1472. php: |
  1473. array(
  1474. 'fixed' => 1230.15,
  1475. )
  1476. ---
  1477. test: Float
  1478. yaml: |
  1479. canonical: 1.23015e+3
  1480. exponential: 12.3015e+02
  1481. negative infinity: -.inf
  1482. not a number: .NaN
  1483. php: |
  1484. array(
  1485. 'canonical' => 1230.15,
  1486. 'exponential' => 1230.15,
  1487. 'negative infinity' => log(0),
  1488. 'not a number' => -log(0)
  1489. )
  1490. ---
  1491. test: Timestamp
  1492. todo: true
  1493. yaml: |
  1494. canonical: 2001-12-15T02:59:43.1Z
  1495. valid iso8601: 2001-12-14t21:59:43.10-05:00
  1496. space separated: 2001-12-14 21:59:43.10 -05:00
  1497. date (noon UTC): 2002-12-14
  1498. ruby: |
  1499. array(
  1500. 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ),
  1501. 'valid iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  1502. 'space separated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
  1503. 'date (noon UTC)' => Date.new( 2002, 12, 14 )
  1504. )
  1505. ---
  1506. test: Binary
  1507. todo: true
  1508. yaml: |
  1509. canonical: !binary "\
  1510. R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
  1511. OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
  1512. +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
  1513. AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
  1514. base64: !binary |
  1515. R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
  1516. OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
  1517. +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
  1518. AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
  1519. description: >
  1520. The binary value above is a tiny arrow
  1521. encoded as a gif image.
  1522. ruby-setup: |
  1523. 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;"
  1524. ruby: |
  1525. {
  1526. 'canonical' => arrow_gif,
  1527. 'base64' => arrow_gif,
  1528. 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n"
  1529. }
  1530. ---
  1531. test: Merge key
  1532. todo: true
  1533. yaml: |
  1534. ---
  1535. - &CENTER { x: 1, y: 2 }
  1536. - &LEFT { x: 0, y: 2 }
  1537. - &BIG { r: 10 }
  1538. - &SMALL { r: 1 }
  1539. # All the following maps are equal:
  1540. - # Explicit keys
  1541. x: 1
  1542. y: 2
  1543. r: 10
  1544. label: center/big
  1545. - # Merge one map
  1546. << : *CENTER
  1547. r: 10
  1548. label: center/big
  1549. - # Merge multiple maps
  1550. << : [ *CENTER, *BIG ]
  1551. label: center/big
  1552. - # Override
  1553. << : [ *BIG, *LEFT, *SMALL ]
  1554. x: 1
  1555. label: center/big
  1556. ruby-setup: |
  1557. center = { 'x' => 1, 'y' => 2 }
  1558. left = { 'x' => 0, 'y' => 2 }
  1559. big = { 'r' => 10 }
  1560. small = { 'r' => 1 }
  1561. node1 = { 'x' => 1, 'y' => 2, 'r' => 10, 'label' => 'center/big' }
  1562. node2 = center.dup
  1563. node2.update( { 'r' => 10, 'label' => 'center/big' } )
  1564. node3 = big.dup
  1565. node3.update( center )
  1566. node3.update( { 'label' => 'center/big' } )
  1567. node4 = small.dup
  1568. node4.update( left )
  1569. node4.update( big )
  1570. node4.update( { 'x' => 1, 'label' => 'center/big' } )
  1571. ruby: |
  1572. [
  1573. center, left, big, small, node1, node2, node3, node4
  1574. ]
  1575. ---
  1576. test: Default key
  1577. todo: true
  1578. yaml: |
  1579. --- # Old schema
  1580. link with:
  1581. - library1.dll
  1582. - library2.dll
  1583. --- # New schema
  1584. link with:
  1585. - = : library1.dll
  1586. version: 1.2
  1587. - = : library2.dll
  1588. version: 2.3
  1589. ruby: |
  1590. y = YAML::Stream.new
  1591. y.add( { 'link with' => [ 'library1.dll', 'library2.dll' ] } )
  1592. obj_h = Hash[ 'version' => 1.2 ]
  1593. obj_h.default = 'library1.dll'
  1594. obj_h2 = Hash[ 'version' => 2.3 ]
  1595. obj_h2.default = 'library2.dll'
  1596. y.add( { 'link with' => [ obj_h, obj_h2 ] } )
  1597. documents: 2
  1598. ---
  1599. test: Special keys
  1600. todo: true
  1601. yaml: |
  1602. "!": These three keys
  1603. "&": had to be quoted
  1604. "=": and are normal strings.
  1605. # NOTE: the following node should NOT be serialized this way.
  1606. encoded node :
  1607. !special '!' : '!type'
  1608. !special|canonical '&' : 12
  1609. = : value
  1610. # The proper way to serialize the above node is as follows:
  1611. node : !!type &12 value
  1612. ruby: |
  1613. { '!' => 'These three keys', '&' => 'had to be quoted',
  1614. '=' => 'and are normal strings.',
  1615. 'encoded node' => YAML::PrivateType.new( 'type', 'value' ),
  1616. 'node' => YAML::PrivateType.new( 'type', 'value' ) }