summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/YAMLIOTest.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2013-08-15 23:17:53 +0000
committerAaron Ballman <aaron@aaronballman.com>2013-08-15 23:17:53 +0000
commit0e63e53da1b144c9a1b8752db3215c55f39446d1 (patch)
tree2f90c575f637e27c0c0792e1c93f168537e465ae /llvm/unittests/Support/YAMLIOTest.cpp
parent1de76773bc3b0ac640d03104680659b99dab18cf (diff)
downloadbcm5719-llvm-0e63e53da1b144c9a1b8752db3215c55f39446d1.tar.gz
bcm5719-llvm-0e63e53da1b144c9a1b8752db3215c55f39446d1.zip
Tighten up the yamilizer so it stops eliding empty sequences if the embedded empty sequence is the first key/value in a map which is itself in a sequence.
Patch with help from Nick Kledzik. llvm-svn: 188508
Diffstat (limited to 'llvm/unittests/Support/YAMLIOTest.cpp')
-rw-r--r--llvm/unittests/Support/YAMLIOTest.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index 0993d8c0b55..eedc5842b63 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -1297,3 +1297,66 @@ TEST(YAMLIO, TestReadBuiltInTypesHex64Error) {
EXPECT_TRUE(yin.error());
}
+struct OptionalTest {
+ std::vector<int> Numbers;
+};
+
+struct OptionalTestSeq {
+ std::vector<OptionalTest> Tests;
+};
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(OptionalTest);
+namespace llvm {
+namespace yaml {
+ template <>
+ struct MappingTraits<OptionalTest> {
+ static void mapping(IO& IO, OptionalTest &OT) {
+ IO.mapOptional("Numbers", OT.Numbers);
+ }
+ };
+
+ template <>
+ struct MappingTraits<OptionalTestSeq> {
+ static void mapping(IO &IO, OptionalTestSeq &OTS) {
+ IO.mapOptional("Tests", OTS.Tests);
+ }
+ };
+}
+}
+
+TEST(YAMLIO, SequenceElideTest) {
+ // Test that writing out a purely optional structure with its fields set to
+ // default followed by other data is properly read back in.
+ OptionalTestSeq Seq;
+ OptionalTest One, Two, Three, Four;
+ int N[] = {1, 2, 3};
+ Three.Numbers.assign(N, N + 3);
+ Seq.Tests.push_back(One);
+ Seq.Tests.push_back(Two);
+ Seq.Tests.push_back(Three);
+ Seq.Tests.push_back(Four);
+
+ std::string intermediate;
+ {
+ llvm::raw_string_ostream ostr(intermediate);
+ Output yout(ostr);
+ yout << Seq;
+ }
+
+ Input yin(intermediate);
+ OptionalTestSeq Seq2;
+ yin >> Seq2;
+
+ EXPECT_FALSE(yin.error());
+
+ EXPECT_EQ(4UL, Seq2.Tests.size());
+
+ EXPECT_TRUE(Seq2.Tests[0].Numbers.empty());
+ EXPECT_TRUE(Seq2.Tests[1].Numbers.empty());
+
+ EXPECT_EQ(1, Seq2.Tests[2].Numbers[0]);
+ EXPECT_EQ(2, Seq2.Tests[2].Numbers[1]);
+ EXPECT_EQ(3, Seq2.Tests[2].Numbers[2]);
+
+ EXPECT_TRUE(Seq2.Tests[3].Numbers.empty());
+}
OpenPOWER on IntegriCloud