1 //===- unittest/Support/YAMLIOTest.cpp ------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/Support/Casting.h"
13 #include "llvm/Support/Format.h"
14 #include "llvm/Support/YAMLTraits.h"
15 #include "gtest/gtest.h"
17 // To keep build bots going, disable tests until I figure out
18 // why gcc complains there is no match for these traits.
21 using llvm::yaml::Input;
22 using llvm::yaml::Output;
24 using llvm::yaml::MappingTraits;
25 using llvm::yaml::MappingNormalization;
26 using llvm::yaml::ScalarTraits;
27 using llvm::yaml::Hex8;
28 using llvm::yaml::Hex16;
29 using llvm::yaml::Hex32;
30 using llvm::yaml::Hex64;
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
41 typedef std::vector<FooBar> FooBarSequence;
43 LLVM_YAML_IS_SEQUENCE_VECTOR(FooBar)
49 struct MappingTraits<FooBar> {
50 static void mapping(IO &io, FooBar& fb) {
51 io.mapRequired("foo", fb.foo);
52 io.mapRequired("bar", fb.bar);
60 // Test the reading of a yaml mapping
62 TEST(YAMLIO, TestMapRead) {
64 Input yin("---\nfoo: 3\nbar: 5\n...\n");
67 EXPECT_FALSE(yin.error());
68 EXPECT_EQ(doc.foo, 3);
74 // Test the reading of a yaml sequence of mappings
76 TEST(YAMLIO, TestSequenceMapRead) {
78 Input yin("---\n - foo: 3\n bar: 5\n - foo: 7\n bar: 9\n...\n");
81 EXPECT_FALSE(yin.error());
82 EXPECT_EQ(seq.size(), 2UL);
83 FooBar& map1 = seq[0];
84 FooBar& map2 = seq[1];
85 EXPECT_EQ(map1.foo, 3);
86 EXPECT_EQ(map1.bar, 5);
87 EXPECT_EQ(map2.foo, 7);
88 EXPECT_EQ(map2.bar, 9);
93 // Test writing then reading back a sequence of mappings
95 TEST(YAMLIO, TestSequenceMapWriteAndRead) {
96 std::string intermediate;
105 seq.push_back(entry1);
106 seq.push_back(entry2);
108 llvm::raw_string_ostream ostr(intermediate);
114 Input yin(intermediate);
118 EXPECT_FALSE(yin.error());
119 EXPECT_EQ(seq2.size(), 2UL);
120 FooBar& map1 = seq2[0];
121 FooBar& map2 = seq2[1];
122 EXPECT_EQ(map1.foo, 10);
123 EXPECT_EQ(map1.bar, -3);
124 EXPECT_EQ(map2.foo, 257);
125 EXPECT_EQ(map2.bar, 0);
130 //===----------------------------------------------------------------------===//
131 // Test built-in types
132 //===----------------------------------------------------------------------===//
134 struct BuiltInTypes {
156 struct MappingTraits<BuiltInTypes> {
157 static void mapping(IO &io, BuiltInTypes& bt) {
158 io.mapRequired("str", bt.str);
159 io.mapRequired("u64", bt.u64);
160 io.mapRequired("u32", bt.u32);
161 io.mapRequired("u16", bt.u16);
162 io.mapRequired("u8", bt.u8);
163 io.mapRequired("b", bt.b);
164 io.mapRequired("s64", bt.s64);
165 io.mapRequired("s32", bt.s32);
166 io.mapRequired("s16", bt.s16);
167 io.mapRequired("s8", bt.s8);
168 io.mapRequired("f", bt.f);
169 io.mapRequired("d", bt.d);
170 io.mapRequired("h8", bt.h8);
171 io.mapRequired("h16", bt.h16);
172 io.mapRequired("h32", bt.h32);
173 io.mapRequired("h64", bt.h64);
181 // Test the reading of all built-in scalar conversions
183 TEST(YAMLIO, TestReadBuiltInTypes) {
201 "h64: 0xFEDCBA9876543210\n"
205 EXPECT_FALSE(yin.error());
206 EXPECT_TRUE(map.str.equals("hello there"));
207 EXPECT_EQ(map.u64, 5000000000ULL);
208 EXPECT_EQ(map.u32, 4000000000);
209 EXPECT_EQ(map.u16, 65000);
210 EXPECT_EQ(map.u8, 255);
211 EXPECT_EQ(map.b, false);
212 EXPECT_EQ(map.s64, -5000000000LL);
213 EXPECT_EQ(map.s32, -2000000000L);
214 EXPECT_EQ(map.s16, -32000);
215 EXPECT_EQ(map.s8, -127);
216 EXPECT_EQ(map.f, 137.125);
217 EXPECT_EQ(map.d, -2.8625);
218 EXPECT_EQ(map.h8, Hex8(255));
219 EXPECT_EQ(map.h16, Hex16(0x8765));
220 EXPECT_EQ(map.h32, Hex32(0xFEDCBA98));
221 EXPECT_EQ(map.h64, Hex64(0xFEDCBA9876543210LL));
226 // Test writing then reading back all built-in scalar types
228 TEST(YAMLIO, TestReadWriteBuiltInTypes) {
229 std::string intermediate;
233 map.u64 = 6000000000;
234 map.u32 = 3000000000;
238 map.s64 = -6000000000;
239 map.s32 = -2000000000;
246 map.h32 = 3000000000;
247 map.h64 = 6000000000LL;
249 llvm::raw_string_ostream ostr(intermediate);
255 Input yin(intermediate);
259 EXPECT_FALSE(yin.error());
260 EXPECT_TRUE(map.str.equals("one two"));
261 EXPECT_EQ(map.u64, 6000000000ULL);
262 EXPECT_EQ(map.u32, 3000000000UL);
263 EXPECT_EQ(map.u16, 50000);
264 EXPECT_EQ(map.u8, 254);
265 EXPECT_EQ(map.b, true);
266 EXPECT_EQ(map.s64, -6000000000LL);
267 EXPECT_EQ(map.s32, -2000000000L);
268 EXPECT_EQ(map.s16, -32000);
269 EXPECT_EQ(map.s8, -128);
270 EXPECT_EQ(map.f, 3.25);
271 EXPECT_EQ(map.d, -2.8625);
272 EXPECT_EQ(map.h8, Hex8(254));
273 EXPECT_EQ(map.h16, Hex16(50000));
274 EXPECT_EQ(map.h32, Hex32(3000000000));
275 EXPECT_EQ(map.h64, Hex64(6000000000LL));
281 //===----------------------------------------------------------------------===//
282 // Test ScalarEnumerationTraits
283 //===----------------------------------------------------------------------===//
304 struct ScalarEnumerationTraits<Colors> {
305 static void enumeration(IO &io, Colors &value) {
306 io.enumCase(value, "red", cRed);
307 io.enumCase(value, "blue", cBlue);
308 io.enumCase(value, "green", cGreen);
309 io.enumCase(value, "yellow",cYellow);
313 struct MappingTraits<ColorMap> {
314 static void mapping(IO &io, ColorMap& c) {
315 io.mapRequired("c1", c.c1);
316 io.mapRequired("c2", c.c2);
317 io.mapRequired("c3", c.c3);
318 io.mapOptional("c4", c.c4, cBlue); // supplies default
319 io.mapOptional("c5", c.c5, cYellow); // supplies default
320 io.mapOptional("c6", c.c6, cRed); // supplies default
328 // Test reading enumerated scalars
330 TEST(YAMLIO, TestEnumRead) {
340 EXPECT_FALSE(yin.error());
341 EXPECT_EQ(cBlue, map.c1);
342 EXPECT_EQ(cRed, map.c2);
343 EXPECT_EQ(cGreen, map.c3);
344 EXPECT_EQ(cBlue, map.c4); // tests default
345 EXPECT_EQ(cYellow,map.c5); // tests overridden
346 EXPECT_EQ(cRed, map.c6); // tests default
351 //===----------------------------------------------------------------------===//
352 // Test ScalarBitSetTraits
353 //===----------------------------------------------------------------------===//
362 inline MyFlags operator|(MyFlags a, MyFlags b) {
363 return static_cast<MyFlags>(
364 static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
378 struct ScalarBitSetTraits<MyFlags> {
379 static void bitset(IO &io, MyFlags &value) {
380 io.bitSetCase(value, "big", flagBig);
381 io.bitSetCase(value, "flat", flagFlat);
382 io.bitSetCase(value, "round", flagRound);
383 io.bitSetCase(value, "pointy",flagPointy);
387 struct MappingTraits<FlagsMap> {
388 static void mapping(IO &io, FlagsMap& c) {
389 io.mapRequired("f1", c.f1);
390 io.mapRequired("f2", c.f2);
391 io.mapRequired("f3", c.f3);
392 io.mapOptional("f4", c.f4, MyFlags(flagRound));
400 // Test reading flow sequence representing bit-mask values
402 TEST(YAMLIO, TestFlagsRead) {
406 "f2: [ round, flat ]\n"
411 EXPECT_FALSE(yin.error());
412 EXPECT_EQ(flagBig, map.f1);
413 EXPECT_EQ(flagRound|flagFlat, map.f2);
414 EXPECT_EQ(flagNone, map.f3); // check empty set
415 EXPECT_EQ(flagRound, map.f4); // check optional key
420 // Test writing then reading back bit-mask values
422 TEST(YAMLIO, TestReadWriteFlags) {
423 std::string intermediate;
427 map.f2 = flagRound | flagFlat;
431 llvm::raw_string_ostream ostr(intermediate);
437 Input yin(intermediate);
441 EXPECT_FALSE(yin.error());
442 EXPECT_EQ(flagBig, map2.f1);
443 EXPECT_EQ(flagRound|flagFlat, map2.f2);
444 EXPECT_EQ(flagNone, map2.f3);
445 //EXPECT_EQ(flagRound, map2.f4); // check optional key
451 //===----------------------------------------------------------------------===//
453 //===----------------------------------------------------------------------===//
455 struct MyCustomType {
460 struct MyCustomTypeMap {
470 struct MappingTraits<MyCustomTypeMap> {
471 static void mapping(IO &io, MyCustomTypeMap& s) {
472 io.mapRequired("f1", s.f1);
473 io.mapRequired("f2", s.f2);
474 io.mapRequired("f3", s.f3);
477 // MyCustomType is formatted as a yaml scalar. A value of
478 // {length=3, width=4} would be represented in yaml as "3 by 4".
480 struct ScalarTraits<MyCustomType> {
481 static void output(const MyCustomType &value, void* ctxt, llvm::raw_ostream &out) {
482 out << llvm::format("%d by %d", value.length, value.width);
484 static StringRef input(StringRef scalar, void* ctxt, MyCustomType &value) {
485 size_t byStart = scalar.find("by");
486 if ( byStart != StringRef::npos ) {
487 StringRef lenStr = scalar.slice(0, byStart);
488 lenStr = lenStr.rtrim();
489 if ( lenStr.getAsInteger(0, value.length) ) {
490 return "malformed length";
492 StringRef widthStr = scalar.drop_front(byStart+2);
493 widthStr = widthStr.ltrim();
494 if ( widthStr.getAsInteger(0, value.width) ) {
495 return "malformed width";
500 return "malformed by";
509 // Test writing then reading back custom values
511 TEST(YAMLIO, TestReadWriteMyCustomType) {
512 std::string intermediate;
521 llvm::raw_string_ostream ostr(intermediate);
527 Input yin(intermediate);
528 MyCustomTypeMap map2;
531 EXPECT_FALSE(yin.error());
532 EXPECT_EQ(1, map2.f1.length);
533 EXPECT_EQ(4, map2.f1.width);
534 EXPECT_EQ(100, map2.f2.length);
535 EXPECT_EQ(400, map2.f2.width);
536 EXPECT_EQ(10, map2.f3);
541 //===----------------------------------------------------------------------===//
542 // Test flow sequences
543 //===----------------------------------------------------------------------===//
545 LLVM_YAML_STRONG_TYPEDEF(int, MyNumber)
546 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyNumber)
547 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::StringRef)
552 struct ScalarTraits<MyNumber> {
553 static void output(const MyNumber &value, void *, llvm::raw_ostream &out) {
557 static StringRef input(StringRef scalar, void *, MyNumber &value) {
559 if ( getAsSignedInteger(scalar, 0, n) )
560 return "invalid number";
568 struct NameAndNumbers {
569 llvm::StringRef name;
570 std::vector<llvm::StringRef> strings;
571 std::vector<MyNumber> single;
572 std::vector<MyNumber> numbers;
578 struct MappingTraits<NameAndNumbers> {
579 static void mapping(IO &io, NameAndNumbers& nn) {
580 io.mapRequired("name", nn.name);
581 io.mapRequired("strings", nn.strings);
582 io.mapRequired("single", nn.single);
583 io.mapRequired("numbers", nn.numbers);
591 // Test writing then reading back custom values
593 TEST(YAMLIO, TestReadWriteMyFlowSequence) {
594 std::string intermediate;
598 map.strings.push_back(llvm::StringRef("one"));
599 map.strings.push_back(llvm::StringRef("two"));
600 map.single.push_back(1);
601 map.numbers.push_back(10);
602 map.numbers.push_back(-30);
603 map.numbers.push_back(1024);
605 llvm::raw_string_ostream ostr(intermediate);
611 Input yin(intermediate);
615 EXPECT_FALSE(yin.error());
616 EXPECT_TRUE(map2.name.equals("hello"));
617 EXPECT_EQ(map2.strings.size(), 2UL);
618 EXPECT_TRUE(map2.strings[0].equals("one"));
619 EXPECT_TRUE(map2.strings[1].equals("two"));
620 EXPECT_EQ(map2.single.size(), 1UL);
621 EXPECT_EQ(1, map2.single[0]);
622 EXPECT_EQ(map2.numbers.size(), 3UL);
623 EXPECT_EQ(10, map2.numbers[0]);
624 EXPECT_EQ(-30, map2.numbers[1]);
625 EXPECT_EQ(1024, map2.numbers[2]);
630 //===----------------------------------------------------------------------===//
631 // Test normalizing/denormalizing
632 //===----------------------------------------------------------------------===//
634 LLVM_YAML_STRONG_TYPEDEF(uint32_t, TotalSeconds)
636 typedef std::vector<TotalSeconds> SecondsSequence;
638 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TotalSeconds)
644 struct MappingTraits<TotalSeconds> {
646 class NormalizedSeconds {
648 NormalizedSeconds(IO &io)
649 : hours(0), minutes(0), seconds(0) {
651 NormalizedSeconds(IO &, TotalSeconds &secs)
653 minutes((secs - (hours*3600))/60),
656 TotalSeconds denormalize(IO &) {
657 return TotalSeconds(hours*3600 + minutes*60 + seconds);
665 static void mapping(IO &io, TotalSeconds &secs) {
666 MappingNormalization<NormalizedSeconds, TotalSeconds> keys(io, secs);
668 io.mapOptional("hours", keys->hours, (uint32_t)0);
669 io.mapOptional("minutes", keys->minutes, (uint8_t)0);
670 io.mapRequired("seconds", keys->seconds);
678 // Test the reading of a yaml sequence of mappings
680 TEST(YAMLIO, TestReadMySecondsSequence) {
682 Input yin("---\n - hours: 1\n seconds: 5\n - seconds: 59\n...\n");
685 EXPECT_FALSE(yin.error());
686 EXPECT_EQ(seq.size(), 2UL);
687 EXPECT_EQ(seq[0], 3605U);
688 EXPECT_EQ(seq[1], 59U);
693 // Test writing then reading back custom values
695 TEST(YAMLIO, TestReadWriteMySecondsSequence) {
696 std::string intermediate;
703 llvm::raw_string_ostream ostr(intermediate);
708 Input yin(intermediate);
709 SecondsSequence seq2;
712 EXPECT_FALSE(yin.error());
713 EXPECT_EQ(seq2.size(), 3UL);
714 EXPECT_EQ(seq2[0], 4000U);
715 EXPECT_EQ(seq2[1], 500U);
716 EXPECT_EQ(seq2[2], 59U);
721 //===----------------------------------------------------------------------===//
722 // Test dynamic typing
723 //===----------------------------------------------------------------------===//
742 struct KindAndFlags {
743 KindAndFlags() : kind(kindA), flags(0) { }
744 KindAndFlags(Kind k, uint32_t f) : kind(k), flags(f) { }
749 typedef std::vector<KindAndFlags> KindAndFlagsSequence;
751 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(KindAndFlags)
756 struct ScalarEnumerationTraits<AFlags> {
757 static void enumeration(IO &io, AFlags &value) {
758 io.enumCase(value, "a1", a1);
759 io.enumCase(value, "a2", a2);
760 io.enumCase(value, "a3", a3);
764 struct ScalarEnumerationTraits<BFlags> {
765 static void enumeration(IO &io, BFlags &value) {
766 io.enumCase(value, "b1", b1);
767 io.enumCase(value, "b2", b2);
768 io.enumCase(value, "b3", b3);
772 struct ScalarEnumerationTraits<Kind> {
773 static void enumeration(IO &io, Kind &value) {
774 io.enumCase(value, "A", kindA);
775 io.enumCase(value, "B", kindB);
779 struct MappingTraits<KindAndFlags> {
780 static void mapping(IO &io, KindAndFlags& kf) {
781 io.mapRequired("kind", kf.kind);
782 // type of flags field varies depending on kind field
783 if ( kf.kind == kindA )
784 io.mapRequired("flags", *((AFlags*)&kf.flags));
786 io.mapRequired("flags", *((BFlags*)&kf.flags));
794 // Test the reading of a yaml sequence dynamic types
796 TEST(YAMLIO, TestReadKindAndFlagsSequence) {
797 KindAndFlagsSequence seq;
798 Input yin("---\n - kind: A\n flags: a2\n - kind: B\n flags: b1\n...\n");
801 EXPECT_FALSE(yin.error());
802 EXPECT_EQ(seq.size(), 2UL);
803 EXPECT_EQ(seq[0].kind, kindA);
804 EXPECT_EQ(seq[0].flags, a2);
805 EXPECT_EQ(seq[1].kind, kindB);
806 EXPECT_EQ(seq[1].flags, b1);
810 // Test writing then reading back dynamic types
812 TEST(YAMLIO, TestReadWriteKindAndFlagsSequence) {
813 std::string intermediate;
815 KindAndFlagsSequence seq;
816 seq.push_back(KindAndFlags(kindA,a1));
817 seq.push_back(KindAndFlags(kindB,b1));
818 seq.push_back(KindAndFlags(kindA,a2));
819 seq.push_back(KindAndFlags(kindB,b2));
820 seq.push_back(KindAndFlags(kindA,a3));
822 llvm::raw_string_ostream ostr(intermediate);
827 Input yin(intermediate);
828 KindAndFlagsSequence seq2;
831 EXPECT_FALSE(yin.error());
832 EXPECT_EQ(seq2.size(), 5UL);
833 EXPECT_EQ(seq2[0].kind, kindA);
834 EXPECT_EQ(seq2[0].flags, a1);
835 EXPECT_EQ(seq2[1].kind, kindB);
836 EXPECT_EQ(seq2[1].flags, b1);
837 EXPECT_EQ(seq2[2].kind, kindA);
838 EXPECT_EQ(seq2[2].flags, a2);
839 EXPECT_EQ(seq2[3].kind, kindB);
840 EXPECT_EQ(seq2[3].flags, b2);
841 EXPECT_EQ(seq2[4].kind, kindA);
842 EXPECT_EQ(seq2[4].flags, a3);
847 //===----------------------------------------------------------------------===//
848 // Test document list
849 //===----------------------------------------------------------------------===//
855 typedef std::vector<FooBarMap> FooBarMapDocumentList;
857 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(FooBarMap)
863 struct MappingTraits<FooBarMap> {
864 static void mapping(IO &io, FooBarMap& fb) {
865 io.mapRequired("foo", fb.foo);
866 io.mapRequired("bar", fb.bar);
874 // Test the reading of a yaml mapping
876 TEST(YAMLIO, TestDocRead) {
878 Input yin("---\nfoo: 3\nbar: 5\n...\n");
881 EXPECT_FALSE(yin.error());
882 EXPECT_EQ(doc.foo, 3);
883 EXPECT_EQ(doc.bar,5);
889 // Test writing then reading back a sequence of mappings
891 TEST(YAMLIO, TestSequenceDocListWriteAndRead) {
892 std::string intermediate;
900 std::vector<FooBarMap> docList;
901 docList.push_back(doc1);
902 docList.push_back(doc2);
904 llvm::raw_string_ostream ostr(intermediate);
911 Input yin(intermediate);
912 std::vector<FooBarMap> docList2;
915 EXPECT_FALSE(yin.error());
916 EXPECT_EQ(docList2.size(), 2UL);
917 FooBarMap& map1 = docList2[0];
918 FooBarMap& map2 = docList2[1];
919 EXPECT_EQ(map1.foo, 10);
920 EXPECT_EQ(map1.bar, -3);
921 EXPECT_EQ(map2.foo, 257);
922 EXPECT_EQ(map2.bar, 0);
927 //===----------------------------------------------------------------------===//
928 // Test error handling
929 //===----------------------------------------------------------------------===//
933 static void suppressErrorMessages(const llvm::SMDiagnostic &, void *) {
938 // Test error handling of unknown enumerated scalar
940 TEST(YAMLIO, TestColorsReadError) {
947 yin.setDiagHandler(suppressErrorMessages);
949 EXPECT_TRUE(yin.error());
954 // Test error handling of flow sequence with unknown value
956 TEST(YAMLIO, TestFlagsReadError) {
960 "f2: [ round, hollow ]\n"
963 yin.setDiagHandler(suppressErrorMessages);
966 EXPECT_TRUE(yin.error());
971 // Test error handling reading built-in uint8_t type
973 LLVM_YAML_IS_SEQUENCE_VECTOR(uint8_t)
974 TEST(YAMLIO, TestReadBuiltInTypesUint8Error) {
975 std::vector<uint8_t> seq;
981 yin.setDiagHandler(suppressErrorMessages);
984 EXPECT_TRUE(yin.error());
989 // Test error handling reading built-in uint16_t type
991 LLVM_YAML_IS_SEQUENCE_VECTOR(uint16_t)
992 TEST(YAMLIO, TestReadBuiltInTypesUint16Error) {
993 std::vector<uint16_t> seq;
999 yin.setDiagHandler(suppressErrorMessages);
1002 EXPECT_TRUE(yin.error());
1007 // Test error handling reading built-in uint32_t type
1009 LLVM_YAML_IS_SEQUENCE_VECTOR(uint32_t)
1010 TEST(YAMLIO, TestReadBuiltInTypesUint32Error) {
1011 std::vector<uint32_t> seq;
1017 yin.setDiagHandler(suppressErrorMessages);
1020 EXPECT_TRUE(yin.error());
1025 // Test error handling reading built-in uint64_t type
1027 LLVM_YAML_IS_SEQUENCE_VECTOR(uint64_t)
1028 TEST(YAMLIO, TestReadBuiltInTypesUint64Error) {
1029 std::vector<uint64_t> seq;
1031 "- 18446744073709551615\n"
1033 "- 19446744073709551615\n"
1035 yin.setDiagHandler(suppressErrorMessages);
1038 EXPECT_TRUE(yin.error());
1043 // Test error handling reading built-in int8_t type
1045 LLVM_YAML_IS_SEQUENCE_VECTOR(int8_t)
1046 TEST(YAMLIO, TestReadBuiltInTypesint8OverError) {
1047 std::vector<int8_t> seq;
1054 yin.setDiagHandler(suppressErrorMessages);
1057 EXPECT_TRUE(yin.error());
1061 // Test error handling reading built-in int8_t type
1063 TEST(YAMLIO, TestReadBuiltInTypesint8UnderError) {
1064 std::vector<int8_t> seq;
1071 yin.setDiagHandler(suppressErrorMessages);
1074 EXPECT_TRUE(yin.error());
1079 // Test error handling reading built-in int16_t type
1081 LLVM_YAML_IS_SEQUENCE_VECTOR(int16_t)
1082 TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) {
1083 std::vector<int16_t> seq;
1090 yin.setDiagHandler(suppressErrorMessages);
1093 EXPECT_TRUE(yin.error());
1098 // Test error handling reading built-in int16_t type
1100 TEST(YAMLIO, TestReadBuiltInTypesint16OverError) {
1101 std::vector<int16_t> seq;
1108 yin.setDiagHandler(suppressErrorMessages);
1111 EXPECT_TRUE(yin.error());
1116 // Test error handling reading built-in int32_t type
1118 LLVM_YAML_IS_SEQUENCE_VECTOR(int32_t)
1119 TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) {
1120 std::vector<int32_t> seq;
1127 yin.setDiagHandler(suppressErrorMessages);
1130 EXPECT_TRUE(yin.error());
1134 // Test error handling reading built-in int32_t type
1136 TEST(YAMLIO, TestReadBuiltInTypesint32OverError) {
1137 std::vector<int32_t> seq;
1144 yin.setDiagHandler(suppressErrorMessages);
1147 EXPECT_TRUE(yin.error());
1152 // Test error handling reading built-in int64_t type
1154 LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)
1155 TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) {
1156 std::vector<int64_t> seq;
1158 "- -9223372036854775808\n"
1160 "- 9223372036854775807\n"
1161 "- -9223372036854775809\n"
1163 yin.setDiagHandler(suppressErrorMessages);
1166 EXPECT_TRUE(yin.error());
1170 // Test error handling reading built-in int64_t type
1172 TEST(YAMLIO, TestReadBuiltInTypesint64OverError) {
1173 std::vector<int64_t> seq;
1175 "- -9223372036854775808\n"
1177 "- 9223372036854775807\n"
1178 "- 9223372036854775809\n"
1180 yin.setDiagHandler(suppressErrorMessages);
1183 EXPECT_TRUE(yin.error());
1187 // Test error handling reading built-in float type
1189 LLVM_YAML_IS_SEQUENCE_VECTOR(float)
1190 TEST(YAMLIO, TestReadBuiltInTypesFloatError) {
1191 std::vector<float> seq;
1198 yin.setDiagHandler(suppressErrorMessages);
1201 EXPECT_TRUE(yin.error());
1205 // Test error handling reading built-in float type
1207 LLVM_YAML_IS_SEQUENCE_VECTOR(double)
1208 TEST(YAMLIO, TestReadBuiltInTypesDoubleError) {
1209 std::vector<double> seq;
1216 yin.setDiagHandler(suppressErrorMessages);
1219 EXPECT_TRUE(yin.error());
1223 // Test error handling reading built-in Hex8 type
1225 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex8)
1226 TEST(YAMLIO, TestReadBuiltInTypesHex8Error) {
1227 std::vector<Hex8> seq;
1233 yin.setDiagHandler(suppressErrorMessages);
1236 EXPECT_TRUE(yin.error());
1241 // Test error handling reading built-in Hex16 type
1243 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex16)
1244 TEST(YAMLIO, TestReadBuiltInTypesHex16Error) {
1245 std::vector<Hex16> seq;
1251 yin.setDiagHandler(suppressErrorMessages);
1254 EXPECT_TRUE(yin.error());
1258 // Test error handling reading built-in Hex32 type
1260 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex32)
1261 TEST(YAMLIO, TestReadBuiltInTypesHex32Error) {
1262 std::vector<Hex32> seq;
1268 yin.setDiagHandler(suppressErrorMessages);
1271 EXPECT_TRUE(yin.error());
1275 // Test error handling reading built-in Hex64 type
1277 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex64)
1278 TEST(YAMLIO, TestReadBuiltInTypesHex64Error) {
1279 std::vector<Hex64> seq;
1282 "- 0xFFEEDDCCBBAA9988\n"
1283 "- 0x12345567890ABCDEF0\n"
1285 yin.setDiagHandler(suppressErrorMessages);
1288 EXPECT_TRUE(yin.error());