if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {
yamlize(*this, Val, Required);
this->postflightKey(SaveInfo);
+ } else if (UseDefault) {
+ Val = T();
}
}
}
}
+struct FooBarOptional {
+ int Foo;
+ int Bar;
+};
+
+namespace llvm {
+namespace yaml {
+template <> struct MappingTraits<FooBarOptional> {
+ static void mapping(IO &YamlIO, FooBarOptional &Obj) {
+ YamlIO.mapRequired("foo", Obj.Foo);
+ YamlIO.mapOptional("bar", Obj.Bar);
+ }
+};
+}
+}
//
// Test the reading of a yaml mapping
}
}
+TEST(YAMLIO, TestMapReadOptional) {
+ FooBarOptional Doc;
+ Doc.Bar = 42;
+ {
+ Input In("---\nfoo: 3\n...\n");
+ In >> Doc;
+
+ EXPECT_FALSE(In.error());
+ EXPECT_EQ(Doc.Foo, 3);
+ EXPECT_EQ(Doc.Bar, 0);
+ }
+}
+
TEST(YAMLIO, TestMalformedMapRead) {
FooBar doc;
Input yin("{foo: 3; bar: 5}", nullptr, suppressErrorMessages);