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"
18 using llvm::yaml::Input;
19 using llvm::yaml::Output;
21 using llvm::yaml::MappingTraits;
22 using llvm::yaml::MappingNormalization;
23 using llvm::yaml::ScalarTraits;
24 using llvm::yaml::Hex8;
25 using llvm::yaml::Hex16;
26 using llvm::yaml::Hex32;
27 using llvm::yaml::Hex64;
30 //===----------------------------------------------------------------------===//
32 //===----------------------------------------------------------------------===//
38 typedef std::vector<FooBar> FooBarSequence;
40 LLVM_YAML_IS_SEQUENCE_VECTOR(FooBar)
46 struct MappingTraits<FooBar> {
47 static void mapping(IO &io, FooBar& fb) {
48 io.mapRequired("foo", fb.foo);
49 io.mapRequired("bar", fb.bar);
57 // Test the reading of a yaml mapping
59 TEST(YAMLIO, TestMapRead) {
61 Input yin("---\nfoo: 3\nbar: 5\n...\n");
64 EXPECT_FALSE(yin.error());
65 EXPECT_EQ(doc.foo, 3);
71 // Test the reading of a yaml sequence of mappings
73 TEST(YAMLIO, TestSequenceMapRead) {
75 Input yin("---\n - foo: 3\n bar: 5\n - foo: 7\n bar: 9\n...\n");
78 EXPECT_FALSE(yin.error());
79 EXPECT_EQ(seq.size(), 2UL);
80 FooBar& map1 = seq[0];
81 FooBar& map2 = seq[1];
82 EXPECT_EQ(map1.foo, 3);
83 EXPECT_EQ(map1.bar, 5);
84 EXPECT_EQ(map2.foo, 7);
85 EXPECT_EQ(map2.bar, 9);
90 // Test writing then reading back a sequence of mappings
92 TEST(YAMLIO, TestSequenceMapWriteAndRead) {
93 std::string intermediate;
102 seq.push_back(entry1);
103 seq.push_back(entry2);
105 llvm::raw_string_ostream ostr(intermediate);
111 Input yin(intermediate);
115 EXPECT_FALSE(yin.error());
116 EXPECT_EQ(seq2.size(), 2UL);
117 FooBar& map1 = seq2[0];
118 FooBar& map2 = seq2[1];
119 EXPECT_EQ(map1.foo, 10);
120 EXPECT_EQ(map1.bar, -3);
121 EXPECT_EQ(map2.foo, 257);
122 EXPECT_EQ(map2.bar, 0);
127 //===----------------------------------------------------------------------===//
128 // Test built-in types
129 //===----------------------------------------------------------------------===//
131 struct BuiltInTypes {
153 struct MappingTraits<BuiltInTypes> {
154 static void mapping(IO &io, BuiltInTypes& bt) {
155 io.mapRequired("str", bt.str);
156 io.mapRequired("u64", bt.u64);
157 io.mapRequired("u32", bt.u32);
158 io.mapRequired("u16", bt.u16);
159 io.mapRequired("u8", bt.u8);
160 io.mapRequired("b", bt.b);
161 io.mapRequired("s64", bt.s64);
162 io.mapRequired("s32", bt.s32);
163 io.mapRequired("s16", bt.s16);
164 io.mapRequired("s8", bt.s8);
165 io.mapRequired("f", bt.f);
166 io.mapRequired("d", bt.d);
167 io.mapRequired("h8", bt.h8);
168 io.mapRequired("h16", bt.h16);
169 io.mapRequired("h32", bt.h32);
170 io.mapRequired("h64", bt.h64);
178 // Test the reading of all built-in scalar conversions
180 TEST(YAMLIO, TestReadBuiltInTypes) {
198 "h64: 0xFEDCBA9876543210\n"
202 EXPECT_FALSE(yin.error());
203 EXPECT_TRUE(map.str.equals("hello there"));
204 EXPECT_EQ(map.u64, 5000000000ULL);
205 EXPECT_EQ(map.u32, 4000000000U);
206 EXPECT_EQ(map.u16, 65000);
207 EXPECT_EQ(map.u8, 255);
208 EXPECT_EQ(map.b, false);
209 EXPECT_EQ(map.s64, -5000000000LL);
210 EXPECT_EQ(map.s32, -2000000000L);
211 EXPECT_EQ(map.s16, -32000);
212 EXPECT_EQ(map.s8, -127);
213 EXPECT_EQ(map.f, 137.125);
214 EXPECT_EQ(map.d, -2.8625);
215 EXPECT_EQ(map.h8, Hex8(255));
216 EXPECT_EQ(map.h16, Hex16(0x8765));
217 EXPECT_EQ(map.h32, Hex32(0xFEDCBA98));
218 EXPECT_EQ(map.h64, Hex64(0xFEDCBA9876543210LL));
223 // Test writing then reading back all built-in scalar types
225 TEST(YAMLIO, TestReadWriteBuiltInTypes) {
226 std::string intermediate;
230 map.u64 = 6000000000ULL;
231 map.u32 = 3000000000U;
235 map.s64 = -6000000000LL;
236 map.s32 = -2000000000;
243 map.h32 = 3000000000U;
244 map.h64 = 6000000000LL;
246 llvm::raw_string_ostream ostr(intermediate);
252 Input yin(intermediate);
256 EXPECT_FALSE(yin.error());
257 EXPECT_TRUE(map.str.equals("one two"));
258 EXPECT_EQ(map.u64, 6000000000ULL);
259 EXPECT_EQ(map.u32, 3000000000U);
260 EXPECT_EQ(map.u16, 50000);
261 EXPECT_EQ(map.u8, 254);
262 EXPECT_EQ(map.b, true);
263 EXPECT_EQ(map.s64, -6000000000LL);
264 EXPECT_EQ(map.s32, -2000000000L);
265 EXPECT_EQ(map.s16, -32000);
266 EXPECT_EQ(map.s8, -128);
267 EXPECT_EQ(map.f, 3.25);
268 EXPECT_EQ(map.d, -2.8625);
269 EXPECT_EQ(map.h8, Hex8(254));
270 EXPECT_EQ(map.h16, Hex16(50000));
271 EXPECT_EQ(map.h32, Hex32(3000000000U));
272 EXPECT_EQ(map.h64, Hex64(6000000000LL));
278 //===----------------------------------------------------------------------===//
279 // Test ScalarEnumerationTraits
280 //===----------------------------------------------------------------------===//
301 struct ScalarEnumerationTraits<Colors> {
302 static void enumeration(IO &io, Colors &value) {
303 io.enumCase(value, "red", cRed);
304 io.enumCase(value, "blue", cBlue);
305 io.enumCase(value, "green", cGreen);
306 io.enumCase(value, "yellow",cYellow);
310 struct MappingTraits<ColorMap> {
311 static void mapping(IO &io, ColorMap& c) {
312 io.mapRequired("c1", c.c1);
313 io.mapRequired("c2", c.c2);
314 io.mapRequired("c3", c.c3);
315 io.mapOptional("c4", c.c4, cBlue); // supplies default
316 io.mapOptional("c5", c.c5, cYellow); // supplies default
317 io.mapOptional("c6", c.c6, cRed); // supplies default
325 // Test reading enumerated scalars
327 TEST(YAMLIO, TestEnumRead) {
337 EXPECT_FALSE(yin.error());
338 EXPECT_EQ(cBlue, map.c1);
339 EXPECT_EQ(cRed, map.c2);
340 EXPECT_EQ(cGreen, map.c3);
341 EXPECT_EQ(cBlue, map.c4); // tests default
342 EXPECT_EQ(cYellow,map.c5); // tests overridden
343 EXPECT_EQ(cRed, map.c6); // tests default
348 //===----------------------------------------------------------------------===//
349 // Test ScalarBitSetTraits
350 //===----------------------------------------------------------------------===//
359 inline MyFlags operator|(MyFlags a, MyFlags b) {
360 return static_cast<MyFlags>(
361 static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
375 struct ScalarBitSetTraits<MyFlags> {
376 static void bitset(IO &io, MyFlags &value) {
377 io.bitSetCase(value, "big", flagBig);
378 io.bitSetCase(value, "flat", flagFlat);
379 io.bitSetCase(value, "round", flagRound);
380 io.bitSetCase(value, "pointy",flagPointy);
384 struct MappingTraits<FlagsMap> {
385 static void mapping(IO &io, FlagsMap& c) {
386 io.mapRequired("f1", c.f1);
387 io.mapRequired("f2", c.f2);
388 io.mapRequired("f3", c.f3);
389 io.mapOptional("f4", c.f4, MyFlags(flagRound));
397 // Test reading flow sequence representing bit-mask values
399 TEST(YAMLIO, TestFlagsRead) {
403 "f2: [ round, flat ]\n"
408 EXPECT_FALSE(yin.error());
409 EXPECT_EQ(flagBig, map.f1);
410 EXPECT_EQ(flagRound|flagFlat, map.f2);
411 EXPECT_EQ(flagNone, map.f3); // check empty set
412 EXPECT_EQ(flagRound, map.f4); // check optional key
417 // Test writing then reading back bit-mask values
419 TEST(YAMLIO, TestReadWriteFlags) {
420 std::string intermediate;
424 map.f2 = flagRound | flagFlat;
428 llvm::raw_string_ostream ostr(intermediate);
434 Input yin(intermediate);
438 EXPECT_FALSE(yin.error());
439 EXPECT_EQ(flagBig, map2.f1);
440 EXPECT_EQ(flagRound|flagFlat, map2.f2);
441 EXPECT_EQ(flagNone, map2.f3);
442 //EXPECT_EQ(flagRound, map2.f4); // check optional key
448 //===----------------------------------------------------------------------===//
450 //===----------------------------------------------------------------------===//
452 struct MyCustomType {
457 struct MyCustomTypeMap {
467 struct MappingTraits<MyCustomTypeMap> {
468 static void mapping(IO &io, MyCustomTypeMap& s) {
469 io.mapRequired("f1", s.f1);
470 io.mapRequired("f2", s.f2);
471 io.mapRequired("f3", s.f3);
474 // MyCustomType is formatted as a yaml scalar. A value of
475 // {length=3, width=4} would be represented in yaml as "3 by 4".
477 struct ScalarTraits<MyCustomType> {
478 static void output(const MyCustomType &value, void* ctxt, llvm::raw_ostream &out) {
479 out << llvm::format("%d by %d", value.length, value.width);
481 static StringRef input(StringRef scalar, void* ctxt, MyCustomType &value) {
482 size_t byStart = scalar.find("by");
483 if ( byStart != StringRef::npos ) {
484 StringRef lenStr = scalar.slice(0, byStart);
485 lenStr = lenStr.rtrim();
486 if ( lenStr.getAsInteger(0, value.length) ) {
487 return "malformed length";
489 StringRef widthStr = scalar.drop_front(byStart+2);
490 widthStr = widthStr.ltrim();
491 if ( widthStr.getAsInteger(0, value.width) ) {
492 return "malformed width";
497 return "malformed by";
506 // Test writing then reading back custom values
508 TEST(YAMLIO, TestReadWriteMyCustomType) {
509 std::string intermediate;
518 llvm::raw_string_ostream ostr(intermediate);
524 Input yin(intermediate);
525 MyCustomTypeMap map2;
528 EXPECT_FALSE(yin.error());
529 EXPECT_EQ(1, map2.f1.length);
530 EXPECT_EQ(4, map2.f1.width);
531 EXPECT_EQ(100, map2.f2.length);
532 EXPECT_EQ(400, map2.f2.width);
533 EXPECT_EQ(10, map2.f3);
538 //===----------------------------------------------------------------------===//
539 // Test flow sequences
540 //===----------------------------------------------------------------------===//
542 LLVM_YAML_STRONG_TYPEDEF(int, MyNumber)
543 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyNumber)
544 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::StringRef)
549 struct ScalarTraits<MyNumber> {
550 static void output(const MyNumber &value, void *, llvm::raw_ostream &out) {
554 static StringRef input(StringRef scalar, void *, MyNumber &value) {
556 if ( getAsSignedInteger(scalar, 0, n) )
557 return "invalid number";
565 struct NameAndNumbers {
566 llvm::StringRef name;
567 std::vector<llvm::StringRef> strings;
568 std::vector<MyNumber> single;
569 std::vector<MyNumber> numbers;
575 struct MappingTraits<NameAndNumbers> {
576 static void mapping(IO &io, NameAndNumbers& nn) {
577 io.mapRequired("name", nn.name);
578 io.mapRequired("strings", nn.strings);
579 io.mapRequired("single", nn.single);
580 io.mapRequired("numbers", nn.numbers);
588 // Test writing then reading back custom values
590 TEST(YAMLIO, TestReadWriteMyFlowSequence) {
591 std::string intermediate;
595 map.strings.push_back(llvm::StringRef("one"));
596 map.strings.push_back(llvm::StringRef("two"));
597 map.single.push_back(1);
598 map.numbers.push_back(10);
599 map.numbers.push_back(-30);
600 map.numbers.push_back(1024);
602 llvm::raw_string_ostream ostr(intermediate);
608 Input yin(intermediate);
612 EXPECT_FALSE(yin.error());
613 EXPECT_TRUE(map2.name.equals("hello"));
614 EXPECT_EQ(map2.strings.size(), 2UL);
615 EXPECT_TRUE(map2.strings[0].equals("one"));
616 EXPECT_TRUE(map2.strings[1].equals("two"));
617 EXPECT_EQ(map2.single.size(), 1UL);
618 EXPECT_EQ(1, map2.single[0]);
619 EXPECT_EQ(map2.numbers.size(), 3UL);
620 EXPECT_EQ(10, map2.numbers[0]);
621 EXPECT_EQ(-30, map2.numbers[1]);
622 EXPECT_EQ(1024, map2.numbers[2]);
627 //===----------------------------------------------------------------------===//
628 // Test normalizing/denormalizing
629 //===----------------------------------------------------------------------===//
631 LLVM_YAML_STRONG_TYPEDEF(uint32_t, TotalSeconds)
633 typedef std::vector<TotalSeconds> SecondsSequence;
635 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TotalSeconds)
641 struct MappingTraits<TotalSeconds> {
643 class NormalizedSeconds {
645 NormalizedSeconds(IO &io)
646 : hours(0), minutes(0), seconds(0) {
648 NormalizedSeconds(IO &, TotalSeconds &secs)
650 minutes((secs - (hours*3600))/60),
653 TotalSeconds denormalize(IO &) {
654 return TotalSeconds(hours*3600 + minutes*60 + seconds);
662 static void mapping(IO &io, TotalSeconds &secs) {
663 MappingNormalization<NormalizedSeconds, TotalSeconds> keys(io, secs);
665 io.mapOptional("hours", keys->hours, (uint32_t)0);
666 io.mapOptional("minutes", keys->minutes, (uint8_t)0);
667 io.mapRequired("seconds", keys->seconds);
675 // Test the reading of a yaml sequence of mappings
677 TEST(YAMLIO, TestReadMySecondsSequence) {
679 Input yin("---\n - hours: 1\n seconds: 5\n - seconds: 59\n...\n");
682 EXPECT_FALSE(yin.error());
683 EXPECT_EQ(seq.size(), 2UL);
684 EXPECT_EQ(seq[0], 3605U);
685 EXPECT_EQ(seq[1], 59U);
690 // Test writing then reading back custom values
692 TEST(YAMLIO, TestReadWriteMySecondsSequence) {
693 std::string intermediate;
700 llvm::raw_string_ostream ostr(intermediate);
705 Input yin(intermediate);
706 SecondsSequence seq2;
709 EXPECT_FALSE(yin.error());
710 EXPECT_EQ(seq2.size(), 3UL);
711 EXPECT_EQ(seq2[0], 4000U);
712 EXPECT_EQ(seq2[1], 500U);
713 EXPECT_EQ(seq2[2], 59U);
718 //===----------------------------------------------------------------------===//
719 // Test dynamic typing
720 //===----------------------------------------------------------------------===//
739 struct KindAndFlags {
740 KindAndFlags() : kind(kindA), flags(0) { }
741 KindAndFlags(Kind k, uint32_t f) : kind(k), flags(f) { }
746 typedef std::vector<KindAndFlags> KindAndFlagsSequence;
748 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(KindAndFlags)
753 struct ScalarEnumerationTraits<AFlags> {
754 static void enumeration(IO &io, AFlags &value) {
755 io.enumCase(value, "a1", a1);
756 io.enumCase(value, "a2", a2);
757 io.enumCase(value, "a3", a3);
761 struct ScalarEnumerationTraits<BFlags> {
762 static void enumeration(IO &io, BFlags &value) {
763 io.enumCase(value, "b1", b1);
764 io.enumCase(value, "b2", b2);
765 io.enumCase(value, "b3", b3);
769 struct ScalarEnumerationTraits<Kind> {
770 static void enumeration(IO &io, Kind &value) {
771 io.enumCase(value, "A", kindA);
772 io.enumCase(value, "B", kindB);
776 struct MappingTraits<KindAndFlags> {
777 static void mapping(IO &io, KindAndFlags& kf) {
778 io.mapRequired("kind", kf.kind);
779 // type of flags field varies depending on kind field
780 if ( kf.kind == kindA )
781 io.mapRequired("flags", *((AFlags*)&kf.flags));
783 io.mapRequired("flags", *((BFlags*)&kf.flags));
791 // Test the reading of a yaml sequence dynamic types
793 TEST(YAMLIO, TestReadKindAndFlagsSequence) {
794 KindAndFlagsSequence seq;
795 Input yin("---\n - kind: A\n flags: a2\n - kind: B\n flags: b1\n...\n");
798 EXPECT_FALSE(yin.error());
799 EXPECT_EQ(seq.size(), 2UL);
800 EXPECT_EQ(seq[0].kind, kindA);
801 EXPECT_EQ(seq[0].flags, (uint32_t)a2);
802 EXPECT_EQ(seq[1].kind, kindB);
803 EXPECT_EQ(seq[1].flags, (uint32_t)b1);
807 // Test writing then reading back dynamic types
809 TEST(YAMLIO, TestReadWriteKindAndFlagsSequence) {
810 std::string intermediate;
812 KindAndFlagsSequence seq;
813 seq.push_back(KindAndFlags(kindA,a1));
814 seq.push_back(KindAndFlags(kindB,b1));
815 seq.push_back(KindAndFlags(kindA,a2));
816 seq.push_back(KindAndFlags(kindB,b2));
817 seq.push_back(KindAndFlags(kindA,a3));
819 llvm::raw_string_ostream ostr(intermediate);
824 Input yin(intermediate);
825 KindAndFlagsSequence seq2;
828 EXPECT_FALSE(yin.error());
829 EXPECT_EQ(seq2.size(), 5UL);
830 EXPECT_EQ(seq2[0].kind, kindA);
831 EXPECT_EQ(seq2[0].flags, (uint32_t)a1);
832 EXPECT_EQ(seq2[1].kind, kindB);
833 EXPECT_EQ(seq2[1].flags, (uint32_t)b1);
834 EXPECT_EQ(seq2[2].kind, kindA);
835 EXPECT_EQ(seq2[2].flags, (uint32_t)a2);
836 EXPECT_EQ(seq2[3].kind, kindB);
837 EXPECT_EQ(seq2[3].flags, (uint32_t)b2);
838 EXPECT_EQ(seq2[4].kind, kindA);
839 EXPECT_EQ(seq2[4].flags, (uint32_t)a3);
844 //===----------------------------------------------------------------------===//
845 // Test document list
846 //===----------------------------------------------------------------------===//
852 typedef std::vector<FooBarMap> FooBarMapDocumentList;
854 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(FooBarMap)
860 struct MappingTraits<FooBarMap> {
861 static void mapping(IO &io, FooBarMap& fb) {
862 io.mapRequired("foo", fb.foo);
863 io.mapRequired("bar", fb.bar);
871 // Test the reading of a yaml mapping
873 TEST(YAMLIO, TestDocRead) {
875 Input yin("---\nfoo: 3\nbar: 5\n...\n");
878 EXPECT_FALSE(yin.error());
879 EXPECT_EQ(doc.foo, 3);
880 EXPECT_EQ(doc.bar,5);
886 // Test writing then reading back a sequence of mappings
888 TEST(YAMLIO, TestSequenceDocListWriteAndRead) {
889 std::string intermediate;
897 std::vector<FooBarMap> docList;
898 docList.push_back(doc1);
899 docList.push_back(doc2);
901 llvm::raw_string_ostream ostr(intermediate);
908 Input yin(intermediate);
909 std::vector<FooBarMap> docList2;
912 EXPECT_FALSE(yin.error());
913 EXPECT_EQ(docList2.size(), 2UL);
914 FooBarMap& map1 = docList2[0];
915 FooBarMap& map2 = docList2[1];
916 EXPECT_EQ(map1.foo, 10);
917 EXPECT_EQ(map1.bar, -3);
918 EXPECT_EQ(map2.foo, 257);
919 EXPECT_EQ(map2.bar, 0);
924 //===----------------------------------------------------------------------===//
925 // Test error handling
926 //===----------------------------------------------------------------------===//
930 static void suppressErrorMessages(const llvm::SMDiagnostic &, void *) {
935 // Test error handling of unknown enumerated scalar
937 TEST(YAMLIO, TestColorsReadError) {
944 yin.setDiagHandler(suppressErrorMessages);
946 EXPECT_TRUE(yin.error());
951 // Test error handling of flow sequence with unknown value
953 TEST(YAMLIO, TestFlagsReadError) {
957 "f2: [ round, hollow ]\n"
960 yin.setDiagHandler(suppressErrorMessages);
963 EXPECT_TRUE(yin.error());
968 // Test error handling reading built-in uint8_t type
970 LLVM_YAML_IS_SEQUENCE_VECTOR(uint8_t)
971 TEST(YAMLIO, TestReadBuiltInTypesUint8Error) {
972 std::vector<uint8_t> seq;
978 yin.setDiagHandler(suppressErrorMessages);
981 EXPECT_TRUE(yin.error());
986 // Test error handling reading built-in uint16_t type
988 LLVM_YAML_IS_SEQUENCE_VECTOR(uint16_t)
989 TEST(YAMLIO, TestReadBuiltInTypesUint16Error) {
990 std::vector<uint16_t> seq;
996 yin.setDiagHandler(suppressErrorMessages);
999 EXPECT_TRUE(yin.error());
1004 // Test error handling reading built-in uint32_t type
1006 LLVM_YAML_IS_SEQUENCE_VECTOR(uint32_t)
1007 TEST(YAMLIO, TestReadBuiltInTypesUint32Error) {
1008 std::vector<uint32_t> seq;
1014 yin.setDiagHandler(suppressErrorMessages);
1017 EXPECT_TRUE(yin.error());
1022 // Test error handling reading built-in uint64_t type
1024 LLVM_YAML_IS_SEQUENCE_VECTOR(uint64_t)
1025 TEST(YAMLIO, TestReadBuiltInTypesUint64Error) {
1026 std::vector<uint64_t> seq;
1028 "- 18446744073709551615\n"
1030 "- 19446744073709551615\n"
1032 yin.setDiagHandler(suppressErrorMessages);
1035 EXPECT_TRUE(yin.error());
1040 // Test error handling reading built-in int8_t type
1042 LLVM_YAML_IS_SEQUENCE_VECTOR(int8_t)
1043 TEST(YAMLIO, TestReadBuiltInTypesint8OverError) {
1044 std::vector<int8_t> seq;
1051 yin.setDiagHandler(suppressErrorMessages);
1054 EXPECT_TRUE(yin.error());
1058 // Test error handling reading built-in int8_t type
1060 TEST(YAMLIO, TestReadBuiltInTypesint8UnderError) {
1061 std::vector<int8_t> seq;
1068 yin.setDiagHandler(suppressErrorMessages);
1071 EXPECT_TRUE(yin.error());
1076 // Test error handling reading built-in int16_t type
1078 LLVM_YAML_IS_SEQUENCE_VECTOR(int16_t)
1079 TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) {
1080 std::vector<int16_t> seq;
1087 yin.setDiagHandler(suppressErrorMessages);
1090 EXPECT_TRUE(yin.error());
1095 // Test error handling reading built-in int16_t type
1097 TEST(YAMLIO, TestReadBuiltInTypesint16OverError) {
1098 std::vector<int16_t> seq;
1105 yin.setDiagHandler(suppressErrorMessages);
1108 EXPECT_TRUE(yin.error());
1113 // Test error handling reading built-in int32_t type
1115 LLVM_YAML_IS_SEQUENCE_VECTOR(int32_t)
1116 TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) {
1117 std::vector<int32_t> seq;
1124 yin.setDiagHandler(suppressErrorMessages);
1127 EXPECT_TRUE(yin.error());
1131 // Test error handling reading built-in int32_t type
1133 TEST(YAMLIO, TestReadBuiltInTypesint32OverError) {
1134 std::vector<int32_t> seq;
1141 yin.setDiagHandler(suppressErrorMessages);
1144 EXPECT_TRUE(yin.error());
1149 // Test error handling reading built-in int64_t type
1151 LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)
1152 TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) {
1153 std::vector<int64_t> seq;
1155 "- -9223372036854775808\n"
1157 "- 9223372036854775807\n"
1158 "- -9223372036854775809\n"
1160 yin.setDiagHandler(suppressErrorMessages);
1163 EXPECT_TRUE(yin.error());
1167 // Test error handling reading built-in int64_t type
1169 TEST(YAMLIO, TestReadBuiltInTypesint64OverError) {
1170 std::vector<int64_t> seq;
1172 "- -9223372036854775808\n"
1174 "- 9223372036854775807\n"
1175 "- 9223372036854775809\n"
1177 yin.setDiagHandler(suppressErrorMessages);
1180 EXPECT_TRUE(yin.error());
1184 // Test error handling reading built-in float type
1186 LLVM_YAML_IS_SEQUENCE_VECTOR(float)
1187 TEST(YAMLIO, TestReadBuiltInTypesFloatError) {
1188 std::vector<float> seq;
1195 yin.setDiagHandler(suppressErrorMessages);
1198 EXPECT_TRUE(yin.error());
1202 // Test error handling reading built-in float type
1204 LLVM_YAML_IS_SEQUENCE_VECTOR(double)
1205 TEST(YAMLIO, TestReadBuiltInTypesDoubleError) {
1206 std::vector<double> seq;
1213 yin.setDiagHandler(suppressErrorMessages);
1216 EXPECT_TRUE(yin.error());
1220 // Test error handling reading built-in Hex8 type
1222 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex8)
1223 TEST(YAMLIO, TestReadBuiltInTypesHex8Error) {
1224 std::vector<Hex8> seq;
1230 yin.setDiagHandler(suppressErrorMessages);
1233 EXPECT_TRUE(yin.error());
1238 // Test error handling reading built-in Hex16 type
1240 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex16)
1241 TEST(YAMLIO, TestReadBuiltInTypesHex16Error) {
1242 std::vector<Hex16> seq;
1248 yin.setDiagHandler(suppressErrorMessages);
1251 EXPECT_TRUE(yin.error());
1255 // Test error handling reading built-in Hex32 type
1257 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex32)
1258 TEST(YAMLIO, TestReadBuiltInTypesHex32Error) {
1259 std::vector<Hex32> seq;
1265 yin.setDiagHandler(suppressErrorMessages);
1268 EXPECT_TRUE(yin.error());
1272 // Test error handling reading built-in Hex64 type
1274 LLVM_YAML_IS_SEQUENCE_VECTOR(Hex64)
1275 TEST(YAMLIO, TestReadBuiltInTypesHex64Error) {
1276 std::vector<Hex64> seq;
1279 "- 0xFFEEDDCCBBAA9988\n"
1280 "- 0x12345567890ABCDEF0\n"
1282 yin.setDiagHandler(suppressErrorMessages);
1285 EXPECT_TRUE(yin.error());