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