diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-06-17 23:26:01 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-06-17 23:26:01 +0000 |
commit | 376fc708daf6d1ba4d66c77c42c8654f90d06c03 (patch) | |
tree | dfb908d7d453d4e784a21787a78fea5c9c6a52b9 /llvm/unittests/Support | |
parent | 4d04afbb61e6027f51049c5f4c09d65c2b32820b (diff) | |
download | bcm5719-llvm-376fc708daf6d1ba4d66c77c42c8654f90d06c03.tar.gz bcm5719-llvm-376fc708daf6d1ba4d66c77c42c8654f90d06c03.zip |
YAML: Assign a value returned by the default constructor to the value in an optional mapping.
This commit ensures that a value that's passed into YAML's IO mapOptional method
is going to be assigned a value returned by the default constructor for that
value's type when the appropriate key is not present in the YAML mapping.
Reviewers: Duncan P. N. Exon Smith
Differential Revision: http://reviews.llvm.org/D10492
llvm-svn: 239972
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/YAMLIOTest.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp index e7affa1698d..0c791b7a020 100644 --- a/llvm/unittests/Support/YAMLIOTest.cpp +++ b/llvm/unittests/Support/YAMLIOTest.cpp @@ -68,6 +68,21 @@ namespace yaml { } } +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 @@ -93,6 +108,19 @@ TEST(YAMLIO, TestMapRead) { } } +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); |