Debian Codegraph @

testdata/node.yaml

raw symbols SCIP
1 # Copyright 2025 The go-yaml Project Contributors
2 # SPDX-License-Identifier: Apache-2.0
3
4 # Node test cases for go-yaml
5 #
6 # Purpose: Tests YAML node structure, including Kind, Style, Tag, Value, and nested
7 # Content. Validates comment preservation (HeadComment, LineComment, FootComment)
8 # and node-level encoding/decoding.
9 #
10 # Format: Test cases use type-as-key format:
11 # - node-test:
12 # name: Test case name
13 # yaml: YAML input string
14 # node: Expected node structure (as NodeInfo)
15 # decode: false # Optional: skip decode test
16 # encode: false # Optional: skip encode test
17 #
18 # Test Types:
19 # node-test - Validates YAML node structure and round-trip encoding/decoding
20 #
21 # Common Keys:
22 # name - Test case name (string)
23 # yaml - Input YAML string to parse
24 # node - Expected node structure in NodeInfo format
25 # decode - Set to false to skip decode test (default: true)
26 # encode - Set to false to skip encode test (default: true)
27 #
28 # NodeInfo Format:
29 # kind - Node kind: Document, Sequence, Mapping, Scalar, Alias
30 # style - Node style: Double, Single, Literal, Folded, Flow (optional)
31 # anchor - Anchor name (optional)
32 # tag - YAML tag like !!null, !!str, !!int (optional)
33 # head - HeadComment text (optional)
34 # line - LineComment text (optional)
35 # foot - FootComment text (optional)
36 # text - Scalar value (for Scalar nodes only)
37 # content - Array of child nodes (for Document, Sequence, Mapping)
38
39 - node-test:
40 name: null value
41 yaml: 'null
42
43 '
44 node:
45 kind: Document
46 content:
47 - kind: Scalar
48 tag: '!!null'
49 text: 'null'
50 - node-test:
51 name: plain string
52 yaml: 'foo
53
54 '
55 node:
56 kind: Document
57 content:
58 - kind: Scalar
59 text: foo
60 - node-test:
61 name: double quoted string
62 yaml: '"foo"
63
64 '
65 node:
66 kind: Document
67 content:
68 - kind: Scalar
69 style: Double
70 text: foo
71 - node-test:
72 name: single quoted string
73 yaml: '''foo''
74
75 '
76 node:
77 kind: Document
78 content:
79 - kind: Scalar
80 style: Single
81 text: foo
82 - node-test:
83 name: boolean true
84 yaml: 'true
85
86 '
87 node:
88 kind: Document
89 content:
90 - kind: Scalar
91 tag: '!!bool'
92 text: 'true'
93 - node-test:
94 name: negative integer
95 yaml: '-10
96
97 '
98 node:
99 kind: Document
100 content:
101 - kind: Scalar
102 tag: '!!int'
103 text: '-10'
104 - node-test:
105 name: large integer
106 yaml: '4294967296
107
108 '
109 node:
110 kind: Document
111 content:
112 - kind: Scalar
113 tag: '!!int'
114 text: '4294967296'
115 - node-test:
116 name: float
117 yaml: '0.1000
118
119 '
120 node:
121 kind: Document
122 content:
123 - kind: Scalar
124 tag: '!!float'
125 text: '0.1000'
126 - node-test:
127 name: empty single quoted string
128 yaml: '''''
129
130 '
131 node:
132 kind: Document
133 content:
134 - kind: Scalar
135 style: Single
136 text: ''
137 - node-test:
138 name: double quoted with escapes
139 yaml: '"\t\n"
140
141 '
142 node:
143 kind: Document
144 content:
145 - kind: Scalar
146 style: Double
147 text: "\t\n"
148 - node-test:
149 name: literal style multiline
150 yaml: "|\n foo\n bar\n"
151 node:
152 kind: Document
153 content:
154 - kind: Scalar
155 style: Literal
156 text: 'foo
157
158 bar
159
160 '
161 - node-test:
162 name: explicit str tag
163 yaml: '!!str 123
164
165 '
166 decode: true
167 encode: false
168 node:
169 kind: Document
170 content:
171 - kind: Scalar
172 tag: '!!str'
173 text: '123'
174 - node-test:
175 name: negative zero
176 yaml: '-0
177
178 '
179 node:
180 kind: Document
181 content:
182 - kind: Scalar
183 tag: '!!float'
184 text: '-0'
185 - node-test:
186 name: mapping with sequence of mappings
187 yaml: "a:\n - b: c\n d: e\n"
188 node:
189 kind: Document
190 content:
191 - kind: Mapping
192 content:
193 - kind: Scalar
194 text: a
195 - kind: Sequence
196 content:
197 - kind: Mapping
198 content:
199 - kind: Scalar
200 text: b
201 - kind: Scalar
202 text: c
203 - kind: Scalar
204 text: d
205 - kind: Scalar
206 text: e
207 - node-test:
208 name: flow mapping nested in mapping
209 yaml: 'foo: {b?r: a?bc}
210
211 '
212 decode: true
213 encode: false
214 node:
215 kind: Document
216 content:
217 - kind: Mapping
218 content:
219 - kind: Scalar
220 text: foo
221 - kind: Mapping
222 style: Flow
223 content:
224 - kind: Scalar
225 text: b?r
226 - kind: Scalar
227 text: a?bc
228 - node-test:
229 name: line comment on key
230 yaml: "a: # AI\n - b\nc:\n - d\n"
231 node:
232 kind: Document
233 content:
234 - kind: Mapping
235 content:
236 - kind: Scalar
237 text: a
238 line: '# AI'
239 - kind: Sequence
240 content:
241 - kind: Scalar
242 text: b
243 - kind: Scalar
244 text: c
245 - kind: Sequence
246 content:
247 - kind: Scalar
248 text: d
249 - node-test:
250 name: simple anchor and alias
251 decode: true
252 encode: false
253 yaml: 'a: &x 1
254
255 b: *x
256
257 '
258 node:
259 kind: Document
260 content:
261 - kind: Mapping
262 content:
263 - kind: Scalar
264 text: a
265 - kind: Scalar
266 anchor: x
267 tag: '!!int'
268 text: '1'
269 - kind: Scalar
270 text: b
271 - kind: Alias
272 - node-test:
273 name: anchor on sequence
274 decode: true
275 encode: false
276 yaml: 'a: &anchor [1, 2]
277
278 b: *anchor
279
280 '
281 node:
282 kind: Document
283 content:
284 - kind: Mapping
285 content:
286 - kind: Scalar
287 text: a
288 - kind: Sequence
289 style: Flow
290 anchor: anchor
291 content:
292 - kind: Scalar
293 tag: '!!int'
294 text: '1'
295 - kind: Scalar
296 tag: '!!int'
297 text: '2'
298 - kind: Scalar
299 text: b
300 - kind: Alias
301 - node-test:
302 name: flow sequence with mixed types
303 yaml: '[1, true, foo]
304
305 '
306 node:
307 kind: Document
308 content:
309 - kind: Sequence
310 style: Flow
311 content:
312 - kind: Scalar
313 tag: '!!int'
314 text: '1'
315 - kind: Scalar
316 tag: '!!bool'
317 text: 'true'
318 - kind: Scalar
319 text: foo
320 - node-test:
321 name: folded multiline string
322 decode: true
323 encode: false
324 yaml: ">\n foo\n bar\n"
325 node:
326 kind: Document
327 content:
328 - kind: Scalar
329 style: Folded
330 text: 'foo bar
331
332 '
333 - node-test:
334 name: block sequence with scalars
335 yaml: '- one
336
337 - two
338
339 - three
340
341 '
342 node:
343 kind: Document
344 content:
345 - kind: Sequence
346 content:
347 - kind: Scalar
348 text: one
349 - kind: Scalar
350 text: two
351 - kind: Scalar
352 text: three
353 - node-test:
354 name: empty mapping value
355 yaml: 'a:
356
357 '
358 node:
359 kind: Document
360 content:
361 - kind: Mapping
362 content:
363 - kind: Scalar
364 text: a
365 - kind: Scalar
366 tag: '!!null'
367 text: ''
368 - node-test:
369 name: mapping with empty string value
370 yaml: 'a: ''''
371
372 '
373 node:
374 kind: Document
375 content:
376 - kind: Mapping
377 content:
378 - kind: Scalar
379 text: a
380 - kind: Scalar
381 style: Single
382 - node-test:
383 name: flow mapping with multiple entries
384 yaml: '{a: 1, b: 2}
385
386 '
387 node:
388 kind: Document
389 content:
390 - kind: Mapping
391 style: Flow
392 content:
393 - kind: Scalar
394 text: a
395 - kind: Scalar
396 tag: '!!int'
397 text: '1'
398 - kind: Scalar
399 text: b
400 - kind: Scalar
401 tag: '!!int'
402 text: '2'
403 - node-test:
404 name: head comment on mapping key
405 yaml: "a:\n # HM\n b: c\n"
406 decode: true
407 encode: false
408 node:
409 kind: Document
410 content:
411 - kind: Mapping
412 content:
413 - kind: Scalar
414 text: a
415 - kind: Mapping
416 content:
417 - kind: Scalar
418 head: '# HM'
419 text: b
420 - kind: Scalar
421 text: c
422 - node-test:
423 name: literal style preserves trailing newline
424 yaml: "|\n foo\n"
425 node:
426 kind: Document
427 content:
428 - kind: Scalar
429 style: Literal
430 text: 'foo
431
432 '
433 - node-test:
434 name: literal style strips final newlines
435 yaml: "|-\n foo\n"
436 node:
437 kind: Document
438 content:
439 - kind: Scalar
440 style: Literal
441 text: foo
442 - node-test:
443 name: double quoted with newline escape
444 yaml: '"foo\nbar"
445
446 '
447 node:
448 kind: Document
449 content:
450 - kind: Scalar
451 style: Double
452 text: 'foo
453
454 bar'
455 - node-test:
456 name: single quoted with doubled single quote
457 yaml: '''foo''''bar''
458
459 '
460 node:
461 kind: Document
462 content:
463 - kind: Scalar
464 style: Single
465 text: foo'bar
466 - node-test:
467 name: sequence of sequences
468 yaml: '- [a, b]
469
470 - [c, d]
471
472 '
473 node:
474 kind: Document
475 content:
476 - kind: Sequence
477 content:
478 - kind: Sequence
479 style: Flow
480 content:
481 - kind: Scalar
482 text: a
483 - kind: Scalar
484 text: b
485 - kind: Sequence
486 style: Flow
487 content:
488 - kind: Scalar
489 text: c
490 - kind: Scalar
491 text: d
492 - node-test:
493 name: mapping of mappings
494 yaml: 'a: {b: 1}
495
496 c: {d: 2}
497
498 '
499 node:
500 kind: Document
501 content:
502 - kind: Mapping
503 content:
504 - kind: Scalar
505 text: a
506 - kind: Mapping
507 style: Flow
508 content:
509 - kind: Scalar
510 text: b
511 - kind: Scalar
512 tag: '!!int'
513 text: '1'
514 - kind: Scalar
515 text: c
516 - kind: Mapping
517 style: Flow
518 content:
519 - kind: Scalar
520 text: d
521 - kind: Scalar
522 tag: '!!int'
523 text: '2'
524 - node-test:
525 name: all comment types on scalar
526 yaml: '# One
527
528 # Two
529
530 true # Three
531
532 # Four
533
534 # Five
535
536 '
537 node:
538 kind: Document
539 content:
540 - kind: Scalar
541 tag: '!!bool'
542 text: 'true'
543 head: '# One
544
545 # Two'
546 line: '# Three'
547 foot: '# Four
548
549 # Five'
550 - node-test:
551 name: unicode in comments
552 yaml: '# Å¡
553
554 true # Å¡
555
556 '
557 node:
558 kind: Document
559 content:
560 - kind: Scalar
561 tag: '!!bool'
562 text: 'true'
563 head: '# Å¡'
564 line: '# Å¡'
565 - node-test:
566 name: custom tag on scalar
567 yaml: '!tag:something 123
568
569 '
570 node:
571 kind: Document
572 content:
573 - kind: Scalar
574 tag: '!tag:something'
575 text: '123'
576 - node-test:
577 name: custom tag on empty mapping
578 yaml: '!tag:something {}
579
580 '
581 node:
582 kind: Document
583 content:
584 - kind: Mapping
585 style: Flow
586 tag: '!tag:something'
587 - node-test:
588 name: custom tag on empty sequence
589 yaml: '!tag:something []
590
591 '
592 node:
593 kind: Document
594 content:
595 - kind: Sequence
596 style: Flow
597 tag: '!tag:something'
598 - node-test:
599 name: merge key as quoted string with sequence
600 yaml: '"<<": []
601
602 '
603 node:
604 kind: Document
605 content:
606 - kind: Mapping
607 content:
608 - kind: Scalar
609 style: Double
610 text: '<<'
611 - kind: Sequence
612 style: Flow
613 - node-test:
614 name: merge key as value
615 yaml: 'foo: "<<"
616
617 '
618 node:
619 kind: Document
620 content:
621 - kind: Mapping
622 content:
623 - kind: Scalar
624 text: foo
625 - kind: Scalar
626 style: Double
627 text: '<<'
628 - node-test:
629 name: simple two element sequence
630 yaml: '- a
631
632 - b
633
634 '
635 node:
636 kind: Document
637 content:
638 - kind: Sequence
639 content:
640 - kind: Scalar
641 text: a
642 - kind: Scalar
643 text: b
644 - node-test:
645 name: nested block sequences
646 yaml: "- a\n- - b\n - c\n"
647 node:
648 kind: Document
649 content:
650 - kind: Sequence
651 content:
652 - kind: Scalar
653 text: a
654 - kind: Sequence
655 content:
656 - kind: Scalar
657 text: b
658 - kind: Scalar
659 text: c
660 - node-test:
661 name: flow sequence with strings
662 yaml: '[a, b]
663
664 '
665 node:
666 kind: Document
667 content:
668 - kind: Sequence
669 style: Flow
670 content:
671 - kind: Scalar
672 text: a
673 - kind: Scalar
674 text: b
675 - node-test:
676 name: block sequence with nested flow sequence
677 yaml: '- a
678
679 - [b, c]
680
681 '
682 node:
683 kind: Document
684 content:
685 - kind: Sequence
686 content:
687 - kind: Scalar
688 text: a
689 - kind: Sequence
690 style: Flow
691 content:
692 - kind: Scalar
693 text: b
694 - kind: Scalar
695 text: c
696 - node-test:
697 name: positive infinity
698 yaml: '.inf
699
700 '
701 node:
702 kind: Document
703 content:
704 - kind: Scalar
705 tag: '!!float'
706 text: '.inf'
707 - node-test:
708 name: explicit null
709 yaml: '~
710
711 '
712 node:
713 kind: Document
714 content:
715 - kind: Scalar
716 tag: '!!null'
717 text: '~'
718 - node-test:
719 name: flow sequence with all comment types
720 yaml: '# H1
721
722 [la, lb] # I
723
724 # F1
725
726 '
727 node:
728 kind: Document
729 content:
730 - kind: Sequence
731 style: Flow
732 head: '# H1'
733 line: '# I'
734 foot: '# F1'
735 content:
736 - kind: Scalar
737 text: la
738 - kind: Scalar
739 text: lb
740 - node-test:
741 name: boolean false
742 yaml: 'false
743
744 '
745 node:
746 kind: Document
747 content:
748 - kind: Scalar
749 tag: '!!bool'
750 text: 'false'
751 - node-test:
752 name: uppercase NULL
753 yaml: 'NULL
754
755 '
756 node:
757 kind: Document
758 content:
759 - kind: Scalar
760 tag: '!!null'
761 text: 'NULL'
762 - node-test:
763 name: empty flow mapping
764 yaml: '{}
765
766 '
767 node:
768 kind: Document
769 content:
770 - kind: Mapping
771 style: Flow
772 - node-test:
773 name: empty flow sequence
774 yaml: '[]
775
776 '
777 node:
778 kind: Document
779 content:
780 - kind: Sequence
781 style: Flow
782 - node-test:
783 name: positive integer
784 yaml: '42
785
786 '
787 node:
788 kind: Document
789 content:
790 - kind: Scalar
791 tag: '!!int'
792 text: '42'
793 - node-test:
794 name: zero
795 yaml: '0
796
797 '
798 node:
799 kind: Document
800 content:
801 - kind: Scalar
802 tag: '!!int'
803 text: '0'
804 - node-test:
805 name: folded style keep chomping
806 yaml: ">+\n foo\n"
807 decode: true
808 encode: false
809 node:
810 kind: Document
811 content:
812 - kind: Scalar
813 style: Folded
814 text: 'foo
815
816 '
817 - node-test:
818 name: simple key-value mapping
819 yaml: 'a: b
820
821 '
822 node:
823 kind: Document
824 content:
825 - kind: Mapping
826 content:
827 - kind: Scalar
828 text: a
829 - kind: Scalar
830 text: b
831 - node-test:
832 name: mapping with integer value
833 yaml: 'a: 1
834
835 '
836 node:
837 kind: Document
838 content:
839 - kind: Mapping
840 content:
841 - kind: Scalar
842 text: a
843 - kind: Scalar
844 tag: '!!int'
845 text: '1'
846 - node-test:
847 name: mapping with null value implicit
848 yaml: 'a:
849
850 '
851 node:
852 kind: Document
853 content:
854 - kind: Mapping
855 content:
856 - kind: Scalar
857 text: a
858 - kind: Scalar
859 tag: '!!null'
860 text: ''
861 - node-test:
862 name: double quoted with tab escape
863 yaml: '"\t"
864
865 '
866 node:
867 kind: Document
868 content:
869 - kind: Scalar
870 style: Double
871 text: "\t"
872 - node-test:
873 name: two-level nested mapping
874 yaml: "a:\n b: c\n"
875 node:
876 kind: Document
877 content:
878 - kind: Mapping
879 content:
880 - kind: Scalar
881 text: a
882 - kind: Mapping
883 content:
884 - kind: Scalar
885 text: b
886 - kind: Scalar
887 text: c
888 - node-test:
889 name: mapping with multiple keys
890 yaml: 'a: 1
891
892 b: 2
893
894 c: 3
895
896 '
897 node:
898 kind: Document
899 content:
900 - kind: Mapping
901 content:
902 - kind: Scalar
903 text: a
904 - kind: Scalar
905 tag: '!!int'
906 text: '1'
907 - kind: Scalar
908 text: b
909 - kind: Scalar
910 tag: '!!int'
911 text: '2'
912 - kind: Scalar
913 text: c
914 - kind: Scalar
915 tag: '!!int'
916 text: '3'
917 - node-test:
918 name: float with exponent
919 yaml: '1.23e+2
920
921 '
922 node:
923 kind: Document
924 content:
925 - kind: Scalar
926 tag: '!!float'
927 text: '1.23e+2'
928 - node-test:
929 name: negative float
930 yaml: '-3.14
931
932 '
933 node:
934 kind: Document
935 content:
936 - kind: Scalar
937 tag: '!!float'
938 text: '-3.14'
939 - node-test:
940 name: uppercase TRUE
941 yaml: 'TRUE
942
943 '
944 node:
945 kind: Document
946 content:
947 - kind: Scalar
948 tag: '!!bool'
949 text: 'TRUE'
950 - node-test:
951 name: uppercase FALSE
952 yaml: 'FALSE
953
954 '
955 node:
956 kind: Document
957 content:
958 - kind: Scalar
959 tag: '!!bool'
960 text: 'FALSE'
961 - node-test:
962 name: three-element sequence
963 yaml: '- a
964
965 - b
966
967 - c
968
969 '
970 node:
971 kind: Document
972 content:
973 - kind: Sequence
974 content:
975 - kind: Scalar
976 text: a
977 - kind: Scalar
978 text: b
979 - kind: Scalar
980 text: c
981 - node-test:
982 name: sequence with integers
983 yaml: '- 1
984
985 - 2
986
987 - 3
988
989 '
990 node:
991 kind: Document
992 content:
993 - kind: Sequence
994 content:
995 - kind: Scalar
996 tag: '!!int'
997 text: '1'
998 - kind: Scalar
999 tag: '!!int'
1000 text: '2'
1001 - kind: Scalar
1002 tag: '!!int'
1003 text: '3'
1004 - node-test:
1005 name: flow sequence with integers
1006 yaml: '[1, 2, 3]
1007
1008 '
1009 node:
1010 kind: Document
1011 content:
1012 - kind: Sequence
1013 style: Flow
1014 content:
1015 - kind: Scalar
1016 tag: '!!int'
1017 text: '1'
1018 - kind: Scalar
1019 tag: '!!int'
1020 text: '2'
1021 - kind: Scalar
1022 tag: '!!int'
1023 text: '3'
1024 - node-test:
1025 name: quoted key with spaces
1026 yaml: '"key with spaces": value
1027
1028 '
1029 node:
1030 kind: Document
1031 content:
1032 - kind: Mapping
1033 content:
1034 - kind: Scalar
1035 style: Double
1036 text: key with spaces
1037 - kind: Scalar
1038 text: value
1039 - node-test:
1040 name: flow mapping with flow sequence value
1041 yaml: '{a: [1, 2]}
1042
1043 '
1044 node:
1045 kind: Document
1046 content:
1047 - kind: Mapping
1048 style: Flow
1049 content:
1050 - kind: Scalar
1051 text: a
1052 - kind: Sequence
1053 style: Flow
1054 content:
1055 - kind: Scalar
1056 tag: '!!int'
1057 text: '1'
1058 - kind: Scalar
1059 tag: '!!int'
1060 text: '2'
1061 - node-test:
1062 name: flow sequence with flow mapping
1063 yaml: '[{a: 1}]
1064
1065 '
1066 node:
1067 kind: Document
1068 content:
1069 - kind: Sequence
1070 style: Flow
1071 content:
1072 - kind: Mapping
1073 style: Flow
1074 content:
1075 - kind: Scalar
1076 text: a
1077 - kind: Scalar
1078 tag: '!!int'
1079 text: '1'
1080 - node-test:
1081 name: block mapping with flow value
1082 yaml: 'a: [1, 2]
1083
1084 '
1085 node:
1086 kind: Document
1087 content:
1088 - kind: Mapping
1089 content:
1090 - kind: Scalar
1091 text: a
1092 - kind: Sequence
1093 style: Flow
1094 content:
1095 - kind: Scalar
1096 tag: '!!int'
1097 text: '1'
1098 - kind: Scalar
1099 tag: '!!int'
1100 text: '2'
1101 - node-test:
1102 name: block mapping with flow mapping value
1103 yaml: 'a: {b: c}
1104
1105 '
1106 node:
1107 kind: Document
1108 content:
1109 - kind: Mapping
1110 content:
1111 - kind: Scalar
1112 text: a
1113 - kind: Mapping
1114 style: Flow
1115 content:
1116 - kind: Scalar
1117 text: b
1118 - kind: Scalar
1119 text: c
1120 - node-test:
1121 name: three-level nested mapping
1122 yaml: "a:\n b:\n c: d\n"
1123 node:
1124 kind: Document
1125 content:
1126 - kind: Mapping
1127 content:
1128 - kind: Scalar
1129 text: a
1130 - kind: Mapping
1131 content:
1132 - kind: Scalar
1133 text: b
1134 - kind: Mapping
1135 content:
1136 - kind: Scalar
1137 text: c
1138 - kind: Scalar
1139 text: d
1140 - node-test:
1141 name: empty double quoted string
1142 yaml: '""
1143
1144 '
1145 node:
1146 kind: Document
1147 content:
1148 - kind: Scalar
1149 style: Double
1150 text: ''
1151 - node-test:
1152 name: mapping with empty key
1153 yaml: '"": value
1154
1155 '
1156 node:
1157 kind: Document
1158 content:
1159 - kind: Mapping
1160 content:
1161 - kind: Scalar
1162 style: Double
1163 text: ''
1164 - kind: Scalar
1165 text: value
1166
1167 # Values with spaces
1168 - node-test:
1169 name: mapping with multi-word value
1170 yaml: "a: b c\n"
1171 node:
1172 kind: Document
1173 content:
1174 - kind: Mapping
1175 content: [{kind: Scalar, text: a}, {kind: Scalar, text: 'b c'}]
1176
1177 # More nested structures
1178 - node-test:
1179 name: sequence in sequence in mapping
1180 decode: true
1181 encode: false
1182 yaml: "a:\n- - b\n"
1183 node:
1184 kind: Document
1185 content:
1186 - kind: Mapping
1187 content:
1188 - {kind: Scalar, text: a}
1189 - kind: Sequence
1190 content:
1191 - kind: Sequence
1192 content: [{kind: Scalar, text: b}]
1193
1194 # Strings that look like other types
1195 - node-test:
1196 name: string that looks like number
1197 yaml: "\"123\"\n"
1198 node:
1199 kind: Document
1200 content:
1201 - {kind: Scalar, style: Double, text: '123'}
1202
1203 - node-test:
1204 name: string that looks like boolean
1205 yaml: "\"true\"\n"
1206 node:
1207 kind: Document
1208 content:
1209 - {kind: Scalar, style: Double, text: 'true'}
1210
1211 # Hex and octal numbers
1212 - node-test:
1213 name: hex integer
1214 yaml: "0x1a\n"
1215 node:
1216 kind: Document
1217 content:
1218 - {kind: Scalar, tag: '!!int', text: '0x1a'}
1219
1220 - node-test:
1221 name: octal integer
1222 yaml: "0o10\n"
1223 node:
1224 kind: Document
1225 content:
1226 - {kind: Scalar, tag: '!!int', text: '0o10'}
1227
1228 # More flow collections
1229 - node-test:
1230 name: nested flow mappings
1231 yaml: "{a: {b: c}}\n"
1232 node:
1233 kind: Document
1234 content:
1235 - kind: Mapping
1236 style: Flow
1237 content:
1238 - {kind: Scalar, text: a}
1239 - kind: Mapping
1240 style: Flow
1241 content: [{kind: Scalar, text: b}, {kind: Scalar, text: c}]
1242
1243 - node-test:
1244 name: nested flow sequences
1245 yaml: "[[a, b]]\n"
1246 node:
1247 kind: Document
1248 content:
1249 - kind: Sequence
1250 style: Flow
1251 content:
1252 - kind: Sequence
1253 style: Flow
1254 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}]
1255
1256 # Comments on flow collections
1257 - node-test:
1258 name: flow mapping with comment
1259 yaml: "{a: b} # comment\n"
1260 node:
1261 kind: Document
1262 content:
1263 - kind: Mapping
1264 style: Flow
1265 line: '# comment'
1266 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}]
1267
1268 # Multiple mappings in document
1269 - node-test:
1270 name: two top-level mappings
1271 yaml: "a: 1\nb: 2\n"
1272 node:
1273 kind: Document
1274 content:
1275 - kind: Mapping
1276 content:
1277 - {kind: Scalar, text: a}
1278 - {kind: Scalar, tag: '!!int', text: '1'}
1279 - {kind: Scalar, text: b}
1280 - {kind: Scalar, tag: '!!int', text: '2'}
1281
1282 # Colon in values
1283 - node-test:
1284 name: colon in quoted value
1285 yaml: "url: \"http://example.com\"\n"
1286 node:
1287 kind: Document
1288 content:
1289 - kind: Mapping
1290 content:
1291 - {kind: Scalar, text: url}
1292 - {kind: Scalar, style: Double, text: 'http://example.com'}
1293
1294 # Leading/trailing spaces
1295 - node-test:
1296 name: value with leading space
1297 yaml: "a: \" b\"\n"
1298 node:
1299 kind: Document
1300 content:
1301 - kind: Mapping
1302 content:
1303 - {kind: Scalar, text: a}
1304 - {kind: Scalar, style: Double, text: ' b'}
1305
1306 - node-test:
1307 name: value with trailing space
1308 yaml: "a: \"b \"\n"
1309 node:
1310 kind: Document
1311 content:
1312 - kind: Mapping
1313 content:
1314 - {kind: Scalar, text: a}
1315 - {kind: Scalar, style: Double, text: 'b '}
1316
1317 # Sequences of mappings
1318 - node-test:
1319 name: sequence of simple mappings
1320 yaml: "- a: 1\n- b: 2\n"
1321 node:
1322 kind: Document
1323 content:
1324 - kind: Sequence
1325 content:
1326 - kind: Mapping
1327 content: [{kind: Scalar, text: a}, {kind: Scalar, tag: '!!int', text: '1'}]
1328 - kind: Mapping
1329 content: [{kind: Scalar, text: b}, {kind: Scalar, tag: '!!int', text: '2'}]
1330
1331 # Mappings with flow sequence values
1332 - node-test:
1333 name: two mappings with flow sequence values
1334 yaml: "a: [1]\nb: [2]\n"
1335 node:
1336 kind: Document
1337 content:
1338 - kind: Mapping
1339 content:
1340 - {kind: Scalar, text: a}
1341 - kind: Sequence
1342 style: Flow
1343 content: [{kind: Scalar, tag: '!!int', text: '1'}]
1344 - {kind: Scalar, text: b}
1345 - kind: Sequence
1346 style: Flow
1347 content: [{kind: Scalar, tag: '!!int', text: '2'}]
1348
1349 # Empty sequence in mapping
1350 - node-test:
1351 name: mapping with empty flow sequence
1352 yaml: "a: []\n"
1353 node:
1354 kind: Document
1355 content:
1356 - kind: Mapping
1357 content:
1358 - {kind: Scalar, text: a}
1359 - kind: Sequence
1360 style: Flow
1361
1362 # Empty mapping in sequence
1363 - node-test:
1364 name: sequence with empty flow mapping
1365 yaml: "[{}]\n"
1366 node:
1367 kind: Document
1368 content:
1369 - kind: Sequence
1370 style: Flow
1371 content:
1372 - kind: Mapping
1373 style: Flow
1374
1375 # Single element sequences
1376 - node-test:
1377 name: single element block sequence
1378 yaml: "- a\n"
1379 node:
1380 kind: Document
1381 content:
1382 - kind: Sequence
1383 content: [{kind: Scalar, text: a}]
1384
1385 - node-test:
1386 name: single element flow sequence
1387 yaml: "[a]\n"
1388 node:
1389 kind: Document
1390 content:
1391 - kind: Sequence
1392 style: Flow
1393 content: [{kind: Scalar, text: a}]
1394
1395 # Single element mappings
1396 - node-test:
1397 name: single element flow mapping
1398 yaml: "{a: 1}\n"
1399 node:
1400 kind: Document
1401 content:
1402 - kind: Mapping
1403 style: Flow
1404 content: [{kind: Scalar, text: a}, {kind: Scalar, tag: '!!int', text: '1'}]
1405
1406 # Different null representations
1407 - node-test:
1408 name: tilde null
1409 yaml: "~\n"
1410 node:
1411 kind: Document
1412 content:
1413 - {kind: Scalar, tag: '!!null', text: '~'}
1414
1415 - node-test:
1416 name: lowercase null
1417 yaml: "null\n"
1418 node:
1419 kind: Document
1420 content:
1421 - {kind: Scalar, tag: '!!null', text: 'null'}
1422
1423 - node-test:
1424 name: uppercase Null
1425 yaml: "Null\n"
1426 node:
1427 kind: Document
1428 content:
1429 - {kind: Scalar, tag: '!!null', text: 'Null'}
1430
1431 # Mixed types in sequences
1432 - node-test:
1433 name: sequence with mixed types
1434 yaml: "- 1\n- foo\n- true\n"
1435 node:
1436 kind: Document
1437 content:
1438 - kind: Sequence
1439 content:
1440 - {kind: Scalar, tag: '!!int', text: '1'}
1441 - {kind: Scalar, text: foo}
1442 - {kind: Scalar, tag: '!!bool', text: 'true'}
1443
1444 # Mixed types in mappings
1445 - node-test:
1446 name: mapping with different value types
1447 yaml: "int: 1\nstr: foo\nbool: true\n"
1448 node:
1449 kind: Document
1450 content:
1451 - kind: Mapping
1452 content:
1453 - {kind: Scalar, text: int}
1454 - {kind: Scalar, tag: '!!int', text: '1'}
1455 - {kind: Scalar, text: str}
1456 - {kind: Scalar, text: foo}
1457 - {kind: Scalar, text: bool}
1458 - {kind: Scalar, tag: '!!bool', text: 'true'}
1459
1460 # Deeply nested flow
1461 - node-test:
1462 name: deeply nested flow mapping
1463 yaml: "{a: {b: {c: 1}}}\n"
1464 node:
1465 kind: Document
1466 content:
1467 - kind: Mapping
1468 style: Flow
1469 content:
1470 - {kind: Scalar, text: a}
1471 - kind: Mapping
1472 style: Flow
1473 content:
1474 - {kind: Scalar, text: b}
1475 - kind: Mapping
1476 style: Flow
1477 content: [{kind: Scalar, text: c}, {kind: Scalar, tag: '!!int', text: '1'}]
1478
1479 # Four-level nested mapping
1480 - node-test:
1481 name: four-level nested mapping
1482 yaml: "a:\n b:\n c:\n d: e\n"
1483 node:
1484 kind: Document
1485 content:
1486 - kind: Mapping
1487 content:
1488 - {kind: Scalar, text: a}
1489 - kind: Mapping
1490 content:
1491 - {kind: Scalar, text: b}
1492 - kind: Mapping
1493 content:
1494 - {kind: Scalar, text: c}
1495 - kind: Mapping
1496 content: [{kind: Scalar, text: d}, {kind: Scalar, text: e}]
1497
1498 # Literal style variations
1499 - node-test:
1500 name: literal with single line
1501 yaml: "|\n single\n"
1502 node:
1503 kind: Document
1504 content:
1505 - {kind: Scalar, style: Literal, text: "single\n"}
1506
1507 - node-test:
1508 name: literal with empty lines
1509 decode: true
1510 encode: false
1511 yaml: "|\n line1\n \n line2\n"
1512 node:
1513 kind: Document
1514 content:
1515 - {kind: Scalar, style: Literal, text: "line1\n\nline2\n"}
1516
1517 # Numbers edge cases
1518 - node-test:
1519 name: leading zeros preserved in string
1520 yaml: "\"007\"\n"
1521 node:
1522 kind: Document
1523 content:
1524 - {kind: Scalar, style: Double, text: '007'}
1525
1526 - node-test:
1527 name: plus sign integer
1528 yaml: "+42\n"
1529 node:
1530 kind: Document
1531 content:
1532 - {kind: Scalar, tag: '!!int', text: '+42'}
1533
1534 # Scientific notation
1535 - node-test:
1536 name: scientific notation lowercase e
1537 yaml: "1.23e2\n"
1538 node:
1539 kind: Document
1540 content:
1541 - {kind: Scalar, tag: '!!float', text: '1.23e2'}
1542
1543 - node-test:
1544 name: scientific notation uppercase E
1545 yaml: "1.23E2\n"
1546 node:
1547 kind: Document
1548 content:
1549 - {kind: Scalar, tag: '!!float', text: '1.23E2'}
1550
1551 - node-test:
1552 name: scientific notation negative exponent
1553 yaml: "1.23e-2\n"
1554 node:
1555 kind: Document
1556 content:
1557 - {kind: Scalar, tag: '!!float', text: '1.23e-2'}
1558
1559 # Very large/small numbers
1560 - node-test:
1561 name: very large integer
1562 yaml: "9223372036854775807\n"
1563 node:
1564 kind: Document
1565 content:
1566 - {kind: Scalar, tag: '!!int', text: '9223372036854775807'}
1567
1568 # Boolean variations already covered TRUE/FALSE, add lowercase
1569 - node-test:
1570 name: lowercase true
1571 yaml: "true\n"
1572 node:
1573 kind: Document
1574 content:
1575 - {kind: Scalar, tag: '!!bool', text: 'true'}
1576
1577 - node-test:
1578 name: lowercase false
1579 yaml: "false\n"
1580 node:
1581 kind: Document
1582 content:
1583 - {kind: Scalar, tag: '!!bool', text: 'false'}
1584
1585 # Quoted numbers
1586 - node-test:
1587 name: single quoted number
1588 yaml: "'123'\n"
1589 node:
1590 kind: Document
1591 content:
1592 - {kind: Scalar, style: Single, text: '123'}
1593
1594 # Flow collections with trailing comma (if valid)
1595 - node-test:
1596 name: flow sequence multiple elements
1597 yaml: "[a, b, c]\n"
1598 node:
1599 kind: Document
1600 content:
1601 - kind: Sequence
1602 style: Flow
1603 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}, {kind: Scalar, text: c}]
1604
1605 - node-test:
1606 name: flow mapping multiple elements
1607 yaml: "{a: 1, b: 2, c: 3}\n"
1608 node:
1609 kind: Document
1610 content:
1611 - kind: Mapping
1612 style: Flow
1613 content:
1614 - {kind: Scalar, text: a}
1615 - {kind: Scalar, tag: '!!int', text: '1'}
1616 - {kind: Scalar, text: b}
1617 - {kind: Scalar, tag: '!!int', text: '2'}
1618 - {kind: Scalar, text: c}
1619 - {kind: Scalar, tag: '!!int', text: '3'}
1620
1621 # Indented block scalars
1622 - node-test:
1623 name: literal with extra indentation
1624 decode: true
1625 encode: false
1626 yaml: "|\n indented\n"
1627 node:
1628 kind: Document
1629 content:
1630 - {kind: Scalar, style: Literal, text: "indented\n"}
1631
1632 # Mapping key variations
1633 - node-test:
1634 name: integer as key
1635 yaml: "1: one\n"
1636 node:
1637 kind: Document
1638 content:
1639 - kind: Mapping
1640 content: [{kind: Scalar, tag: '!!int', text: '1'}, {kind: Scalar, text: one}]
1641
1642 - node-test:
1643 name: boolean as key
1644 yaml: "true: yes\n"
1645 node:
1646 kind: Document
1647 content:
1648 - kind: Mapping
1649 content: [{kind: Scalar, tag: '!!bool', text: 'true'}, {kind: Scalar, text: yes}]
1650
1651 # Sequences with mixed nesting
1652 - node-test:
1653 name: sequence with mapping and scalars
1654 yaml: "- a\n- b: c\n- d\n"
1655 node:
1656 kind: Document
1657 content:
1658 - kind: Sequence
1659 content:
1660 - {kind: Scalar, text: a}
1661 - kind: Mapping
1662 content: [{kind: Scalar, text: b}, {kind: Scalar, text: c}]
1663 - {kind: Scalar, text: d}
1664
1665 # Mappings with mixed value types
1666 - node-test:
1667 name: mapping with scalar and sequence values
1668 yaml: "a: b\nc:\n - d\n"
1669 node:
1670 kind: Document
1671 content:
1672 - kind: Mapping
1673 content:
1674 - {kind: Scalar, text: a}
1675 - {kind: Scalar, text: b}
1676 - {kind: Scalar, text: c}
1677 - kind: Sequence
1678 content: [{kind: Scalar, text: d}]
1679
1680 - node-test:
1681 name: mapping with scalar and mapping values
1682 yaml: "a: b\nc:\n d: e\n"
1683 node:
1684 kind: Document
1685 content:
1686 - kind: Mapping
1687 content:
1688 - {kind: Scalar, text: a}
1689 - {kind: Scalar, text: b}
1690 - {kind: Scalar, text: c}
1691 - kind: Mapping
1692 content: [{kind: Scalar, text: d}, {kind: Scalar, text: e}]
1693
1694 # Special characters in plain scalars
1695 - node-test:
1696 name: plain scalar with dash
1697 yaml: "foo-bar\n"
1698 node:
1699 kind: Document
1700 content:
1701 - {kind: Scalar, text: foo-bar}
1702
1703 - node-test:
1704 name: plain scalar with underscore
1705 yaml: "foo_bar\n"
1706 node:
1707 kind: Document
1708 content:
1709 - {kind: Scalar, text: foo_bar}
1710
1711 - node-test:
1712 name: plain scalar with dot
1713 yaml: "foo.bar\n"
1714 node:
1715 kind: Document
1716 content:
1717 - {kind: Scalar, text: foo.bar}
1718
1719 # Numbers with underscores (if supported)
1720 - node-test:
1721 name: number with underscores
1722 yaml: "1_000_000\n"
1723 node:
1724 kind: Document
1725 content:
1726 - {kind: Scalar, tag: '!!int', text: '1_000_000'}
1727
1728 # Zero variants
1729 - node-test:
1730 name: float zero
1731 yaml: "0.0\n"
1732 node:
1733 kind: Document
1734 content:
1735 - {kind: Scalar, tag: '!!float', text: '0.0'}
1736
1737 # Whitespace-only differences
1738 - node-test:
1739 name: mapping with extra blank line
1740 decode: true
1741 encode: false
1742 yaml: "a: b\n\nc: d\n"
1743 node:
1744 kind: Document
1745 content:
1746 - kind: Mapping
1747 content:
1748 - {kind: Scalar, text: a}
1749 - {kind: Scalar, text: b}
1750 - {kind: Scalar, text: c}
1751 - {kind: Scalar, text: d}
1752
1753 # Single quoted with escapes
1754 - node-test:
1755 name: single quoted with literal single quote
1756 yaml: "'don''t'\n"
1757 node:
1758 kind: Document
1759 content:
1760 - {kind: Scalar, style: Single, text: "don't"}
1761
1762 # Double quoted with various escapes
1763 - node-test:
1764 name: double quoted with backslash
1765 yaml: "\"foo\\\\bar\"\n"
1766 node:
1767 kind: Document
1768 content:
1769 - {kind: Scalar, style: Double, text: 'foo\bar'}
1770
1771 - node-test:
1772 name: double quoted with quote
1773 yaml: "\"foo\\\"bar\"\n"
1774 node:
1775 kind: Document
1776 content:
1777 - {kind: Scalar, style: Double, text: 'foo"bar'}
1778
1779 # Complex flow structures
1780 - node-test:
1781 name: flow mapping in flow sequence
1782 yaml: "[{a: 1}, {b: 2}]\n"
1783 node:
1784 kind: Document
1785 content:
1786 - kind: Sequence
1787 style: Flow
1788 content:
1789 - kind: Mapping
1790 style: Flow
1791 content: [{kind: Scalar, text: a}, {kind: Scalar, tag: '!!int', text: '1'}]
1792 - kind: Mapping
1793 style: Flow
1794 content: [{kind: Scalar, text: b}, {kind: Scalar, tag: '!!int', text: '2'}]
1795
1796 - node-test:
1797 name: flow sequence in flow mapping
1798 yaml: "{a: [1, 2], b: [3, 4]}\n"
1799 node:
1800 kind: Document
1801 content:
1802 - kind: Mapping
1803 style: Flow
1804 content:
1805 - {kind: Scalar, text: a}
1806 - kind: Sequence
1807 style: Flow
1808 content: [{kind: Scalar, tag: '!!int', text: '1'}, {kind: Scalar, tag: '!!int', text: '2'}]
1809 - {kind: Scalar, text: b}
1810 - kind: Sequence
1811 style: Flow
1812 content: [{kind: Scalar, tag: '!!int', text: '3'}, {kind: Scalar, tag: '!!int', text: '4'}]
1813
1814 # Edge case numbers
1815 - node-test:
1816 name: negative zero float
1817 yaml: "-0.0\n"
1818 node:
1819 kind: Document
1820 content:
1821 - {kind: Scalar, tag: '!!float', text: '-0.0'}
1822
1823 - node-test:
1824 name: integer zero
1825 yaml: "0\n"
1826 node:
1827 kind: Document
1828 content:
1829 - {kind: Scalar, tag: '!!int', text: '0'}
1830
1831 # More string edge cases
1832 - node-test:
1833 name: empty plain scalar becomes null
1834 decode: true
1835 encode: false
1836 yaml: "a:\nb: c\n"
1837 node:
1838 kind: Document
1839 content:
1840 - kind: Mapping
1841 content:
1842 - {kind: Scalar, text: a}
1843 - {kind: Scalar, tag: '!!null', text: ''}
1844 - {kind: Scalar, text: b}
1845 - {kind: Scalar, text: c}
1846
1847 # Multiline plain scalars
1848 - node-test:
1849 name: plain scalar on single line
1850 yaml: "this is a long string\n"
1851 node:
1852 kind: Document
1853 content:
1854 - {kind: Scalar, text: 'this is a long string'}
1855
1856 # Keys with special values
1857 - node-test:
1858 name: null as mapping key
1859 yaml: "null: value\n"
1860 node:
1861 kind: Document
1862 content:
1863 - kind: Mapping
1864 content: [{kind: Scalar, tag: '!!null', text: 'null'}, {kind: Scalar, text: value}]
1865
1866 - node-test:
1867 name: empty string as key
1868 yaml: "\"\": value\n"
1869 node:
1870 kind: Document
1871 content:
1872 - kind: Mapping
1873 content: [{kind: Scalar, style: Double, text: ''}, {kind: Scalar, text: value}]
1874
1875 # Floats with trailing zeros
1876 - node-test:
1877 name: float with trailing zero
1878 yaml: "1.0\n"
1879 node:
1880 kind: Document
1881 content:
1882 - {kind: Scalar, tag: '!!float', text: '1.0'}
1883
1884 - node-test:
1885 name: float with many decimals
1886 yaml: "3.141592653589793\n"
1887 node:
1888 kind: Document
1889 content:
1890 - {kind: Scalar, tag: '!!float', text: '3.141592653589793'}
1891
1892 # Mixed sequences
1893 - node-test:
1894 name: sequence of different collection types
1895 yaml: "- [a]\n- {b: c}\n"
1896 node:
1897 kind: Document
1898 content:
1899 - kind: Sequence
1900 content:
1901 - kind: Sequence
1902 style: Flow
1903 content: [{kind: Scalar, text: a}]
1904 - kind: Mapping
1905 style: Flow
1906 content: [{kind: Scalar, text: b}, {kind: Scalar, text: c}]
1907
1908 # More complex nested structures
1909 - node-test:
1910 name: mapping with sequence containing mappings
1911 yaml: "items:\n - name: foo\n value: 1\n - name: bar\n value: 2\n"
1912 node:
1913 kind: Document
1914 content:
1915 - kind: Mapping
1916 content:
1917 - {kind: Scalar, text: items}
1918 - kind: Sequence
1919 content:
1920 - kind: Mapping
1921 content: [{kind: Scalar, text: name}, {kind: Scalar, text: foo}, {kind: Scalar, text: value}, {kind: Scalar, tag: '!!int', text: '1'}]
1922 - kind: Mapping
1923 content: [{kind: Scalar, text: name}, {kind: Scalar, text: bar}, {kind: Scalar, text: value}, {kind: Scalar, tag: '!!int', text: '2'}]
1924
1925 # Different integer formats (hex, octal already covered)
1926 - node-test:
1927 name: binary integer
1928 yaml: "0b1010\n"
1929 node:
1930 kind: Document
1931 content:
1932 - {kind: Scalar, tag: '!!int', text: '0b1010'}
1933
1934 # More special float values
1935 - node-test:
1936 name: positive infinity
1937 yaml: ".inf\n"
1938 node:
1939 kind: Document
1940 content:
1941 - {kind: Scalar, tag: '!!float', text: '.inf'}
1942
1943 - node-test:
1944 name: negative infinity
1945 yaml: "-.inf\n"
1946 node:
1947 kind: Document
1948 content:
1949 - {kind: Scalar, tag: '!!float', text: '-.inf'}
1950
1951 - node-test:
1952 name: not a number
1953 yaml: ".nan\n"
1954 node:
1955 kind: Document
1956 content:
1957 - {kind: Scalar, tag: '!!float', text: '.nan'}
1958
1959 # Complex key-value patterns
1960 - node-test:
1961 name: complex key simple value
1962 yaml: "[a, b]: value\n"
1963 decode: true
1964 encode: false
1965 node:
1966 kind: Document
1967 content:
1968 - kind: Mapping
1969 content:
1970 - kind: Sequence
1971 style: Flow
1972 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}]
1973 - {kind: Scalar, text: value}
1974
1975 # Plain scalars that could be ambiguous
1976 - node-test:
1977 name: plain scalar starting with dash
1978 yaml: "\"- foo\"\n"
1979 node:
1980 kind: Document
1981 content:
1982 - {kind: Scalar, style: Double, text: '- foo'}
1983
1984 - node-test:
1985 name: plain scalar starting with bracket
1986 yaml: "\"[foo]\"\n"
1987 node:
1988 kind: Document
1989 content:
1990 - {kind: Scalar, style: Double, text: '[foo]'}
1991
1992 - node-test:
1993 name: plain scalar starting with brace
1994 yaml: "\"{foo}\"\n"
1995 node:
1996 kind: Document
1997 content:
1998 - {kind: Scalar, style: Double, text: '{foo}'}
1999
2000 # Sequences and mappings with comments on elements
2001 - node-test:
2002 name: sequence with line comments
2003 yaml: "- a # comment a\n- b # comment b\n"
2004 node:
2005 kind: Document
2006 content:
2007 - kind: Sequence
2008 content:
2009 - {kind: Scalar, text: a, line: '# comment a'}
2010 - {kind: Scalar, text: b, line: '# comment b'}
2011
2012 - node-test:
2013 name: mapping with line comments on values
2014 yaml: "a: 1 # first\nb: 2 # second\n"
2015 node:
2016 kind: Document
2017 content:
2018 - kind: Mapping
2019 content:
2020 - {kind: Scalar, text: a}
2021 - {kind: Scalar, tag: '!!int', text: '1', line: '# first'}
2022 - {kind: Scalar, text: b}
2023 - {kind: Scalar, tag: '!!int', text: '2', line: '# second'}
2024
2025 # More nested flow
2026 - node-test:
2027 name: deeply nested flow sequence
2028 yaml: "[[[a]]]\n"
2029 node:
2030 kind: Document
2031 content:
2032 - kind: Sequence
2033 style: Flow
2034 content:
2035 - kind: Sequence
2036 style: Flow
2037 content:
2038 - kind: Sequence
2039 style: Flow
2040 content: [{kind: Scalar, text: a}]
2041
2042 # More FootComment tests
2043 - node-test:
2044 name: scalar with foot comment
2045 yaml: "foo\n# foot\n"
2046 node:
2047 kind: Document
2048 content:
2049 - {kind: Scalar, text: foo, foot: '# foot'}
2050
2051 # Quoted special characters
2052 - node-test:
2053 name: double quoted with carriage return
2054 yaml: "\"foo\\rbar\"\n"
2055 node:
2056 kind: Document
2057 content:
2058 - {kind: Scalar, style: Double, text: "foo\rbar"}
2059
2060 # Multiple levels of flow nesting
2061 - node-test:
2062 name: flow mapping with nested sequences
2063 yaml: "{a: [1, 2], b: [3, 4]}\n"
2064 node:
2065 kind: Document
2066 content:
2067 - kind: Mapping
2068 style: Flow
2069 content:
2070 - {kind: Scalar, text: a}
2071 - kind: Sequence
2072 style: Flow
2073 content: [{kind: Scalar, tag: '!!int', text: '1'}, {kind: Scalar, tag: '!!int', text: '2'}]
2074 - {kind: Scalar, text: b}
2075 - kind: Sequence
2076 style: Flow
2077 content: [{kind: Scalar, tag: '!!int', text: '3'}, {kind: Scalar, tag: '!!int', text: '4'}]
2078
2079 # Literal and folded variations
2080 - node-test:
2081 name: literal with chomping indicator keep
2082 decode: true
2083 encode: false
2084 yaml: "|+\n content\n"
2085 node:
2086 kind: Document
2087 content:
2088 - {kind: Scalar, style: Literal, text: "content\n"}
2089
2090 - node-test:
2091 name: literal with chomping indicator strip
2092 yaml: "|-\n content\n"
2093 node:
2094 kind: Document
2095 content:
2096 - {kind: Scalar, style: Literal, text: content}
2097
2098 - node-test:
2099 name: folded with chomping indicator strip
2100 decode: true
2101 encode: false
2102 yaml: ">-\n content\n"
2103 node:
2104 kind: Document
2105 content:
2106 - {kind: Scalar, style: Folded, text: content}
2107
2108 # Collections as mapping keys
2109 - node-test:
2110 name: mapping as mapping key
2111 decode: true
2112 encode: false
2113 yaml: "{a: b}: value\n"
2114 node:
2115 kind: Document
2116 content:
2117 - kind: Mapping
2118 content:
2119 - kind: Mapping
2120 style: Flow
2121 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}]
2122 - {kind: Scalar, text: value}
2123
2124 # More empty value cases
2125 - node-test:
2126 name: two keys with empty values
2127 yaml: "a:\nb:\n"
2128 node:
2129 kind: Document
2130 content:
2131 - kind: Mapping
2132 content:
2133 - {kind: Scalar, text: a}
2134 - {kind: Scalar, tag: '!!null', text: ''}
2135 - {kind: Scalar, text: b}
2136 - {kind: Scalar, tag: '!!null', text: ''}
2137
2138 # Numbers in scientific notation edge cases
2139 - node-test:
2140 name: scientific notation with large exponent
2141 yaml: "1e100\n"
2142 node:
2143 kind: Document
2144 content:
2145 - {kind: Scalar, tag: '!!float', text: '1e100'}
2146
2147 # Multiline strings in flow collections
2148 - node-test:
2149 name: flow mapping with quoted multiline value
2150 yaml: "{a: \"line1\\nline2\"}\n"
2151 node:
2152 kind: Document
2153 content:
2154 - kind: Mapping
2155 style: Flow
2156 content:
2157 - {kind: Scalar, text: a}
2158 - {kind: Scalar, style: Double, text: "line1\nline2"}
2159
2160 # Sequences with null elements
2161 - node-test:
2162 name: sequence with null elements
2163 yaml: "- null\n- ~\n-\n"
2164 node:
2165 kind: Document
2166 content:
2167 - kind: Sequence
2168 content:
2169 - {kind: Scalar, tag: '!!null', text: 'null'}
2170 - {kind: Scalar, tag: '!!null', text: '~'}
2171 - {kind: Scalar, tag: '!!null', text: ''}
2172
2173 # Mix of inline and block in same document
2174 - node-test:
2175 name: block mapping then flow mapping
2176 yaml: "a: b\nc: {d: e}\n"
2177 node:
2178 kind: Document
2179 content:
2180 - kind: Mapping
2181 content:
2182 - {kind: Scalar, text: a}
2183 - {kind: Scalar, text: b}
2184 - {kind: Scalar, text: c}
2185 - kind: Mapping
2186 style: Flow
2187 content: [{kind: Scalar, text: d}, {kind: Scalar, text: e}]
2188
2189 - node-test:
2190 name: block sequence then flow sequence
2191 yaml: "- a\n- [b, c]\n"
2192 node:
2193 kind: Document
2194 content:
2195 - kind: Sequence
2196 content:
2197 - {kind: Scalar, text: a}
2198 - kind: Sequence
2199 style: Flow
2200 content: [{kind: Scalar, text: b}, {kind: Scalar, text: c}]
2201
2202 # Special mapping key cases
2203 - node-test:
2204 name: quoted number as key
2205 yaml: "\"123\": value\n"
2206 node:
2207 kind: Document
2208 content:
2209 - kind: Mapping
2210 content:
2211 - {kind: Scalar, style: Double, text: '123'}
2212 - {kind: Scalar, text: value}
2213
2214 - node-test:
2215 name: quoted boolean as key
2216 yaml: "\"true\": value\n"
2217 node:
2218 kind: Document
2219 content:
2220 - kind: Mapping
2221 content:
2222 - {kind: Scalar, style: Double, text: 'true'}
2223 - {kind: Scalar, text: value}
2224
2225 # Edge cases with whitespace
2226 - node-test:
2227 name: value with only spaces quoted
2228 yaml: "a: \" \"\n"
2229 node:
2230 kind: Document
2231 content:
2232 - kind: Mapping
2233 content:
2234 - {kind: Scalar, text: a}
2235 - {kind: Scalar, style: Double, text: ' '}
2236
2237 # More complex comments
2238 - node-test:
2239 name: head comment on second mapping key
2240 decode: true
2241 encode: false
2242 yaml: "a: 1\n# head\nb: 2\n"
2243 node:
2244 kind: Document
2245 content:
2246 - kind: Mapping
2247 content:
2248 - {kind: Scalar, text: a}
2249 - {kind: Scalar, tag: '!!int', text: '1'}
2250 - {kind: Scalar, text: b, head: '# head'}
2251 - {kind: Scalar, tag: '!!int', text: '2'}
2252
2253 # Nested empty collections
2254 - node-test:
2255 name: empty mapping in mapping
2256 yaml: "a: {}\n"
2257 node:
2258 kind: Document
2259 content:
2260 - kind: Mapping
2261 content:
2262 - {kind: Scalar, text: a}
2263 - kind: Mapping
2264 style: Flow
2265
2266 - node-test:
2267 name: empty sequence in sequence
2268 yaml: "- []\n"
2269 node:
2270 kind: Document
2271 content:
2272 - kind: Sequence
2273 content:
2274 - kind: Sequence
2275 style: Flow
2276
2277 # More integer edge cases
2278 - node-test:
2279 name: negative integer
2280 yaml: "-42\n"
2281 node:
2282 kind: Document
2283 content:
2284 - {kind: Scalar, tag: '!!int', text: '-42'}
2285
2286 - node-test:
2287 name: large negative integer
2288 yaml: "-9223372036854775808\n"
2289 node:
2290 kind: Document
2291 content:
2292 - {kind: Scalar, tag: '!!int', text: '-9223372036854775808'}
2293
2294 # String that looks like a tag
2295 - node-test:
2296 name: quoted string resembling tag
2297 yaml: "\"!!str\"\n"
2298 node:
2299 kind: Document
2300 content:
2301 - {kind: Scalar, style: Double, text: '!!str'}
2302
2303 # More nesting combinations
2304 - node-test:
2305 name: five-level nested mapping
2306 yaml: "a:\n b:\n c:\n d:\n e: f\n"
2307 node:
2308 kind: Document
2309 content:
2310 - kind: Mapping
2311 content:
2312 - {kind: Scalar, text: a}
2313 - kind: Mapping
2314 content:
2315 - {kind: Scalar, text: b}
2316 - kind: Mapping
2317 content:
2318 - {kind: Scalar, text: c}
2319 - kind: Mapping
2320 content:
2321 - {kind: Scalar, text: d}
2322 - kind: Mapping
2323 content: [{kind: Scalar, text: e}, {kind: Scalar, text: f}]
2324
2325 # Final edge cases to reach completion
2326 - node-test:
2327 name: sequence of empty mappings
2328 yaml: "- {}\n- {}\n"
2329 node:
2330 kind: Document
2331 content:
2332 - kind: Sequence
2333 content:
2334 - kind: Mapping
2335 style: Flow
2336 - kind: Mapping
2337 style: Flow
2338
2339 - node-test:
2340 name: mapping of empty sequences
2341 yaml: "a: []\nb: []\n"
2342 node:
2343 kind: Document
2344 content:
2345 - kind: Mapping
2346 content:
2347 - {kind: Scalar, text: a}
2348 - kind: Sequence
2349 style: Flow
2350 - {kind: Scalar, text: b}
2351 - kind: Sequence
2352 style: Flow
2353
2354 - node-test:
2355 name: deeply nested sequences
2356 yaml: "- - - a\n"
2357 node:
2358 kind: Document
2359 content:
2360 - kind: Sequence
2361 content:
2362 - kind: Sequence
2363 content:
2364 - kind: Sequence
2365 content: [{kind: Scalar, text: a}]
2366
2367 - node-test:
2368 name: mapping value as empty quoted string
2369 yaml: "a: \"\"\n"
2370 node:
2371 kind: Document
2372 content:
2373 - kind: Mapping
2374 content:
2375 - {kind: Scalar, text: a}
2376 - {kind: Scalar, style: Double, text: ''}
2377
2378 - node-test:
2379 name: flow mapping with spaces around colon
2380 decode: true
2381 encode: false
2382 yaml: "{a : b}\n"
2383 node:
2384 kind: Document
2385 content:
2386 - kind: Mapping
2387 style: Flow
2388 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}]
2389
2390 - node-test:
2391 name: flow sequence with extra spaces
2392 decode: true
2393 encode: false
2394 yaml: "[ a , b ]\n"
2395 node:
2396 kind: Document
2397 content:
2398 - kind: Sequence
2399 style: Flow
2400 content: [{kind: Scalar, text: a}, {kind: Scalar, text: b}]
2401
2402 - node-test:
2403 name: plain scalar with numbers and letters
2404 yaml: "abc123\n"
2405 node:
2406 kind: Document
2407 content:
2408 - {kind: Scalar, text: abc123}
2409
2410 - node-test:
2411 name: plain scalar with mixed case
2412 yaml: "FooBar\n"
2413 node:
2414 kind: Document
2415 content:
2416 - {kind: Scalar, text: FooBar}
2417
2418 - node-test:
2419 name: mapping with numeric string keys and values
2420 yaml: "\"1\": \"2\"\n"
2421 node:
2422 kind: Document
2423 content:
2424 - kind: Mapping
2425 content:
2426 - {kind: Scalar, style: Double, text: '1'}
2427 - {kind: Scalar, style: Double, text: '2'}
2428
2429 - node-test:
2430 name: three empty sequences
2431 yaml: "- []\n- []\n- []\n"
2432 node:
2433 kind: Document
2434 content:
2435 - kind: Sequence
2436 content:
2437 - kind: Sequence
2438 style: Flow
2439 - kind: Sequence
2440 style: Flow
2441 - kind: Sequence
2442 style: Flow
2443
2444 - node-test:
2445 name: complex mixed nesting
2446 yaml: "- a: 1\n b:\n - c\n"
2447 node:
2448 kind: Document
2449 content:
2450 - kind: Sequence
2451 content:
2452 - kind: Mapping
2453 content:
2454 - {kind: Scalar, text: a}
2455 - {kind: Scalar, tag: '!!int', text: '1'}
2456 - {kind: Scalar, text: b}
2457 - kind: Sequence
2458 content: [{kind: Scalar, text: c}]
2459
2460 - node-test:
2461 name: alternating scalars and collections
2462 yaml: "- foo\n- [bar]\n- baz\n- {qux: 1}\n"
2463 node:
2464 kind: Document
2465 content:
2466 - kind: Sequence
2467 content:
2468 - {kind: Scalar, text: foo}
2469 - kind: Sequence
2470 style: Flow
2471 content: [{kind: Scalar, text: bar}]
2472 - {kind: Scalar, text: baz}
2473 - kind: Mapping
2474 style: Flow
2475 content: [{kind: Scalar, text: qux}, {kind: Scalar, tag: '!!int', text: '1'}]
2476
2477 # Merge key encoding tests.
2478 # An implicit !!merge tag (Tag set but no TaggedStyle) is elided on output
2479 # so callers that hand-build a node with Value: "<<" get clean `<<:` syntax
2480 # (yq issue #2677). An explicit !!merge (TaggedStyle set) is preserved.
2481 - node-test:
2482 name: merge key with flow mapping value
2483 yaml: "<<: {a: 1}\n"
2484 decode: false
2485 node:
2486 kind: Document
2487 content:
2488 - kind: Mapping
2489 content:
2490 - kind: Scalar
2491 tag: '!!merge'
2492 text: '<<'
2493 - kind: Mapping
2494 style: Flow
2495 content:
2496 - {kind: Scalar, text: a}
2497 - {kind: Scalar, tag: '!!int', text: '1'}
2498
2499 - node-test:
2500 name: merge key in nested mapping
2501 yaml: "foo:\n <<: {a: 1}\n"
2502 decode: false
2503 node:
2504 kind: Document
2505 content:
2506 - kind: Mapping
2507 content:
2508 - kind: Scalar
2509 text: foo
2510 - kind: Mapping
2511 content:
2512 - kind: Scalar
2513 tag: '!!merge'
2514 text: '<<'
2515 - kind: Mapping
2516 style: Flow
2517 content:
2518 - {kind: Scalar, text: a}
2519 - {kind: Scalar, tag: '!!int', text: '1'}
2520
2521 - node-test:
2522 name: merge key with explicit tag preserved
2523 yaml: "!!merge <<: {a: 1}\n"
2524 decode: false
2525 node:
2526 kind: Document
2527 content:
2528 - kind: Mapping
2529 content:
2530 - kind: Scalar
2531 tag: '!!merge'
2532 style: Tagged
2533 text: '<<'
2534 - kind: Mapping
2535 style: Flow
2536 content:
2537 - {kind: Scalar, text: a}
2538 - {kind: Scalar, tag: '!!int', text: '1'}
2539
2540 - node-test:
2541 name: bare merge key with untagged scalar
2542 yaml: "<<: {a: 1}\n"
2543 decode: false
2544 node:
2545 kind: Document
2546 content:
2547 - kind: Mapping
2548 content:
2549 - kind: Scalar
2550 text: '<<'
2551 - kind: Mapping
2552 style: Flow
2553 content:
2554 - {kind: Scalar, text: a}
2555 - {kind: Scalar, tag: '!!int', text: '1'}