diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2017-01-04 03:51:36 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-01-04 03:51:36 +0000 |
commit | 87dd2ab000000a0ee6c643293caf105710327c8b (patch) | |
tree | 9206f4da51aefc9e0b81f3743cb7f61ddfede9fc /llvm/unittests/Support | |
parent | 5f0793b36cfeffe17e31ccc62597034c9da2b6b8 (diff) | |
download | bcm5719-llvm-87dd2ab000000a0ee6c643293caf105710327c8b.tar.gz bcm5719-llvm-87dd2ab000000a0ee6c643293caf105710327c8b.zip |
Support: Add YAML I/O support for custom mappings.
This will be used to YAMLify parts of the module summary.
Differential Revision: https://reviews.llvm.org/D28014
llvm-svn: 290935
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/YAMLIOTest.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp index c3e18d33235..dc7c5d47cba 100644 --- a/llvm/unittests/Support/YAMLIOTest.cpp +++ b/llvm/unittests/Support/YAMLIOTest.cpp @@ -2369,6 +2369,68 @@ TEST(YAMLIO, TestMapWithContext) { out.clear(); } +LLVM_YAML_IS_STRING_MAP(int) + +TEST(YAMLIO, TestCustomMapping) { + std::map<std::string, int> x; + x["foo"] = 1; + x["bar"] = 2; + + std::string out; + llvm::raw_string_ostream ostr(out); + Output xout(ostr, nullptr, 0); + + xout << x; + ostr.flush(); + EXPECT_EQ("---\n" + "bar: 2\n" + "foo: 1\n" + "...\n", + out); + + Input yin(out); + std::map<std::string, int> y; + yin >> y; + EXPECT_EQ(2ul, y.size()); + EXPECT_EQ(1, y["foo"]); + EXPECT_EQ(2, y["bar"]); +} + +LLVM_YAML_IS_STRING_MAP(FooBar) + +TEST(YAMLIO, TestCustomMappingStruct) { + std::map<std::string, FooBar> x; + x["foo"].foo = 1; + x["foo"].bar = 2; + x["bar"].foo = 3; + x["bar"].bar = 4; + + std::string out; + llvm::raw_string_ostream ostr(out); + Output xout(ostr, nullptr, 0); + + xout << x; + ostr.flush(); + EXPECT_EQ("---\n" + "bar: \n" + " foo: 3\n" + " bar: 4\n" + "foo: \n" + " foo: 1\n" + " bar: 2\n" + "...\n", + out); + + Input yin(out); + std::map<std::string, FooBar> y; + yin >> y; + EXPECT_EQ(2ul, y.size()); + EXPECT_EQ(1, y["foo"].foo); + EXPECT_EQ(2, y["foo"].bar); + EXPECT_EQ(3, y["bar"].foo); + EXPECT_EQ(4, y["bar"].bar); +} + TEST(YAMLIO, InvalidInput) { // polluting 1 value in the sequence Input yin("---\n- foo: 3\n bar: 5\n1\n- foo: 3\n bar: 5\n...\n"); |