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