-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyamltest.ml
1753 lines (1669 loc) · 42.3 KB
/
yamltest.ml
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
open OUnit2
open OUnitTest
open Yaml
open Pa_ppx_testutils
let warning s = Fmt.(pf stderr "%s\n%!" s)
let matches ~pattern text =
match Str.search_forward (Str.regexp pattern) text 0 with
_ -> true
| exception Not_found -> false
let assert_raises_exn_pattern pattern f =
Testutil.assert_raises_exn_pred
(function
Failure msg when matches ~pattern msg -> true
| Invalid_argument msg when matches ~pattern msg -> true
| _ -> false
)
f
let printer x = Fmt.(str "%a" Yaytypes.pp_yaml x)
let cmp = Yaytypes.equal_yaml
let preview = "preview" >::: [
"2.1" >:: (fun ctxt ->
assert_equal ~printer
(`A (
[`String ("Mark McGwire")
; `String ("Sammy Sosa")
; `String ("Ken Griffey")]
))
(of_string_exn {|- Mark McGwire
- Sammy Sosa
- Ken Griffey|})
)
; "2.2" >:: (fun ctxt ->
assert_equal ~printer
(`O ([("hr", `Float (65.)); ("avg", `Float (0.278)); ("rbi", `Float (147.))]))
(of_string_exn {|hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In|})
)
; "2.3" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("american",
`A (
[`String ("Boston Red Sox"); `String ("Detroit Tigers");
`String ("New York Yankees")]
));
("national",
`A (
[`String ("New York Mets"); `String ("Chicago Cubs");
`String ("Atlanta Braves")]
))
]
))
(of_string_exn {|american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves|})
)
; "2.4" >:: (fun ctxt ->
assert_equal ~printer
(`A (
[`O (
[("name", `String ("Mark McGwire")); ("hr", `Float (65.));
("avg", `Float (0.278))]
);
`O (
[("name", `String ("Sammy Sosa")); ("hr", `Float (63.));
("avg", `Float (0.288))]
)
]
))
(of_string_exn {|-
name: Mark McGwire
hr: 65
avg: 0.278
-
name: Sammy Sosa
hr: 63
avg: 0.288|})
)
; "2.5" >:: (fun ctxt ->
assert_equal ~printer
(`A (
[`A ([`String ("name"); `String ("hr"); `String ("avg")]);
`A ([`String ("Mark McGwire"); `Float (65.); `Float (0.278)]);
`A ([`String ("Sammy Sosa"); `Float (63.); `Float (0.288)])]
))
(of_string_exn {|- [name , hr, avg ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa , 63, 0.288]
|})
)
; "2.6" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("Mark McGwire", `O ([("hr", `Float (65.)); ("avg", `Float (0.278))]));
("Sammy Sosa", `O ([("hr", `Float (63.)); ("avg", `Float (0.288))]))]
))
(of_string_exn {|Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
hr: 63,
avg: 0.288
}|})
)
; "2.7" >:: (fun ctxt ->
warning "example 2.7 has multiple docs: this isn't implemented right" ;
assert_equal ~printer
(`A (
[`String ("Mark McGwire"); `String ("Sammy Sosa"); `String ("Ken Griffey")]
))
(of_string_exn {|# Ranking of 1998 home runs
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals|})
)
; "2.8" >:: (fun ctxt ->
warning "example 2.8 has multiple docs: this isn't implemented right" ;
assert_equal ~printer
(`O (
[("time", `String ("20:03:20")); ("player", `String ("Sammy Sosa"));
("action", `String ("strike (miss)"))]
))
(of_string_exn {|---
time: 20:03:20
player: Sammy Sosa
action: strike (miss)
...
---
time: 20:03:47
player: Sammy Sosa
action: grand slam
...|})
)
; "2.9" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("hr", `A ([`String ("Mark McGwire"); `String ("Sammy Sosa")]));
("rbi", `A ([`String ("Sammy Sosa"); `String ("Ken Griffey")]))]
))
(of_string_exn {|---
hr: # 1998 hr ranking
- Mark McGwire
- Sammy Sosa
rbi:
# 1998 rbi ranking
- Sammy Sosa
- Ken Griffey|})
)
; "2.10" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|---
hr:
- Mark McGwire
# Following node labeled SS
- &SS Sammy Sosa
rbi:
- *SS # Subsequent occurrence
- Ken Griffey|})
)
; "2.11" >:: (fun ctxt ->
assert_raises_exn_pattern
"only string keys are supported"
(fun () -> of_string_exn {|? - Detroit Tigers
- Chicago cubs
:
- 2001-07-23
? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]|})
)
; "2.12" >:: (fun ctxt ->
assert_equal ~printer
(`A (
[`O ([("item", `String ("Super Hoop")); ("quantity", `Float (1.))]);
`O ([("item", `String ("Basketball")); ("quantity", `Float (4.))]);
`O ([("item", `String ("Big Shoes")); ("quantity", `Float (1.))])]
))
(of_string_exn {|---
# Products purchased
- item : Super Hoop
quantity: 1
- item : Basketball
quantity: 4
- item : Big Shoes
quantity: 1
|})
)
; "2.13" >:: (fun ctxt ->
assert_equal ~printer
(`String ("\\//||\\/||\n\
// || ||__"))
(of_string_exn {|# ASCII Art
--- |
\//||\/||
// || ||__|})
)
; "2.14" >:: (fun ctxt ->
assert_equal ~printer
(`String ("Mark McGwire's year was crippled by a knee injury."))
(of_string_exn {|--- >
Mark McGwire's
year was crippled
by a knee injury.|})
)
; "2.15" >:: (fun ctxt ->
assert_equal ~printer
(`String (
"Sammy Sosa completed another fine season with great stats.\n\n\
\ 63 Home Runs\n\
\ 0.288 Batting Average\n\n\
What a year!"
))
(of_string_exn {|>
Sammy Sosa completed another
fine season with great stats.
63 Home Runs
0.288 Batting Average
What a year!|})
)
; "2.16" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("name", `String ("Mark McGwire"));
("accomplishment",
`String ("Mark set a major league home run record in 1998.\n"));
("stats", `String ("65 Home Runs\n0.278 Batting Average\n"))]
))
(of_string_exn {|name: Mark McGwire
accomplishment: >
Mark set a major league
home run record in 1998.
stats: |
65 Home Runs
0.278 Batting Average
|})
)
; "2.17" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("unicode", `String ("Sosa did fine.\226\152\186"));
("control", `String ("\b1998\t1999\t2000\n"));
("hex esc", `String ("\r\n is \r\n"));
("single", `String ("\"Howdy!\" he cried."));
("quoted", `String (" # Not a 'comment'."));
("tie-fighter", `String ("|\\-*-/|"))]
))
(of_string_exn {|unicode: "Sosa did fine.\u263A"
control: "\b1998\t1999\t2000\n"
hex esc: "\x0d\x0a is \r\n"
single: '"Howdy!" he cried.'
quoted: ' # Not a ''comment''.'
tie-fighter: '|\-*-/|'|})
)
; "2.18" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("plain", `String ("This unquoted scalar spans many lines."));
("quoted", `String ("So does this quoted scalar.\n"))]
))
(of_string_exn {|plain:
This unquoted scalar
spans many lines.
quoted: "So does this
quoted scalar.\n"
|})
)
; "2.19" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("canonical", `Float (12345.)); ("decimal", `Float (12345.));
("octal", `String ("0o14")); ("hexadecimal", `Float (12.))]
))
(of_string_exn {|canonical: 12345
decimal: +12345
octal: 0o14
hexadecimal: 0xC
|})
)
; "2.20" >:: (fun ctxt ->
assert_equal ~printer
~cmp
(`O (
[("canonical", `Float (1230.15)); ("exponential", `Float (1230.15));
("fixed", `Float (1230.15));
("negative infinity", `Float (neg_infinity));
("not a number", `Float (nan))]
))
(of_string_exn {|canonical: 1.23015e+3
exponential: 12.3015e+02
fixed: 1230.15
negative infinity: -.inf
not a number: .NaN|})
)
; "2.21" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("null", `Null); ("booleans", `A ([`Bool (true); `Bool (false)]));
("string", `String ("012345"))]
))
(of_string_exn {|null:
booleans: [ true, false ]
string: '012345'|})
)
; "2.22" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("canonical", `String ("2001-12-15T02:59:43.1Z"));
("iso8601", `String ("2001-12-14t21:59:43.10-05:00"));
("spaced", `String ("2001-12-14 21:59:43.10 -5"));
("date", `String ("2002-12-14"))]
))
(of_string_exn {|canonical: 2001-12-15T02:59:43.1Z
iso8601: 2001-12-14t21:59:43.10-05:00
spaced: 2001-12-14 21:59:43.10 -5
date: 2002-12-14|})
)
; "2.23" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("not-date", `String ("2002-04-28"));
("picture",
`String (
"R0lGODlhDAAMAIQAAP//9/X\n17unp5WZmZgAAAOfn515eXv\nPz7Y6OjuDg4J+fn5OTk6enp\n56enmleECcgggoBADs=\n"
));
("application specific tag",
`String (
"The semantics of the tag\nabove may be different for\ndifferent documents.\n"
))
]
))
(of_string_exn {|---
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.
|})
)
; "2.24" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|%TAG ! tag:clarkevans.com,2002:
--- !shape
# Use the ! handle for presenting
# tag:clarkevans.com,2002:circle
- !circle
center: &ORIGIN {x: 73, y: 129}
radius: 7
- !line
start: *ORIGIN
finish: { x: 89, y: 102 }
- !label
start: *ORIGIN
color: 0xFFEEBB
text: Pretty vector drawing.|})
)
; "2.25" >:: (fun ctxt ->
assert_equal ~printer
(`O ([("Mark McGwire", `Null); ("Sammy Sosa", `Null); ("Ken Griff", `Null)]))
(of_string_exn {|# Sets are represented as a
# Mapping where each key is
# associated with a null value
--- !!set
? Mark McGwire
? Sammy Sosa
? Ken Griff|})
)
; "2.26" >:: (fun ctxt ->
assert_equal ~printer
(`A (
[`O ([("Mark McGwire", `Float (65.))]);
`O ([("Sammy Sosa", `Float (63.))]); `O ([("Ken Griffy", `Float (58.))])]
))
(of_string_exn {|# 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|})
)
; "2.27" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|--- !<tag: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.|})
)
; "2.28" >:: (fun ctxt ->
warning "example 2.28 has multiple docs: this isn't implemented right" ;
assert_equal ~printer
(`O (
[("Time", `String ("2001-11-23 15:01:42 -5")); ("User", `String ("ed"));
("Warning", `String ("This is an error message for the log file"))]
))
(of_string_exn {|---
Time: 2001-11-23 15:01:42 -5
User: ed
Warning:
This is an error message
for the log file
---
Time: 2001-11-23 15:02:31 -5
User: ed
Warning:
A slightly different error
message.
---
Date: 2001-11-23 15:03:17 -5
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
|})
)
]
let characters = "characters" >::: [
"5.3" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("sequence", `A ([`String ("one"); `String ("two")]));
("mapping", `O ([("sky", `String ("blue")); ("sea", `String ("green"))]))
]
))
(of_string_exn {|sequence:
- one
- two
mapping:
? sky
: blue
sea : green|})
)
; "5.4" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("sequence", `A ([`String ("one"); `String ("two")]));
("mapping", `O ([("sky", `String ("blue")); ("sea", `String ("green"))]))
]
))
(of_string_exn {|
sequence: [ one, two, ]
mapping: { sky: blue, sea: green }|})
)
; "5.5" >:: (fun ctxt ->
assert_equal ~printer
(`Null)
(of_string_exn {|# Comment only.|})
)
; "5.6" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|anchored: !local &anchor value
alias: *anchor|})
)
; "5.7" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("literal", `String ("some\ntext\n")); ("folded", `String ("some text"))]))
(of_string_exn {|literal: |
some
text
folded: >
some
text|})
)
; "5.8" >:: (fun ctxt ->
assert_equal ~printer
(`O ([("single", `String ("text")); ("double", `String ("text"))]))
(of_string_exn {|
single: 'text'
double: "text"|})
)
; "5.9" >:: (fun ctxt ->
warning "example 5.9 won't work b/c ocaml-yaml is 1.1-compat" ;
assert_raises_exn_pattern
"incompatible YAML document"
(fun () -> of_string_exn {|%YAML 1.2
--- text|})
)
; "5.10" >:: (fun ctxt ->
assert_raises_exn_pattern
"found character that cannot start any token"
(fun () -> of_string_exn {|commercial-at: @text
grave-accent: `text|})
)
; "5.11" >:: (fun ctxt ->
assert_equal ~printer
(`String ("Line break (no glyph)\nLine break (glyphed)\n"))
(of_string_exn {||
Line break (no glyph)
Line break (glyphed)
|})
)
; "5.12" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("quoted", `String ("Quoted \t"));
("block", `String ("void main() {\n\
\tprintf(\"Hello, world!\\n\");\n\
}"))]
))
(of_string_exn {|# Tabs and spaces
quoted: "Quoted "
block: |
void main() {
printf("Hello, world!\n");
}|})
)
; "5.13" >:: (fun ctxt ->
warning "example 5.13 won't work b/c ocaml-yaml doesn't handle in-string NULLs right" ;
assert_equal ~printer
(`String ("Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B \x00 \x20 \xA0 \x85 \u2028 \u2029 A A A"))
(of_string_exn {|"Fun with \\
\" \a \b \e \f \
\n \r \t \v \0 \
\ \_ \N \L \P \
\x41 \u0041 \U00000041"|})
)
; "5.14" >:: (fun ctxt ->
assert_raises_exn_pattern
"unknown escape character"
(fun () -> of_string_exn {|Bad escapes:
"\c
\xq-"|})
)
]
let basic_structures = "basic structures" >::: [
"6.1" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("Not indented",
`O (
[("By one space", `String ("By four\n spaces\n"));
("Flow style",
`A (
[`String ("By two"); `String ("Also by two");
`String ("Still by two")]
))
]
))
]
))
(of_string_exn {| # Leading comment line spaces are
# neither content nor indentation.
Not indented:
By one space: |
By four
spaces
Flow style: [ # Leading spaces
By two, # in flow style
Also by two, # are neither
Still by two # content nor
] # indentation.|})
)
; "6.2" >:: (fun ctxt ->
warning "example 6.2 won't work b/c ocaml-yaml refuses to parse it (but perl's YAML::PP (1.2-compat) does)" ;
assert_raises_exn_pattern
"found character that cannot start any token"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn "? a\n\
: -\tb\n\
\ - -\tc\
\ - d"))
)
; "6.3" >:: (fun ctxt ->
warning "example 6.3 won't work b/c ocaml-yaml refuses to parse it (but perl's YAML::PP (1.2-compat) does)" ;
assert_raises_exn_pattern
"found character that cannot start any token"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn "- foo:\t bar\n\
- - baz\n\
\ -\tbaz"))
)
; "6.4" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("plain", `String ("text lines")); ("quoted", `String ("text lines"));
("block", `String ("text\n \tlines"))]
))
(of_string_exn {|
plain: text
lines
quoted: "text
lines"
block: |
text
lines|})
)
; "6.5" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("Folding", `String ("Empty line\nas a line feed"));
("Chomping", `String ("Clipped empty lines\n"))]
))
(of_string_exn {|
Folding:
"Empty line
as a line feed"
Chomping: |
Clipped empty lines
|})
)
; "6.6" >:: (fun ctxt ->
assert_equal ~printer
(`String ("trimmed\n\n\nas space"))
(of_string_exn {|>-
trimmed
as
space|})
)
; "6.7" >:: (fun ctxt ->
assert_equal ~printer
(`String ("foo \n\n\t bar\n\nbaz\n"))
(of_string_exn {|>
foo
bar
baz
|})
)
; "6.8" >:: (fun ctxt ->
assert_equal ~printer
(`String (" foo\nbar\nbaz "))
(of_string_exn {|"
foo
bar
baz
"|})
)
; "6.9" >:: (fun ctxt ->
assert_equal ~printer
(`O ([("key", `String ("value"))]))
(of_string_exn {|key: # Comment
value|})
)
; "6.10" >:: (fun ctxt ->
assert_equal ~printer
(`Null)
(of_string_exn {| # Comment
|})
)
; "6.11" >:: (fun ctxt ->
assert_equal ~printer
(`O ([("key", `String ("value"))]))
(of_string_exn {|key: # Comment
# lines
value
|})
)
; "6.12" >:: (fun ctxt ->
assert_raises_exn_pattern
"only string keys are supported"
(fun () -> of_string_exn {|{ first: Sammy, last: Sosa }:
# Statistics:
hr: # Home runs
65
avg: # Average
0.278|})
)
; "6.13" >:: (fun ctxt ->
warning "example 6.13 won't work b/c ocaml-yaml refuses to parse it (but perl's YAML::PP (1.2-compat) does)" ;
assert_raises_exn_pattern
"found unknown directive"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|%FOO bar baz # Should be ignored
# with a warning.
--- "foo"|}))
)
; "6.14" >:: (fun ctxt ->
warning "example 6.14 won't work b/c ocaml-yaml refuses to parse it (but perl's YAML::PP (1.2-compat) does)" ;
assert_raises_exn_pattern
"found incompatible YAML document"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|%YAML 1.3 # Attempt parsing
# with a warning
---
"foo"|}))
)
; "6.15" >:: (fun ctxt ->
assert_raises_exn_pattern
"found incompatible YAML document"
(fun () -> of_string_exn {|%YAML 1.2
%YAML 1.1
foo|})
)
; "6.16" >:: (fun ctxt ->
assert_equal ~printer
(`String ("foo"))
(of_string_exn {|%TAG !yaml! tag:yaml.org,2002:
---
!yaml!str "foo"|})
)
; "6.17" >:: (fun ctxt ->
assert_raises_exn_pattern
"found duplicate %TAG directive"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|%TAG ! !foo
%TAG ! !foo
bar|}))
)
; "6.18" >:: (fun ctxt ->
assert_equal ~printer
(`String ("bar"))
(of_string_exn {|# Private
!foo "bar"
...
# Global
%TAG ! tag:example.com,2000:app/
---
!foo "bar"|})
)
; "6.19" >:: (fun ctxt ->
assert_equal ~printer
(`String ("1 - 3"))
(of_string_exn {|
%TAG !! tag:example.com,2000:app/
---
!!int 1 - 3 # Interval, not integer|})
)
; "6.20" >:: (fun ctxt ->
assert_equal ~printer
(`String ("bar"))
(of_string_exn {|
%TAG !e! tag:example.com,2000:app/
---
!e!foo "bar"|})
)
; "6.21" >:: (fun ctxt ->
warning "example 6.21 has multiple docs: this isn't implemented right" ;
assert_equal ~printer
(`String ("fluorescent"))
(of_string_exn {|%TAG !m! !my-
--- # Bulb here
!m!light fluorescent
...
%TAG !m! !my-
--- # Color here
!m!light green|})
)
; "6.22" >:: (fun ctxt ->
assert_equal ~printer
(`A ([`String ("bar")]))
(of_string_exn {|%TAG !e! tag:example.com,2000:app/
---
- !e!foo "bar"|})
)
; "6.23" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|!!str &a1 "foo":
!!str bar
&a2 baz : *a1|})
)
; "6.24" >:: (fun ctxt ->
assert_equal ~printer
(`O ([("foo", `String ("baz"))]))
(of_string_exn {|!<tag:yaml.org,2002:str> foo :
!<!bar> baz|})
)
; "6.25" >:: (fun ctxt ->
warning "example 6.25 has invalid verbatim tags: this isn't implemented right" ;
assert_equal ~printer
(`A ([`String ("foo"); `String ("bar")]))
(of_string_exn {|- !<!> foo
- !<$:?> bar|})
)
; "6.26" >:: (fun ctxt ->
assert_equal ~printer
(`A ([`String ("foo"); `String ("bar"); `String ("baz")]))
(of_string_exn {|%TAG !e! tag:example.com,2000:app/
---
- !local foo
- !!str bar
- !e!tag%21 baz|})
)
; "6.27" >:: (fun ctxt ->
assert_raises_exn_pattern
"did not find expected tag URI"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|%TAG !e! tag:example,2000:app/
---
- !e! foo
- !h!bar baz|}))
)
; "6.28" >:: (fun ctxt ->
assert_equal ~printer
(`A ([`String ("12"); `Float (12.); `Float (12.)]))
(of_string_exn {|# Assuming conventional resolution:
- "12"
- 12
- ! 12|})
)
; "6.29" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|First occurrence: &anchor Value
Second occurrence: *anchor|})
)
]
let flow_styles = "flow styles" >::: [
"7.1" >:: (fun ctxt ->
assert_raises_exn_pattern
"Anchors are not supported when serialising to JSON"
(fun () -> of_string_exn {|First occurrence: &anchor Foo
Second occurrence: *anchor
Override anchor: &anchor Bar
Reuse anchor: *anchor|})
)
; "7.2" >:: (fun ctxt ->
warning "example 7.2 not accepted by ocaml-yaml (b/c 1.1)" ;
assert_raises_exn_pattern
"did not find expected"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|{
foo : !!str,
!!str : bar,
}|}))
)
; "7.3" >:: (fun ctxt ->
warning "example 7.2 not accepted by ocaml-yaml (b/c 1.1)" ;
assert_raises_exn_pattern
"found unexpected ':' character"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|{
? foo :,
: bar,
}|}))
)
; "7.4" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("implicit block key",
`A ([`O ([("implicit flow key", `String ("value"))])]))]
))
(of_string_exn {|"implicit block key" : [
"implicit flow key" : value,
]|})
)
; "7.5" >:: (fun ctxt ->
assert_equal ~printer
(`String ("folded to a space,\nto a line feed, or \t \tnon-content"))
(of_string_exn {|"folded
to a space,
to a line feed, or \
\ non-content"|})
)
; "7.6" >:: (fun ctxt ->
assert_equal ~printer
(`String (" 1st non-empty\n2nd non-empty 3rd non-empty "))
(of_string_exn {|" 1st non-empty
2nd non-empty
3rd non-empty "|})
)
; "7.7" >:: (fun ctxt ->
assert_equal ~printer
(`String ("here's to \"quotes\""))
(of_string_exn {| 'here''s to "quotes"'|})
)
; "7.8" >:: (fun ctxt ->
assert_equal ~printer
(`O (
[("implicit block key",
`A ([`O ([("implicit flow key", `String ("value"))])]))]
))
(of_string_exn {|'implicit block key' : [
'implicit flow key' : value,
]|})
)
; "7.9" >:: (fun ctxt ->
assert_equal ~printer
(`String (" 1st non-empty\n2nd non-empty 3rd non-empty "))
(of_string_exn {|
' 1st non-empty
2nd non-empty
3rd non-empty '|})
)
; "7.10" >:: (fun ctxt ->
assert_raises_exn_pattern
"did not find expected node content"
(fun () ->
assert_equal ~printer
(`Null)
(of_string_exn {|# Outside flow collection:
- ::vector
- ": - ()"
- Up, up, and away!
- -123
- http://example.com/foo#bar
# Inside flow collection:
- [ ::vector,
": - ()",
"Up, up and away!",
-123,
http://example.com/foo#bar ]
|}))
)
; "7.10-::vector" >:: (fun ctxt ->
assert_equal ~printer
(`A ([`String ("::vector"); `A ([`String ("::vector")])]))
(of_string_exn {|# Outside flow collection:
- ::vector