Debian Codegraph @

dependencies/pkg/mod/github.com/goccy/[email protected]/lexer/lexer_test.go

raw
1 package lexer_test
2
3 import (
4 "sort"
5 "testing"
6
7 "github.com/goccy/go-yaml/lexer"
8 "github.com/goccy/go-yaml/token"
9 )
10
11 func TestTokenize(t *testing.T) {
12 tests := []struct {
13 YAML string
14 Tokens token.Tokens
15 }{
16 {
17 YAML: `null
18 `,
19 Tokens: token.Tokens{
20 {
21 Type: token.NullType,
22 CharacterType: token.CharacterTypeMiscellaneous,
23 Indicator: token.NotIndicator,
24 Value: "null",
25 Origin: "null\n\t\t",
26 },
27 },
28 },
29 {
30 YAML: `{}
31 `,
32 Tokens: token.Tokens{
33 {
34 Type: token.MappingStartType,
35 CharacterType: token.CharacterTypeIndicator,
36 Indicator: token.FlowCollectionIndicator,
37 Value: "{",
38 Origin: "{",
39 },
40 {
41 Type: token.MappingEndType,
42 CharacterType: token.CharacterTypeIndicator,
43 Indicator: token.FlowCollectionIndicator,
44 Value: "}",
45 Origin: "}",
46 },
47 },
48 },
49 {
50 YAML: `v: hi
51 `,
52 Tokens: token.Tokens{
53 {
54 Type: token.StringType,
55 CharacterType: token.CharacterTypeMiscellaneous,
56 Indicator: token.NotIndicator,
57 Value: "v",
58 Origin: "v",
59 },
60 {
61 Type: token.MappingValueType,
62 CharacterType: token.CharacterTypeIndicator,
63 Indicator: token.BlockStructureIndicator,
64 Value: ":",
65 Origin: ":",
66 },
67 {
68 Type: token.StringType,
69 CharacterType: token.CharacterTypeMiscellaneous,
70 Indicator: token.NotIndicator,
71 Value: "hi",
72 Origin: " hi\n",
73 },
74 },
75 },
76 {
77 YAML: `v: "true"
78 `,
79 Tokens: token.Tokens{
80 {
81 Type: token.StringType,
82 CharacterType: token.CharacterTypeMiscellaneous,
83 Indicator: token.NotIndicator,
84 Value: "v",
85 Origin: "v",
86 },
87 {
88 Type: token.MappingValueType,
89 CharacterType: token.CharacterTypeIndicator,
90 Indicator: token.BlockStructureIndicator,
91 Value: ":",
92 Origin: ":",
93 },
94 {
95 Type: token.DoubleQuoteType,
96 CharacterType: token.CharacterTypeIndicator,
97 Indicator: token.QuotedScalarIndicator,
98 Value: "true",
99 Origin: " \"true\"",
100 },
101 },
102 },
103 {
104 YAML: `v: "false"
105 `,
106 Tokens: token.Tokens{
107 {
108 Type: token.StringType,
109 CharacterType: token.CharacterTypeMiscellaneous,
110 Indicator: token.NotIndicator,
111 Value: "v",
112 Origin: "v",
113 },
114 {
115 Type: token.MappingValueType,
116 CharacterType: token.CharacterTypeIndicator,
117 Indicator: token.BlockStructureIndicator,
118 Value: ":",
119 Origin: ":",
120 },
121 {
122 Type: token.DoubleQuoteType,
123 CharacterType: token.CharacterTypeIndicator,
124 Indicator: token.QuotedScalarIndicator,
125 Value: "false",
126 Origin: " \"false\"",
127 },
128 },
129 },
130 {
131 YAML: `v: true
132 `,
133 Tokens: token.Tokens{
134 {
135 Type: token.StringType,
136 CharacterType: token.CharacterTypeMiscellaneous,
137 Indicator: token.NotIndicator,
138 Value: "v",
139 Origin: "v",
140 },
141 {
142 Type: token.MappingValueType,
143 CharacterType: token.CharacterTypeIndicator,
144 Indicator: token.BlockStructureIndicator,
145 Value: ":",
146 Origin: ":",
147 },
148 {
149 Type: token.BoolType,
150 CharacterType: token.CharacterTypeMiscellaneous,
151 Indicator: token.NotIndicator,
152 Value: "true",
153 Origin: " true\n",
154 },
155 },
156 },
157 {
158 YAML: `v: false
159 `,
160 Tokens: token.Tokens{
161 {
162 Type: token.StringType,
163 CharacterType: token.CharacterTypeMiscellaneous,
164 Indicator: token.NotIndicator,
165 Value: "v",
166 Origin: "v",
167 },
168 {
169 Type: token.MappingValueType,
170 CharacterType: token.CharacterTypeIndicator,
171 Indicator: token.BlockStructureIndicator,
172 Value: ":",
173 Origin: ":",
174 },
175 {
176 Type: token.BoolType,
177 CharacterType: token.CharacterTypeMiscellaneous,
178 Indicator: token.NotIndicator,
179 Value: "false",
180 Origin: " false\n",
181 },
182 },
183 },
184 {
185 YAML: `v: 10
186 `,
187 Tokens: token.Tokens{
188 {
189 Type: token.StringType,
190 CharacterType: token.CharacterTypeMiscellaneous,
191 Indicator: token.NotIndicator,
192 Value: "v",
193 Origin: "v",
194 },
195 {
196 Type: token.MappingValueType,
197 CharacterType: token.CharacterTypeIndicator,
198 Indicator: token.BlockStructureIndicator,
199 Value: ":",
200 Origin: ":",
201 },
202 {
203 Type: token.IntegerType,
204 CharacterType: token.CharacterTypeMiscellaneous,
205 Indicator: token.NotIndicator,
206 Value: "10",
207 Origin: " 10\n",
208 },
209 },
210 },
211 {
212 YAML: `v: -10
213 `,
214 Tokens: token.Tokens{
215 {
216 Type: token.StringType,
217 CharacterType: token.CharacterTypeMiscellaneous,
218 Indicator: token.NotIndicator,
219 Value: "v",
220 Origin: "v",
221 },
222 {
223 Type: token.MappingValueType,
224 CharacterType: token.CharacterTypeIndicator,
225 Indicator: token.BlockStructureIndicator,
226 Value: ":",
227 Origin: ":",
228 },
229 {
230 Type: token.IntegerType,
231 CharacterType: token.CharacterTypeMiscellaneous,
232 Indicator: token.NotIndicator,
233 Value: "-10",
234 Origin: " -10\n",
235 },
236 },
237 },
238 {
239 YAML: `v: 42
240 `,
241 Tokens: token.Tokens{
242 {
243 Type: token.StringType,
244 CharacterType: token.CharacterTypeMiscellaneous,
245 Indicator: token.NotIndicator,
246 Value: "v",
247 Origin: "v",
248 },
249 {
250 Type: token.MappingValueType,
251 CharacterType: token.CharacterTypeIndicator,
252 Indicator: token.BlockStructureIndicator,
253 Value: ":",
254 Origin: ":",
255 },
256 {
257 Type: token.IntegerType,
258 CharacterType: token.CharacterTypeMiscellaneous,
259 Indicator: token.NotIndicator,
260 Value: "42",
261 Origin: " 42\n",
262 },
263 },
264 },
265 {
266 YAML: `v: 4294967296
267 `,
268 Tokens: token.Tokens{
269 {
270 Type: token.StringType,
271 CharacterType: token.CharacterTypeMiscellaneous,
272 Indicator: token.NotIndicator,
273 Value: "v",
274 Origin: "v",
275 },
276 {
277 Type: token.MappingValueType,
278 CharacterType: token.CharacterTypeIndicator,
279 Indicator: token.BlockStructureIndicator,
280 Value: ":",
281 Origin: ":",
282 },
283 {
284 Type: token.IntegerType,
285 CharacterType: token.CharacterTypeMiscellaneous,
286 Indicator: token.NotIndicator,
287 Value: "4294967296",
288 Origin: " 4294967296\n",
289 },
290 },
291 },
292 {
293 YAML: `v: "10"
294 `,
295 Tokens: token.Tokens{
296 {
297 Type: token.StringType,
298 CharacterType: token.CharacterTypeMiscellaneous,
299 Indicator: token.NotIndicator,
300 Value: "v",
301 Origin: "v",
302 },
303 {
304 Type: token.MappingValueType,
305 CharacterType: token.CharacterTypeIndicator,
306 Indicator: token.BlockStructureIndicator,
307 Value: ":",
308 Origin: ":",
309 },
310 {
311 Type: token.DoubleQuoteType,
312 CharacterType: token.CharacterTypeIndicator,
313 Indicator: token.QuotedScalarIndicator,
314 Value: "10",
315 Origin: " \"10\"",
316 },
317 },
318 },
319 {
320 YAML: `v: 0.1
321 `,
322 Tokens: token.Tokens{
323 {
324 Type: token.StringType,
325 CharacterType: token.CharacterTypeMiscellaneous,
326 Indicator: token.NotIndicator,
327 Value: "v",
328 Origin: "v",
329 },
330 {
331 Type: token.MappingValueType,
332 CharacterType: token.CharacterTypeIndicator,
333 Indicator: token.BlockStructureIndicator,
334 Value: ":",
335 Origin: ":",
336 },
337 {
338 Type: token.FloatType,
339 CharacterType: token.CharacterTypeMiscellaneous,
340 Indicator: token.NotIndicator,
341 Value: "0.1",
342 Origin: " 0.1\n",
343 },
344 },
345 },
346 {
347 YAML: `v: 0.99
348 `,
349 Tokens: token.Tokens{
350 {
351 Type: token.StringType,
352 CharacterType: token.CharacterTypeMiscellaneous,
353 Indicator: token.NotIndicator,
354 Value: "v",
355 Origin: "v",
356 },
357 {
358 Type: token.MappingValueType,
359 CharacterType: token.CharacterTypeIndicator,
360 Indicator: token.BlockStructureIndicator,
361 Value: ":",
362 Origin: ":",
363 },
364 {
365 Type: token.FloatType,
366 CharacterType: token.CharacterTypeMiscellaneous,
367 Indicator: token.NotIndicator,
368 Value: "0.99",
369 Origin: " 0.99\n",
370 },
371 },
372 },
373 {
374 YAML: `v: -0.1
375 `,
376 Tokens: token.Tokens{
377 {
378 Type: token.StringType,
379 CharacterType: token.CharacterTypeMiscellaneous,
380 Indicator: token.NotIndicator,
381 Value: "v",
382 Origin: "v",
383 },
384 {
385 Type: token.MappingValueType,
386 CharacterType: token.CharacterTypeIndicator,
387 Indicator: token.BlockStructureIndicator,
388 Value: ":",
389 Origin: ":",
390 },
391 {
392 Type: token.FloatType,
393 CharacterType: token.CharacterTypeMiscellaneous,
394 Indicator: token.NotIndicator,
395 Value: "-0.1",
396 Origin: " -0.1\n",
397 },
398 },
399 },
400 {
401 YAML: `v: .inf
402 `,
403 Tokens: token.Tokens{
404 {
405 Type: token.StringType,
406 CharacterType: token.CharacterTypeMiscellaneous,
407 Indicator: token.NotIndicator,
408 Value: "v",
409 Origin: "v",
410 },
411 {
412 Type: token.MappingValueType,
413 CharacterType: token.CharacterTypeIndicator,
414 Indicator: token.BlockStructureIndicator,
415 Value: ":",
416 Origin: ":",
417 },
418 {
419 Type: token.InfinityType,
420 CharacterType: token.CharacterTypeMiscellaneous,
421 Indicator: token.NotIndicator,
422 Value: ".inf",
423 Origin: " .inf\n",
424 },
425 },
426 },
427 {
428 YAML: `v: -.inf
429 `,
430 Tokens: token.Tokens{
431 {
432 Type: token.StringType,
433 CharacterType: token.CharacterTypeMiscellaneous,
434 Indicator: token.NotIndicator,
435 Value: "v",
436 Origin: "v",
437 },
438 {
439 Type: token.MappingValueType,
440 CharacterType: token.CharacterTypeIndicator,
441 Indicator: token.BlockStructureIndicator,
442 Value: ":",
443 Origin: ":",
444 },
445 {
446 Type: token.InfinityType,
447 CharacterType: token.CharacterTypeMiscellaneous,
448 Indicator: token.NotIndicator,
449 Value: "-.inf",
450 Origin: " -.inf\n",
451 },
452 },
453 },
454 {
455 YAML: `v: .nan
456 `,
457 Tokens: token.Tokens{
458 {
459 Type: token.StringType,
460 CharacterType: token.CharacterTypeMiscellaneous,
461 Indicator: token.NotIndicator,
462 Value: "v",
463 Origin: "v",
464 },
465 {
466 Type: token.MappingValueType,
467 CharacterType: token.CharacterTypeIndicator,
468 Indicator: token.BlockStructureIndicator,
469 Value: ":",
470 Origin: ":",
471 },
472 {
473 Type: token.NanType,
474 CharacterType: token.CharacterTypeMiscellaneous,
475 Indicator: token.NotIndicator,
476 Value: ".nan",
477 Origin: " .nan\n",
478 },
479 },
480 },
481 {
482 YAML: `v: null
483 `,
484 Tokens: token.Tokens{
485 {
486 Type: token.StringType,
487 CharacterType: token.CharacterTypeMiscellaneous,
488 Indicator: token.NotIndicator,
489 Value: "v",
490 Origin: "v",
491 },
492 {
493 Type: token.MappingValueType,
494 CharacterType: token.CharacterTypeIndicator,
495 Indicator: token.BlockStructureIndicator,
496 Value: ":",
497 Origin: ":",
498 },
499 {
500 Type: token.NullType,
501 CharacterType: token.CharacterTypeMiscellaneous,
502 Indicator: token.NotIndicator,
503 Value: "null",
504 Origin: " null\n",
505 },
506 },
507 },
508 {
509 YAML: `v: ""
510 `,
511 Tokens: token.Tokens{
512 {
513 Type: token.StringType,
514 CharacterType: token.CharacterTypeMiscellaneous,
515 Indicator: token.NotIndicator,
516 Value: "v",
517 Origin: "v",
518 },
519 {
520 Type: token.MappingValueType,
521 CharacterType: token.CharacterTypeIndicator,
522 Indicator: token.BlockStructureIndicator,
523 Value: ":",
524 Origin: ":",
525 },
526 {
527 Type: token.DoubleQuoteType,
528 CharacterType: token.CharacterTypeIndicator,
529 Indicator: token.QuotedScalarIndicator,
530 Value: "",
531 Origin: " \"\"",
532 },
533 },
534 },
535 {
536 YAML: `v:
537 - A
538 - B
539 `,
540 Tokens: token.Tokens{
541 {
542 Type: token.StringType,
543 CharacterType: token.CharacterTypeMiscellaneous,
544 Indicator: token.NotIndicator,
545 Value: "v",
546 Origin: "v",
547 },
548 {
549 Type: token.MappingValueType,
550 CharacterType: token.CharacterTypeIndicator,
551 Indicator: token.BlockStructureIndicator,
552 Value: ":",
553 Origin: ":",
554 },
555 {
556 Type: token.SequenceEntryType,
557 CharacterType: token.CharacterTypeIndicator,
558 Indicator: token.BlockStructureIndicator,
559 Value: "-",
560 Origin: "\n\t\t-",
561 },
562 {
563 Type: token.StringType,
564 CharacterType: token.CharacterTypeMiscellaneous,
565 Indicator: token.NotIndicator,
566 Value: "A",
567 Origin: " A\n",
568 },
569 {
570 Type: token.SequenceEntryType,
571 CharacterType: token.CharacterTypeIndicator,
572 Indicator: token.BlockStructureIndicator,
573 Value: "-",
574 Origin: "\t\t-",
575 },
576 {
577 Type: token.StringType,
578 CharacterType: token.CharacterTypeMiscellaneous,
579 Indicator: token.NotIndicator,
580 Value: "B",
581 Origin: " B\n",
582 },
583 },
584 },
585 {
586 YAML: `v:
587 - A
588 - |-
589 B
590 C
591 `,
592 Tokens: token.Tokens{
593 {
594 Type: token.StringType,
595 CharacterType: token.CharacterTypeMiscellaneous,
596 Indicator: token.NotIndicator,
597 Value: "v",
598 Origin: "v",
599 },
600 {
601 Type: token.MappingValueType,
602 CharacterType: token.CharacterTypeIndicator,
603 Indicator: token.BlockStructureIndicator,
604 Value: ":",
605 Origin: ":",
606 },
607 {
608 Type: token.SequenceEntryType,
609 CharacterType: token.CharacterTypeIndicator,
610 Indicator: token.BlockStructureIndicator,
611 Value: "-",
612 Origin: "\n\t\t-",
613 },
614 {
615 Type: token.StringType,
616 CharacterType: token.CharacterTypeMiscellaneous,
617 Indicator: token.NotIndicator,
618 Value: "A",
619 Origin: " A\n",
620 },
621 {
622 Type: token.SequenceEntryType,
623 CharacterType: token.CharacterTypeIndicator,
624 Indicator: token.BlockStructureIndicator,
625 Value: "-",
626 Origin: "\t\t-",
627 },
628 {
629 Type: token.LiteralType,
630 CharacterType: token.CharacterTypeIndicator,
631 Indicator: token.BlockScalarIndicator,
632 Value: "|-",
633 Origin: " |-\n",
634 },
635 {
636 Type: token.StringType,
637 CharacterType: token.CharacterTypeMiscellaneous,
638 Indicator: token.NotIndicator,
639 Value: "\t\t B",
640 Origin: "\t\t B\n",
641 },
642 {
643 Type: token.StringType,
644 CharacterType: token.CharacterTypeMiscellaneous,
645 Indicator: token.NotIndicator,
646 Value: "\t\t C",
647 Origin: "\t\t C\n",
648 },
649 },
650 },
651 {
652 YAML: `v:
653 - A
654 - 1
655 - B:
656 - 2
657 - 3
658 `,
659 Tokens: token.Tokens{
660 {
661 Type: token.StringType,
662 CharacterType: token.CharacterTypeMiscellaneous,
663 Indicator: token.NotIndicator,
664 Value: "v",
665 Origin: "v",
666 },
667 {
668 Type: token.MappingValueType,
669 CharacterType: token.CharacterTypeIndicator,
670 Indicator: token.BlockStructureIndicator,
671 Value: ":",
672 Origin: ":",
673 },
674 {
675 Type: token.SequenceEntryType,
676 CharacterType: token.CharacterTypeIndicator,
677 Indicator: token.BlockStructureIndicator,
678 Value: "-",
679 Origin: "\n\t\t-",
680 },
681 {
682 Type: token.StringType,
683 CharacterType: token.CharacterTypeMiscellaneous,
684 Indicator: token.NotIndicator,
685 Value: "A",
686 Origin: " A\n",
687 },
688 {
689 Type: token.SequenceEntryType,
690 CharacterType: token.CharacterTypeIndicator,
691 Indicator: token.BlockStructureIndicator,
692 Value: "-",
693 Origin: "\t\t-",
694 },
695 {
696 Type: token.IntegerType,
697 CharacterType: token.CharacterTypeMiscellaneous,
698 Indicator: token.NotIndicator,
699 Value: "1",
700 Origin: " 1\n",
701 },
702 {
703 Type: token.SequenceEntryType,
704 CharacterType: token.CharacterTypeIndicator,
705 Indicator: token.BlockStructureIndicator,
706 Value: "-",
707 Origin: "\t\t-",
708 },
709 {
710 Type: token.StringType,
711 CharacterType: token.CharacterTypeMiscellaneous,
712 Indicator: token.NotIndicator,
713 Value: "B",
714 Origin: " B",
715 },
716 {
717 Type: token.MappingValueType,
718 CharacterType: token.CharacterTypeIndicator,
719 Indicator: token.BlockStructureIndicator,
720 Value: ":",
721 Origin: ":",
722 },
723 {
724 Type: token.SequenceEntryType,
725 CharacterType: token.CharacterTypeIndicator,
726 Indicator: token.BlockStructureIndicator,
727 Value: "-",
728 Origin: "\n\t\t -",
729 },
730 {
731 Type: token.IntegerType,
732 CharacterType: token.CharacterTypeMiscellaneous,
733 Indicator: token.NotIndicator,
734 Value: "2",
735 Origin: " 2\n",
736 },
737 {
738 Type: token.SequenceEntryType,
739 CharacterType: token.CharacterTypeIndicator,
740 Indicator: token.BlockStructureIndicator,
741 Value: "-",
742 Origin: "\t\t -",
743 },
744 {
745 Type: token.IntegerType,
746 CharacterType: token.CharacterTypeMiscellaneous,
747 Indicator: token.NotIndicator,
748 Value: "3",
749 Origin: " 3\n",
750 },
751 },
752 },
753 {
754 YAML: `a:
755 b: c
756 `,
757 Tokens: token.Tokens{
758 {
759 Type: token.StringType,
760 CharacterType: token.CharacterTypeMiscellaneous,
761 Indicator: token.NotIndicator,
762 Value: "a",
763 Origin: "a",
764 },
765 {
766 Type: token.MappingValueType,
767 CharacterType: token.CharacterTypeIndicator,
768 Indicator: token.BlockStructureIndicator,
769 Value: ":",
770 Origin: ":",
771 },
772 {
773 Type: token.StringType,
774 CharacterType: token.CharacterTypeMiscellaneous,
775 Indicator: token.NotIndicator,
776 Value: "\t\t b",
777 Origin: "\n\t\t b",
778 },
779 {
780 Type: token.MappingValueType,
781 CharacterType: token.CharacterTypeIndicator,
782 Indicator: token.BlockStructureIndicator,
783 Value: ":",
784 Origin: ":",
785 },
786 {
787 Type: token.StringType,
788 CharacterType: token.CharacterTypeMiscellaneous,
789 Indicator: token.NotIndicator,
790 Value: "c",
791 Origin: " c\n",
792 },
793 },
794 },
795 {
796 YAML: `a: '-'
797 `,
798 Tokens: token.Tokens{
799 {
800 Type: token.StringType,
801 CharacterType: token.CharacterTypeMiscellaneous,
802 Indicator: token.NotIndicator,
803 Value: "a",
804 Origin: "a",
805 },
806 {
807 Type: token.MappingValueType,
808 CharacterType: token.CharacterTypeIndicator,
809 Indicator: token.BlockStructureIndicator,
810 Value: ":",
811 Origin: ":",
812 },
813 {
814 Type: token.SingleQuoteType,
815 CharacterType: token.CharacterTypeIndicator,
816 Indicator: token.QuotedScalarIndicator,
817 Value: "-",
818 Origin: " '-'",
819 },
820 },
821 },
822 {
823 YAML: `123
824 `,
825 Tokens: token.Tokens{
826 {
827 Type: token.IntegerType,
828 CharacterType: token.CharacterTypeMiscellaneous,
829 Indicator: token.NotIndicator,
830 Value: "123",
831 Origin: "123\n\t\t",
832 },
833 },
834 },
835 {
836 YAML: `hello: world
837 `,
838 Tokens: token.Tokens{
839 {
840 Type: token.StringType,
841 CharacterType: token.CharacterTypeMiscellaneous,
842 Indicator: token.NotIndicator,
843 Value: "hello",
844 Origin: "hello",
845 },
846 {
847 Type: token.MappingValueType,
848 CharacterType: token.CharacterTypeIndicator,
849 Indicator: token.BlockStructureIndicator,
850 Value: ":",
851 Origin: ":",
852 },
853 {
854 Type: token.StringType,
855 CharacterType: token.CharacterTypeMiscellaneous,
856 Indicator: token.NotIndicator,
857 Value: "world",
858 Origin: " world\n",
859 },
860 },
861 },
862 {
863 YAML: `a: null
864 `,
865 Tokens: token.Tokens{
866 {
867 Type: token.StringType,
868 CharacterType: token.CharacterTypeMiscellaneous,
869 Indicator: token.NotIndicator,
870 Value: "a",
871 Origin: "a",
872 },
873 {
874 Type: token.MappingValueType,
875 CharacterType: token.CharacterTypeIndicator,
876 Indicator: token.BlockStructureIndicator,
877 Value: ":",
878 Origin: ":",
879 },
880 {
881 Type: token.NullType,
882 CharacterType: token.CharacterTypeMiscellaneous,
883 Indicator: token.NotIndicator,
884 Value: "null",
885 Origin: " null\n",
886 },
887 },
888 },
889 {
890 YAML: `a: {x: 1}
891 `,
892 Tokens: token.Tokens{
893 {
894 Type: token.StringType,
895 CharacterType: token.CharacterTypeMiscellaneous,
896 Indicator: token.NotIndicator,
897 Value: "a",
898 Origin: "a",
899 },
900 {
901 Type: token.MappingValueType,
902 CharacterType: token.CharacterTypeIndicator,
903 Indicator: token.BlockStructureIndicator,
904 Value: ":",
905 Origin: ":",
906 },
907 {
908 Type: token.MappingStartType,
909 CharacterType: token.CharacterTypeIndicator,
910 Indicator: token.FlowCollectionIndicator,
911 Value: "{",
912 Origin: " {",
913 },
914 {
915 Type: token.StringType,
916 CharacterType: token.CharacterTypeMiscellaneous,
917 Indicator: token.NotIndicator,
918 Value: "x",
919 Origin: "x",
920 },
921 {
922 Type: token.MappingValueType,
923 CharacterType: token.CharacterTypeIndicator,
924 Indicator: token.BlockStructureIndicator,
925 Value: ":",
926 Origin: ":",
927 },
928 {
929 Type: token.IntegerType,
930 CharacterType: token.CharacterTypeMiscellaneous,
931 Indicator: token.NotIndicator,
932 Value: "1",
933 Origin: " 1",
934 },
935 {
936 Type: token.MappingEndType,
937 CharacterType: token.CharacterTypeIndicator,
938 Indicator: token.FlowCollectionIndicator,
939 Value: "}",
940 Origin: "}",
941 },
942 },
943 },
944 {
945 YAML: `a: [1, 2]
946 `,
947 Tokens: token.Tokens{
948 {
949 Type: token.StringType,
950 CharacterType: token.CharacterTypeMiscellaneous,
951 Indicator: token.NotIndicator,
952 Value: "a",
953 Origin: "a",
954 },
955 {
956 Type: token.MappingValueType,
957 CharacterType: token.CharacterTypeIndicator,
958 Indicator: token.BlockStructureIndicator,
959 Value: ":",
960 Origin: ":",
961 },
962 {
963 Type: token.SequenceStartType,
964 CharacterType: token.CharacterTypeIndicator,
965 Indicator: token.FlowCollectionIndicator,
966 Value: "[",
967 Origin: " [",
968 },
969 {
970 Type: token.IntegerType,
971 CharacterType: token.CharacterTypeMiscellaneous,
972 Indicator: token.NotIndicator,
973 Value: "1",
974 Origin: "1",
975 },
976 {
977 Type: token.CollectEntryType,
978 CharacterType: token.CharacterTypeIndicator,
979 Indicator: token.FlowCollectionIndicator,
980 Value: ",",
981 Origin: ",",
982 },
983 {
984 Type: token.IntegerType,
985 CharacterType: token.CharacterTypeMiscellaneous,
986 Indicator: token.NotIndicator,
987 Value: "2",
988 Origin: " 2",
989 },
990 {
991 Type: token.SequenceEndType,
992 CharacterType: token.CharacterTypeIndicator,
993 Indicator: token.FlowCollectionIndicator,
994 Value: "]",
995 Origin: "]",
996 },
997 },
998 },
999 {
1000 YAML: `t2: 2018-01-09T10:40:47Z
1001 t4: 2098-01-09T10:40:47Z
1002 `,
1003 Tokens: token.Tokens{
1004 {
1005 Type: token.StringType,
1006 CharacterType: token.CharacterTypeMiscellaneous,
1007 Indicator: token.NotIndicator,
1008 Value: "t2",
1009 Origin: "t2",
1010 },
1011 {
1012 Type: token.MappingValueType,
1013 CharacterType: token.CharacterTypeIndicator,
1014 Indicator: token.BlockStructureIndicator,
1015 Value: ":",
1016 Origin: ":",
1017 },
1018 {
1019 Type: token.StringType,
1020 CharacterType: token.CharacterTypeMiscellaneous,
1021 Indicator: token.NotIndicator,
1022 Value: "2018-01-09T10:40:47Z",
1023 Origin: " 2018-01-09T10:40:47Z\n",
1024 },
1025 {
1026 Type: token.StringType,
1027 CharacterType: token.CharacterTypeMiscellaneous,
1028 Indicator: token.NotIndicator,
1029 Value: "\t\tt4",
1030 Origin: "\t\tt4",
1031 },
1032 {
1033 Type: token.MappingValueType,
1034 CharacterType: token.CharacterTypeIndicator,
1035 Indicator: token.BlockStructureIndicator,
1036 Value: ":",
1037 Origin: ":",
1038 },
1039 {
1040 Type: token.StringType,
1041 CharacterType: token.CharacterTypeMiscellaneous,
1042 Indicator: token.NotIndicator,
1043 Value: "2098-01-09T10:40:47Z",
1044 Origin: " 2098-01-09T10:40:47Z\n",
1045 },
1046 },
1047 },
1048 {
1049 YAML: `a: {b: c, d: e}
1050 `,
1051 Tokens: token.Tokens{
1052 {
1053 Type: token.StringType,
1054 CharacterType: token.CharacterTypeMiscellaneous,
1055 Indicator: token.NotIndicator,
1056 Value: "a",
1057 Origin: "a",
1058 },
1059 {
1060 Type: token.MappingValueType,
1061 CharacterType: token.CharacterTypeIndicator,
1062 Indicator: token.BlockStructureIndicator,
1063 Value: ":",
1064 Origin: ":",
1065 },
1066 {
1067 Type: token.MappingStartType,
1068 CharacterType: token.CharacterTypeIndicator,
1069 Indicator: token.FlowCollectionIndicator,
1070 Value: "{",
1071 Origin: " {",
1072 },
1073 {
1074 Type: token.StringType,
1075 CharacterType: token.CharacterTypeMiscellaneous,
1076 Indicator: token.NotIndicator,
1077 Value: "b",
1078 Origin: "b",
1079 },
1080 {
1081 Type: token.MappingValueType,
1082 CharacterType: token.CharacterTypeIndicator,
1083 Indicator: token.BlockStructureIndicator,
1084 Value: ":",
1085 Origin: ":",
1086 },
1087 {
1088 Type: token.StringType,
1089 CharacterType: token.CharacterTypeMiscellaneous,
1090 Indicator: token.NotIndicator,
1091 Value: "c",
1092 Origin: " c",
1093 },
1094 {
1095 Type: token.CollectEntryType,
1096 CharacterType: token.CharacterTypeIndicator,
1097 Indicator: token.FlowCollectionIndicator,
1098 Value: ",",
1099 Origin: ",",
1100 },
1101 {
1102 Type: token.StringType,
1103 CharacterType: token.CharacterTypeMiscellaneous,
1104 Indicator: token.NotIndicator,
1105 Value: "d",
1106 Origin: " d",
1107 },
1108 {
1109 Type: token.MappingValueType,
1110 CharacterType: token.CharacterTypeIndicator,
1111 Indicator: token.BlockStructureIndicator,
1112 Value: ":",
1113 Origin: ":",
1114 },
1115 {
1116 Type: token.StringType,
1117 CharacterType: token.CharacterTypeMiscellaneous,
1118 Indicator: token.NotIndicator,
1119 Value: "e",
1120 Origin: " e",
1121 },
1122 {
1123 Type: token.MappingEndType,
1124 CharacterType: token.CharacterTypeIndicator,
1125 Indicator: token.FlowCollectionIndicator,
1126 Value: "}",
1127 Origin: "}",
1128 },
1129 },
1130 },
1131 {
1132 YAML: `a: 3s
1133 `,
1134 Tokens: token.Tokens{
1135 {
1136 Type: token.StringType,
1137 CharacterType: token.CharacterTypeMiscellaneous,
1138 Indicator: token.NotIndicator,
1139 Value: "a",
1140 Origin: "a",
1141 },
1142 {
1143 Type: token.MappingValueType,
1144 CharacterType: token.CharacterTypeIndicator,
1145 Indicator: token.BlockStructureIndicator,
1146 Value: ":",
1147 Origin: ":",
1148 },
1149 {
1150 Type: token.StringType,
1151 CharacterType: token.CharacterTypeMiscellaneous,
1152 Indicator: token.NotIndicator,
1153 Value: "3s",
1154 Origin: " 3s\n",
1155 },
1156 },
1157 },
1158 {
1159 YAML: `a: <foo>
1160 `,
1161 Tokens: token.Tokens{
1162 {
1163 Type: token.StringType,
1164 CharacterType: token.CharacterTypeMiscellaneous,
1165 Indicator: token.NotIndicator,
1166 Value: "a",
1167 Origin: "a",
1168 },
1169 {
1170 Type: token.MappingValueType,
1171 CharacterType: token.CharacterTypeIndicator,
1172 Indicator: token.BlockStructureIndicator,
1173 Value: ":",
1174 Origin: ":",
1175 },
1176 {
1177 Type: token.StringType,
1178 CharacterType: token.CharacterTypeMiscellaneous,
1179 Indicator: token.NotIndicator,
1180 Value: "<foo>",
1181 Origin: " <foo>\n",
1182 },
1183 },
1184 },
1185 {
1186 YAML: `a: "1:1"
1187 `,
1188 Tokens: token.Tokens{
1189 {
1190 Type: token.StringType,
1191 CharacterType: token.CharacterTypeMiscellaneous,
1192 Indicator: token.NotIndicator,
1193 Value: "a",
1194 Origin: "a",
1195 },
1196 {
1197 Type: token.MappingValueType,
1198 CharacterType: token.CharacterTypeIndicator,
1199 Indicator: token.BlockStructureIndicator,
1200 Value: ":",
1201 Origin: ":",
1202 },
1203 {
1204 Type: token.DoubleQuoteType,
1205 CharacterType: token.CharacterTypeIndicator,
1206 Indicator: token.QuotedScalarIndicator,
1207 Value: "1:1",
1208 Origin: " \"1:1\"",
1209 },
1210 },
1211 },
1212 {
1213 YAML: `a: "\0"
1214 `,
1215 Tokens: token.Tokens{
1216 {
1217 Type: token.StringType,
1218 CharacterType: token.CharacterTypeMiscellaneous,
1219 Indicator: token.NotIndicator,
1220 Value: "a",
1221 Origin: "a",
1222 },
1223 {
1224 Type: token.MappingValueType,
1225 CharacterType: token.CharacterTypeIndicator,
1226 Indicator: token.BlockStructureIndicator,
1227 Value: ":",
1228 Origin: ":",
1229 },
1230 {
1231 Type: token.DoubleQuoteType,
1232 CharacterType: token.CharacterTypeIndicator,
1233 Indicator: token.QuotedScalarIndicator,
1234 Value: "\\0",
1235 Origin: " \"\\0\"",
1236 },
1237 },
1238 },
1239 {
1240 YAML: `a: !!binary gIGC
1241 `,
1242 Tokens: token.Tokens{
1243 {
1244 Type: token.StringType,
1245 CharacterType: token.CharacterTypeMiscellaneous,
1246 Indicator: token.NotIndicator,
1247 Value: "a",
1248 Origin: "a",
1249 },
1250 {
1251 Type: token.MappingValueType,
1252 CharacterType: token.CharacterTypeIndicator,
1253 Indicator: token.BlockStructureIndicator,
1254 Value: ":",
1255 Origin: ":",
1256 },
1257 {
1258 Type: token.TagType,
1259 CharacterType: token.CharacterTypeIndicator,
1260 Indicator: token.NodePropertyIndicator,
1261 Value: "!!binary",
1262 Origin: " !!binary ",
1263 },
1264 {
1265 Type: token.StringType,
1266 CharacterType: token.CharacterTypeMiscellaneous,
1267 Indicator: token.NotIndicator,
1268 Value: "gIGC",
1269 Origin: "gIGC\n",
1270 },
1271 },
1272 },
1273 {
1274 YAML: `a: !!binary |
1275 kJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJ
1276 CQ
1277 `,
1278 Tokens: token.Tokens{
1279 {
1280 Type: token.StringType,
1281 CharacterType: token.CharacterTypeMiscellaneous,
1282 Indicator: token.NotIndicator,
1283 Value: "a",
1284 Origin: "a",
1285 },
1286 {
1287 Type: token.MappingValueType,
1288 CharacterType: token.CharacterTypeIndicator,
1289 Indicator: token.BlockStructureIndicator,
1290 Value: ":",
1291 Origin: ":",
1292 },
1293 {
1294 Type: token.TagType,
1295 CharacterType: token.CharacterTypeIndicator,
1296 Indicator: token.NodePropertyIndicator,
1297 Value: "!!binary",
1298 Origin: " !!binary ",
1299 },
1300 {
1301 Type: token.LiteralType,
1302 CharacterType: token.CharacterTypeIndicator,
1303 Indicator: token.BlockScalarIndicator,
1304 Value: "|",
1305 Origin: "|\n",
1306 },
1307 {
1308 Type: token.StringType,
1309 CharacterType: token.CharacterTypeMiscellaneous,
1310 Indicator: token.NotIndicator,
1311 Value: "\t\t kJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJ",
1312 Origin: "\t\t kJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJ\n",
1313 },
1314 {
1315 Type: token.StringType,
1316 CharacterType: token.CharacterTypeMiscellaneous,
1317 Indicator: token.NotIndicator,
1318 Value: "\t\t CQ",
1319 Origin: "\t\t CQ\n",
1320 },
1321 },
1322 },
1323 {
1324 YAML: `b: 2
1325 a: 1
1326 d: 4
1327 c: 3
1328 sub:
1329 e: 5
1330 `,
1331 Tokens: token.Tokens{
1332 {
1333 Type: token.StringType,
1334 CharacterType: token.CharacterTypeMiscellaneous,
1335 Indicator: token.NotIndicator,
1336 Value: "b",
1337 Origin: "b",
1338 },
1339 {
1340 Type: token.MappingValueType,
1341 CharacterType: token.CharacterTypeIndicator,
1342 Indicator: token.BlockStructureIndicator,
1343 Value: ":",
1344 Origin: ":",
1345 },
1346 {
1347 Type: token.IntegerType,
1348 CharacterType: token.CharacterTypeMiscellaneous,
1349 Indicator: token.NotIndicator,
1350 Value: "2",
1351 Origin: " 2\n",
1352 },
1353 {
1354 Type: token.StringType,
1355 CharacterType: token.CharacterTypeMiscellaneous,
1356 Indicator: token.NotIndicator,
1357 Value: "\t\ta",
1358 Origin: "\t\ta",
1359 },
1360 {
1361 Type: token.MappingValueType,
1362 CharacterType: token.CharacterTypeIndicator,
1363 Indicator: token.BlockStructureIndicator,
1364 Value: ":",
1365 Origin: ":",
1366 },
1367 {
1368 Type: token.IntegerType,
1369 CharacterType: token.CharacterTypeMiscellaneous,
1370 Indicator: token.NotIndicator,
1371 Value: "1",
1372 Origin: " 1\n",
1373 },
1374 {
1375 Type: token.StringType,
1376 CharacterType: token.CharacterTypeMiscellaneous,
1377 Indicator: token.NotIndicator,
1378 Value: "\t\td",
1379 Origin: "\t\td",
1380 },
1381 {
1382 Type: token.MappingValueType,
1383 CharacterType: token.CharacterTypeIndicator,
1384 Indicator: token.BlockStructureIndicator,
1385 Value: ":",
1386 Origin: ":",
1387 },
1388 {
1389 Type: token.IntegerType,
1390 CharacterType: token.CharacterTypeMiscellaneous,
1391 Indicator: token.NotIndicator,
1392 Value: "4",
1393 Origin: " 4\n",
1394 },
1395 {
1396 Type: token.StringType,
1397 CharacterType: token.CharacterTypeMiscellaneous,
1398 Indicator: token.NotIndicator,
1399 Value: "\t\tc",
1400 Origin: "\t\tc",
1401 },
1402 {
1403 Type: token.MappingValueType,
1404 CharacterType: token.CharacterTypeIndicator,
1405 Indicator: token.BlockStructureIndicator,
1406 Value: ":",
1407 Origin: ":",
1408 },
1409 {
1410 Type: token.IntegerType,
1411 CharacterType: token.CharacterTypeMiscellaneous,
1412 Indicator: token.NotIndicator,
1413 Value: "3",
1414 Origin: " 3\n",
1415 },
1416 {
1417 Type: token.StringType,
1418 CharacterType: token.CharacterTypeMiscellaneous,
1419 Indicator: token.NotIndicator,
1420 Value: "\t\tsub",
1421 Origin: "\t\tsub",
1422 },
1423 {
1424 Type: token.MappingValueType,
1425 CharacterType: token.CharacterTypeIndicator,
1426 Indicator: token.BlockStructureIndicator,
1427 Value: ":",
1428 Origin: ":",
1429 },
1430 {
1431 Type: token.StringType,
1432 CharacterType: token.CharacterTypeMiscellaneous,
1433 Indicator: token.NotIndicator,
1434 Value: "\t\t e",
1435 Origin: "\n\t\t e",
1436 },
1437 {
1438 Type: token.MappingValueType,
1439 CharacterType: token.CharacterTypeIndicator,
1440 Indicator: token.BlockStructureIndicator,
1441 Value: ":",
1442 Origin: ":",
1443 },
1444 {
1445 Type: token.IntegerType,
1446 CharacterType: token.CharacterTypeMiscellaneous,
1447 Indicator: token.NotIndicator,
1448 Value: "5",
1449 Origin: " 5\n",
1450 },
1451 },
1452 },
1453 {
1454 YAML: `a: 1.2.3.4
1455 `,
1456 Tokens: token.Tokens{
1457 {
1458 Type: token.StringType,
1459 CharacterType: token.CharacterTypeMiscellaneous,
1460 Indicator: token.NotIndicator,
1461 Value: "a",
1462 Origin: "a",
1463 },
1464 {
1465 Type: token.MappingValueType,
1466 CharacterType: token.CharacterTypeIndicator,
1467 Indicator: token.BlockStructureIndicator,
1468 Value: ":",
1469 Origin: ":",
1470 },
1471 {
1472 Type: token.StringType,
1473 CharacterType: token.CharacterTypeMiscellaneous,
1474 Indicator: token.NotIndicator,
1475 Value: "1.2.3.4",
1476 Origin: " 1.2.3.4\n",
1477 },
1478 },
1479 },
1480 {
1481 YAML: `a: "2015-02-24T18:19:39Z"
1482 `,
1483 Tokens: token.Tokens{
1484 {
1485 Type: token.StringType,
1486 CharacterType: token.CharacterTypeMiscellaneous,
1487 Indicator: token.NotIndicator,
1488 Value: "a",
1489 Origin: "a",
1490 },
1491 {
1492 Type: token.MappingValueType,
1493 CharacterType: token.CharacterTypeIndicator,
1494 Indicator: token.BlockStructureIndicator,
1495 Value: ":",
1496 Origin: ":",
1497 },
1498 {
1499 Type: token.DoubleQuoteType,
1500 CharacterType: token.CharacterTypeIndicator,
1501 Indicator: token.QuotedScalarIndicator,
1502 Value: "2015-02-24T18:19:39Z",
1503 Origin: " \"2015-02-24T18:19:39Z\"",
1504 },
1505 },
1506 },
1507 {
1508 YAML: `a: 'b: c'
1509 `,
1510 Tokens: token.Tokens{
1511 {
1512 Type: token.StringType,
1513 CharacterType: token.CharacterTypeMiscellaneous,
1514 Indicator: token.NotIndicator,
1515 Value: "a",
1516 Origin: "a",
1517 },
1518 {
1519 Type: token.MappingValueType,
1520 CharacterType: token.CharacterTypeIndicator,
1521 Indicator: token.BlockStructureIndicator,
1522 Value: ":",
1523 Origin: ":",
1524 },
1525 {
1526 Type: token.SingleQuoteType,
1527 CharacterType: token.CharacterTypeIndicator,
1528 Indicator: token.QuotedScalarIndicator,
1529 Value: "b: c",
1530 Origin: " 'b: c'",
1531 },
1532 },
1533 },
1534 {
1535 YAML: `a: 'Hello #comment'
1536 `,
1537 Tokens: token.Tokens{
1538 {
1539 Type: token.StringType,
1540 CharacterType: token.CharacterTypeMiscellaneous,
1541 Indicator: token.NotIndicator,
1542 Value: "a",
1543 Origin: "a",
1544 },
1545 {
1546 Type: token.MappingValueType,
1547 CharacterType: token.CharacterTypeIndicator,
1548 Indicator: token.BlockStructureIndicator,
1549 Value: ":",
1550 Origin: ":",
1551 },
1552 {
1553 Type: token.SingleQuoteType,
1554 CharacterType: token.CharacterTypeIndicator,
1555 Indicator: token.QuotedScalarIndicator,
1556 Value: "Hello #comment",
1557 Origin: " 'Hello #comment'",
1558 },
1559 },
1560 },
1561 {
1562 YAML: `a: 100.5
1563 `,
1564 Tokens: token.Tokens{
1565 {
1566 Type: token.StringType,
1567 CharacterType: token.CharacterTypeMiscellaneous,
1568 Indicator: token.NotIndicator,
1569 Value: "a",
1570 Origin: "a",
1571 },
1572 {
1573 Type: token.MappingValueType,
1574 CharacterType: token.CharacterTypeIndicator,
1575 Indicator: token.BlockStructureIndicator,
1576 Value: ":",
1577 Origin: ":",
1578 },
1579 {
1580 Type: token.FloatType,
1581 CharacterType: token.CharacterTypeMiscellaneous,
1582 Indicator: token.NotIndicator,
1583 Value: "100.5",
1584 Origin: " 100.5\n",
1585 },
1586 },
1587 },
1588 {
1589 YAML: `a: bogus
1590 `,
1591 Tokens: token.Tokens{
1592 {
1593 Type: token.StringType,
1594 CharacterType: token.CharacterTypeMiscellaneous,
1595 Indicator: token.NotIndicator,
1596 Value: "a",
1597 Origin: "a",
1598 },
1599 {
1600 Type: token.MappingValueType,
1601 CharacterType: token.CharacterTypeIndicator,
1602 Indicator: token.BlockStructureIndicator,
1603 Value: ":",
1604 Origin: ":",
1605 },
1606 {
1607 Type: token.StringType,
1608 CharacterType: token.CharacterTypeMiscellaneous,
1609 Indicator: token.NotIndicator,
1610 Value: "bogus",
1611 Origin: " bogus\n",
1612 },
1613 },
1614 },
1615 {
1616 YAML: `"a": double quoted map key`,
1617 Tokens: token.Tokens{
1618 {
1619 Type: token.DoubleQuoteType,
1620 CharacterType: token.CharacterTypeIndicator,
1621 Indicator: token.QuotedScalarIndicator,
1622 Value: "a",
1623 Origin: "\"a\"",
1624 },
1625 {
1626 Type: token.MappingValueType,
1627 CharacterType: token.CharacterTypeIndicator,
1628 Indicator: token.BlockStructureIndicator,
1629 Value: ":",
1630 Origin: ":",
1631 },
1632 {
1633 Type: token.StringType,
1634 CharacterType: token.CharacterTypeMiscellaneous,
1635 Indicator: token.NotIndicator,
1636 Value: "double quoted map key",
1637 Origin: " double quoted map key",
1638 },
1639 },
1640 },
1641 {
1642 YAML: `'a': single quoted map key`,
1643 Tokens: token.Tokens{
1644 {
1645 Type: token.SingleQuoteType,
1646 CharacterType: token.CharacterTypeIndicator,
1647 Indicator: token.QuotedScalarIndicator,
1648 Value: "a",
1649 Origin: "'a'",
1650 },
1651 {
1652 Type: token.MappingValueType,
1653 CharacterType: token.CharacterTypeIndicator,
1654 Indicator: token.BlockStructureIndicator,
1655 Value: ":",
1656 Origin: ":",
1657 },
1658 {
1659 Type: token.StringType,
1660 CharacterType: token.CharacterTypeMiscellaneous,
1661 Indicator: token.NotIndicator,
1662 Value: "single quoted map key",
1663 Origin: " single quoted map key",
1664 },
1665 },
1666 },
1667 {
1668 YAML: `a: "double quoted"
1669 b: "value map"`,
1670 Tokens: token.Tokens{
1671 {
1672 Type: token.StringType,
1673 CharacterType: token.CharacterTypeMiscellaneous,
1674 Indicator: token.NotIndicator,
1675 Value: "a",
1676 Origin: "a",
1677 },
1678 {
1679 Type: token.MappingValueType,
1680 CharacterType: token.CharacterTypeIndicator,
1681 Indicator: token.BlockStructureIndicator,
1682 Value: ":",
1683 Origin: ":",
1684 },
1685 {
1686 Type: token.DoubleQuoteType,
1687 CharacterType: token.CharacterTypeIndicator,
1688 Indicator: token.QuotedScalarIndicator,
1689 Value: "double quoted",
1690 Origin: " \"double quoted\"",
1691 },
1692 {
1693 Type: token.StringType,
1694 CharacterType: token.CharacterTypeMiscellaneous,
1695 Indicator: token.NotIndicator,
1696 Value: "\t\tb",
1697 Origin: "\n\t\tb",
1698 },
1699 {
1700 Type: token.MappingValueType,
1701 CharacterType: token.CharacterTypeIndicator,
1702 Indicator: token.BlockStructureIndicator,
1703 Value: ":",
1704 Origin: ":",
1705 },
1706 {
1707 Type: token.DoubleQuoteType,
1708 CharacterType: token.CharacterTypeIndicator,
1709 Indicator: token.QuotedScalarIndicator,
1710 Value: "value map",
1711 Origin: " \"value map\"",
1712 },
1713 },
1714 },
1715 {
1716 YAML: `a: 'single quoted'
1717 b: 'value map'`,
1718 Tokens: token.Tokens{
1719 {
1720 Type: token.StringType,
1721 CharacterType: token.CharacterTypeMiscellaneous,
1722 Indicator: token.NotIndicator,
1723 Value: "a",
1724 Origin: "a",
1725 },
1726 {
1727 Type: token.MappingValueType,
1728 CharacterType: token.CharacterTypeIndicator,
1729 Indicator: token.BlockStructureIndicator,
1730 Value: ":",
1731 Origin: ":",
1732 },
1733 {
1734 Type: token.SingleQuoteType,
1735 CharacterType: token.CharacterTypeIndicator,
1736 Indicator: token.QuotedScalarIndicator,
1737 Value: "single quoted",
1738 Origin: " 'single quoted'",
1739 },
1740 {
1741 Type: token.StringType,
1742 CharacterType: token.CharacterTypeMiscellaneous,
1743 Indicator: token.NotIndicator,
1744 Value: "\t\tb",
1745 Origin: "\n\t\tb",
1746 },
1747 {
1748 Type: token.MappingValueType,
1749 CharacterType: token.CharacterTypeIndicator,
1750 Indicator: token.BlockStructureIndicator,
1751 Value: ":",
1752 Origin: ":",
1753 },
1754 {
1755 Type: token.SingleQuoteType,
1756 CharacterType: token.CharacterTypeIndicator,
1757 Indicator: token.QuotedScalarIndicator,
1758 Value: "value map",
1759 Origin: " 'value map'",
1760 },
1761 },
1762 },
1763 {
1764 YAML: `json: '\"expression\": \"thi:\"'`,
1765 Tokens: token.Tokens{
1766 {
1767 Type: token.StringType,
1768 CharacterType: token.CharacterTypeMiscellaneous,
1769 Indicator: token.NotIndicator,
1770 Value: "json",
1771 Origin: "json",
1772 },
1773 {
1774 Type: token.MappingValueType,
1775 CharacterType: token.CharacterTypeIndicator,
1776 Indicator: token.BlockStructureIndicator,
1777 Value: ":",
1778 Origin: ":",
1779 },
1780 {
1781 Type: token.SingleQuoteType,
1782 CharacterType: token.CharacterTypeIndicator,
1783 Indicator: token.QuotedScalarIndicator,
1784 Value: "\\\"expression\\\": \\\"thi:\\\"",
1785 Origin: " '\\\"expression\\\": \\\"thi:\\\"'",
1786 },
1787 },
1788 },
1789 {
1790 YAML: `json: "\"expression\": \"thi:\""`,
1791 Tokens: token.Tokens{
1792 {
1793 Type: token.StringType,
1794 CharacterType: token.CharacterTypeMiscellaneous,
1795 Indicator: token.NotIndicator,
1796 Value: "json",
1797 Origin: "json",
1798 },
1799 {
1800 Type: token.MappingValueType,
1801 CharacterType: token.CharacterTypeIndicator,
1802 Indicator: token.BlockStructureIndicator,
1803 Value: ":",
1804 Origin: ":",
1805 },
1806 {
1807 Type: token.DoubleQuoteType,
1808 CharacterType: token.CharacterTypeIndicator,
1809 Indicator: token.QuotedScalarIndicator,
1810 Value: "\"expression\": \"thi:\"",
1811 Origin: " \"\\\"expression\\\": \\\"thi:\\\"\"",
1812 },
1813 },
1814 },
1815 }
1816 for _, test := range tests {
1817 t.Run(test.YAML, func(t *testing.T) {
1818 tokens := lexer.Tokenize(test.YAML)
1819 if len(tokens) != len(test.Tokens) {
1820 t.Fatalf("Tokenize(%q) token count mismatch, expected: %d got: %d", test.YAML, len(test.Tokens), len(tokens))
1821 }
1822 for i := range test.Tokens {
1823 if tokens[i].Type != test.Tokens[i].Type {
1824 t.Errorf("Tokenize(%q)[%d] token.Type mismatch, expected: %s got: %s", test.YAML, i, test.Tokens[i].Type, tokens[i].Type)
1825 }
1826 if tokens[i].CharacterType != test.Tokens[i].CharacterType {
1827 t.Errorf("Tokenize(%q)[%d] token.CharacterType mismatch, expected: %s got: %s", test.YAML, i, test.Tokens[i].CharacterType, tokens[i].CharacterType)
1828 }
1829 if tokens[i].Indicator != test.Tokens[i].Indicator {
1830 t.Errorf("Tokenize(%q)[%d] token.Indicator mismatch, expected: %s got: %s", test.YAML, i, test.Tokens[i].Indicator, tokens[i].Indicator)
1831 }
1832 if tokens[i].Value != test.Tokens[i].Value {
1833 t.Errorf("Tokenize(%q)[%d] token.Value mismatch, expected: %q got: %q", test.YAML, i, test.Tokens[i].Value, tokens[i].Value)
1834 }
1835 if tokens[i].Origin != test.Tokens[i].Origin {
1836 t.Errorf("Tokenize(%q)[%d] token.Origin mismatch, expected: %q got: %q", test.YAML, i, test.Tokens[i].Origin, tokens[i].Origin)
1837 }
1838 }
1839 })
1840 }
1841 }
1842
1843 type testToken struct {
1844 line int
1845 column int
1846 value string
1847 }
1848
1849 func TestSingleLineToken_ValueLineColumnPosition(t *testing.T) {
1850 tests := []struct {
1851 name string
1852 src string
1853 expect map[int]string // Column -> Value map.
1854 }{
1855 {
1856 name: "single quote, single value array",
1857 src: "test: ['test']",
1858 expect: map[int]string{
1859 1: "test",
1860 5: ":",
1861 7: "[",
1862 8: "test",
1863 14: "]",
1864 },
1865 },
1866 {
1867 name: "double quote, single value array",
1868 src: `test: ["test"]`,
1869 expect: map[int]string{
1870 1: "test",
1871 5: ":",
1872 7: "[",
1873 8: "test",
1874 14: "]",
1875 },
1876 },
1877 {
1878 name: "no quotes, single value array",
1879 src: "test: [somevalue]",
1880 expect: map[int]string{
1881 1: "test",
1882 5: ":",
1883 7: "[",
1884 8: "somevalue",
1885 17: "]",
1886 },
1887 },
1888 {
1889 name: "single quote, multi value array",
1890 src: "myarr: ['1','2','3', '444' , '55','66' , '77' ]",
1891 expect: map[int]string{
1892 1: "myarr",
1893 6: ":",
1894 8: "[",
1895 9: "1",
1896 12: ",",
1897 13: "2",
1898 16: ",",
1899 17: "3",
1900 20: ",",
1901 22: "444",
1902 28: ",",
1903 30: "55",
1904 34: ",",
1905 35: "66",
1906 40: ",",
1907 43: "77",
1908 49: "]",
1909 },
1910 },
1911 {
1912 name: "double quote, multi value array",
1913 src: `myarr: ["1","2","3", "444" , "55","66" , "77" ]`,
1914 expect: map[int]string{
1915 1: "myarr",
1916 6: ":",
1917 8: "[",
1918 9: "1",
1919 12: ",",
1920 13: "2",
1921 16: ",",
1922 17: "3",
1923 20: ",",
1924 22: "444",
1925 28: ",",
1926 30: "55",
1927 34: ",",
1928 35: "66",
1929 40: ",",
1930 43: "77",
1931 49: "]",
1932 },
1933 },
1934 {
1935 name: "no quote, multi value array",
1936 src: "numbers: [1, 5, 99,100, 3, 7 ]",
1937 expect: map[int]string{
1938 1: "numbers",
1939 8: ":",
1940 10: "[",
1941 11: "1",
1942 12: ",",
1943 14: "5",
1944 15: ",",
1945 17: "99",
1946 19: ",",
1947 20: "100",
1948 23: ",",
1949 25: "3",
1950 26: ",",
1951 28: "7",
1952 30: "]",
1953 },
1954 },
1955 {
1956 name: "double quotes, nested arrays",
1957 src: `Strings: ["1",["2",["3"]]]`,
1958 expect: map[int]string{
1959 1: "Strings",
1960 8: ":",
1961 10: "[",
1962 11: "1",
1963 14: ",",
1964 15: "[",
1965 16: "2",
1966 19: ",",
1967 20: "[",
1968 21: "3",
1969 24: "]",
1970 25: "]",
1971 26: "]",
1972 },
1973 },
1974 {
1975 name: "mixed quotes, nested arrays",
1976 src: `Values: [1,['2',"3",4,["5",6]]]`,
1977 expect: map[int]string{
1978 1: "Values",
1979 7: ":",
1980 9: "[",
1981 10: "1",
1982 11: ",",
1983 12: "[",
1984 13: "2",
1985 16: ",",
1986 17: "3",
1987 20: ",",
1988 21: "4",
1989 22: ",",
1990 23: "[",
1991 24: "5",
1992 27: ",",
1993 28: "6",
1994 29: "]",
1995 30: "]",
1996 31: "]",
1997 },
1998 },
1999 {
2000 name: "double quote, empty array",
2001 src: `Empty: ["", ""]`,
2002 expect: map[int]string{
2003 1: "Empty",
2004 6: ":",
2005 8: "[",
2006 9: "",
2007 11: ",",
2008 13: "",
2009 15: "]",
2010 },
2011 },
2012 {
2013 name: "double quote key",
2014 src: `"a": b`,
2015 expect: map[int]string{
2016 1: "a",
2017 4: ":",
2018 6: "b",
2019 },
2020 },
2021 {
2022 name: "single quote key",
2023 src: `'a': b`,
2024 expect: map[int]string{
2025 1: "a",
2026 4: ":",
2027 6: "b",
2028 },
2029 },
2030 {
2031 name: "double quote key and value",
2032 src: `"a": "b"`,
2033 expect: map[int]string{
2034 1: "a",
2035 4: ":",
2036 6: "b",
2037 },
2038 },
2039 {
2040 name: "single quote key and value",
2041 src: `'a': 'b'`,
2042 expect: map[int]string{
2043 1: "a",
2044 4: ":",
2045 6: "b",
2046 },
2047 },
2048 {
2049 name: "double quote key, single quote value",
2050 src: `"a": 'b'`,
2051 expect: map[int]string{
2052 1: "a",
2053 4: ":",
2054 6: "b",
2055 },
2056 },
2057 {
2058 name: "single quote key, double quote value",
2059 src: `'a': "b"`,
2060 expect: map[int]string{
2061 1: "a",
2062 4: ":",
2063 6: "b",
2064 },
2065 },
2066 }
2067
2068 for _, tc := range tests {
2069 t.Run(tc.name, func(t *testing.T) {
2070 got := lexer.Tokenize(tc.src)
2071 sort.Slice(got, func(i, j int) bool {
2072 return got[i].Position.Column < got[j].Position.Column
2073 })
2074 var expected []testToken
2075 for k, v := range tc.expect {
2076 tt := testToken{
2077 line: 1,
2078 column: k,
2079 value: v,
2080 }
2081 expected = append(expected, tt)
2082 }
2083 sort.Slice(expected, func(i, j int) bool {
2084 return expected[i].column < expected[j].column
2085 })
2086 if len(got) != len(expected) {
2087 t.Errorf("Tokenize(%s) token count mismatch, expected:%d got:%d", tc.src, len(expected), len(got))
2088 }
2089 for i, tok := range got {
2090 if !tokenMatches(tok, expected[i]) {
2091 t.Errorf("Tokenize(%s) expected:%+v got line:%d column:%d value:%s", tc.src, expected[i], tok.Position.Line, tok.Position.Column, tok.Value)
2092 }
2093 }
2094 })
2095 }
2096 }
2097
2098 func tokenMatches(t *token.Token, e testToken) bool {
2099 return t != nil && t.Position != nil &&
2100 t.Value == e.value &&
2101 t.Position.Line == e.line &&
2102 t.Position.Column == e.column
2103 }
2104
2105 func TestMultiLineToken_ValueLineColumnPosition(t *testing.T) {
2106 tests := []struct {
2107 name string
2108 src string
2109 expect []testToken
2110 }{
2111 {
2112 name: "double quote",
2113 src: `one: "1 2 3 4 5"
2114 two: "1 2
2115 3 4
2116 5"
2117 three: "1 2 3 4
2118 5"`,
2119 expect: []testToken{
2120 {
2121 line: 1,
2122 column: 1,
2123 value: "one",
2124 },
2125 {
2126 line: 1,
2127 column: 4,
2128 value: ":",
2129 },
2130 {
2131 line: 1,
2132 column: 6,
2133 value: "1 2 3 4 5",
2134 },
2135 {
2136 line: 2,
2137 column: 1,
2138 value: "two",
2139 },
2140 {
2141 line: 2,
2142 column: 4,
2143 value: ":",
2144 },
2145 {
2146 line: 2,
2147 column: 6,
2148 value: "1 2 3 4 5",
2149 },
2150 {
2151 line: 5,
2152 column: 1,
2153 value: "three",
2154 },
2155 {
2156 line: 5,
2157 column: 6,
2158 value: ":",
2159 },
2160 {
2161 line: 5,
2162 column: 8,
2163 value: "1 2 3 4 5",
2164 },
2165 },
2166 },
2167 {
2168 name: "single quote in an array",
2169 src: `arr: ['1', 'and
2170 two']
2171 last: 'hello'`,
2172 expect: []testToken{
2173 {
2174 line: 1,
2175 column: 1,
2176 value: "arr",
2177 },
2178 {
2179 line: 1,
2180 column: 4,
2181 value: ":",
2182 },
2183 {
2184 line: 1,
2185 column: 6,
2186 value: "[",
2187 },
2188 {
2189 line: 1,
2190 column: 7,
2191 value: "1",
2192 },
2193 {
2194 line: 1,
2195 column: 10,
2196 value: ",",
2197 },
2198 {
2199 line: 1,
2200 column: 12,
2201 value: "and two",
2202 },
2203 {
2204 line: 2,
2205 column: 5,
2206 value: "]",
2207 },
2208 {
2209 line: 3,
2210 column: 1,
2211 value: "last",
2212 },
2213 {
2214 line: 3,
2215 column: 5,
2216 value: ":",
2217 },
2218 {
2219 line: 3,
2220 column: 7,
2221 value: "hello",
2222 },
2223 },
2224 },
2225 {
2226 name: "single quote and double quote",
2227 src: `foo: "test
2228
2229
2230
2231
2232 bar"
2233 foo2: 'bar2'`,
2234 expect: []testToken{
2235 {
2236 line: 1,
2237 column: 1,
2238 value: "foo",
2239 },
2240 {
2241 line: 1,
2242 column: 4,
2243 value: ":",
2244 },
2245 {
2246 line: 1,
2247 column: 6,
2248 value: "test bar",
2249 },
2250 {
2251 line: 7,
2252 column: 1,
2253 value: "foo2",
2254 },
2255 {
2256 line: 7,
2257 column: 5,
2258 value: ":",
2259 },
2260 {
2261 line: 7,
2262 column: 7,
2263 value: "bar2",
2264 },
2265 },
2266 },
2267 {
2268 name: "single and double quote map keys",
2269 src: `"a": test
2270 'b': 1
2271 c: true`,
2272 expect: []testToken{
2273 {
2274 line: 1,
2275 column: 1,
2276 value: "a",
2277 },
2278 {
2279 line: 1,
2280 column: 4,
2281 value: ":",
2282 },
2283 {
2284 line: 1,
2285 column: 6,
2286 value: "test",
2287 },
2288 {
2289 line: 2,
2290 column: 1,
2291 value: "b",
2292 },
2293 {
2294 line: 2,
2295 column: 4,
2296 value: ":",
2297 },
2298 {
2299 line: 2,
2300 column: 6,
2301 value: "1",
2302 },
2303 {
2304 line: 3,
2305 column: 1,
2306 value: "c",
2307 },
2308 {
2309 line: 3,
2310 column: 2,
2311 value: ":",
2312 },
2313 {
2314 line: 3,
2315 column: 4,
2316 value: "true",
2317 },
2318 },
2319 },
2320 {
2321 name: "issue326",
2322 src: `a: |
2323 Text
2324 b: 1`,
2325 expect: []testToken{
2326 {
2327 line: 1,
2328 column: 1,
2329 value: "a",
2330 },
2331 {
2332 line: 1,
2333 column: 2,
2334 value: ":",
2335 },
2336 {
2337 line: 1,
2338 column: 4,
2339 value: "|",
2340 },
2341 {
2342 line: 2,
2343 column: 3,
2344 value: "Text\n",
2345 },
2346 {
2347 line: 3,
2348 column: 1,
2349 value: "b",
2350 },
2351 {
2352 line: 3,
2353 column: 2,
2354 value: ":",
2355 },
2356 {
2357 line: 3,
2358 column: 4,
2359 value: "1",
2360 },
2361 },
2362 },
2363 }
2364
2365 for _, tc := range tests {
2366 t.Run(tc.name, func(t *testing.T) {
2367 got := lexer.Tokenize(tc.src)
2368 sort.Slice(got, func(i, j int) bool {
2369 // sort by line, then column
2370 if got[i].Position.Line < got[j].Position.Line {
2371 return true
2372 } else if got[i].Position.Line == got[j].Position.Line {
2373 return got[i].Position.Column < got[j].Position.Column
2374 }
2375 return false
2376 })
2377 sort.Slice(tc.expect, func(i, j int) bool {
2378 if tc.expect[i].line < tc.expect[j].line {
2379 return true
2380 } else if tc.expect[i].line == tc.expect[j].line {
2381 return tc.expect[i].column < tc.expect[j].column
2382 }
2383 return false
2384 })
2385 if len(got) != len(tc.expect) {
2386 t.Errorf("Tokenize() token count mismatch, expected:%d got:%d", len(tc.expect), len(got))
2387 }
2388 for i, tok := range got {
2389 if !tokenMatches(tok, tc.expect[i]) {
2390 t.Errorf("Tokenize() expected:%+v got line:%d column:%d value:%s", tc.expect[i], tok.Position.Line, tok.Position.Column, tok.Value)
2391 }
2392 }
2393 })
2394 }
2395 }