summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-04-10 07:37:33 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-04-10 07:37:33 +0000
commit878657074a3d65262d4c010dc2261ea688f19e8c (patch)
tree7c36abbfa347bd998b0a993f3875e9760d029fa5 /unittests
parentfb52dba011ae1785654f2f3a3cedef2119789dc2 (diff)
downloadllvm-878657074a3d65262d4c010dc2261ea688f19e8c.tar.gz
llvm-878657074a3d65262d4c010dc2261ea688f19e8c.tar.bz2
llvm-878657074a3d65262d4c010dc2261ea688f19e8c.tar.xz
YAMLIO: Allow scalars to dictate quotation rules
Introduce ScalarTraits::mustQuote which determines whether or not a StringRef needs quoting before it is acceptable to output. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205955 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/YAMLIOTest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp
index 0f1951f4fc..cf95532141 100644
--- a/unittests/Support/YAMLIOTest.cpp
+++ b/unittests/Support/YAMLIOTest.cpp
@@ -303,12 +303,22 @@ struct StringTypes {
llvm::StringRef str4;
llvm::StringRef str5;
llvm::StringRef str6;
+ llvm::StringRef str7;
+ llvm::StringRef str8;
+ llvm::StringRef str9;
+ llvm::StringRef str10;
+ llvm::StringRef str11;
std::string stdstr1;
std::string stdstr2;
std::string stdstr3;
std::string stdstr4;
std::string stdstr5;
std::string stdstr6;
+ std::string stdstr7;
+ std::string stdstr8;
+ std::string stdstr9;
+ std::string stdstr10;
+ std::string stdstr11;
};
namespace llvm {
@@ -322,12 +332,22 @@ namespace yaml {
io.mapRequired("str4", st.str4);
io.mapRequired("str5", st.str5);
io.mapRequired("str6", st.str6);
+ io.mapRequired("str7", st.str7);
+ io.mapRequired("str8", st.str8);
+ io.mapRequired("str9", st.str9);
+ io.mapRequired("str10", st.str10);
+ io.mapRequired("str11", st.str11);
io.mapRequired("stdstr1", st.stdstr1);
io.mapRequired("stdstr2", st.stdstr2);
io.mapRequired("stdstr3", st.stdstr3);
io.mapRequired("stdstr4", st.stdstr4);
io.mapRequired("stdstr5", st.stdstr5);
io.mapRequired("stdstr6", st.stdstr6);
+ io.mapRequired("stdstr7", st.stdstr7);
+ io.mapRequired("stdstr8", st.stdstr8);
+ io.mapRequired("stdstr9", st.stdstr9);
+ io.mapRequired("stdstr10", st.stdstr10);
+ io.mapRequired("stdstr11", st.stdstr11);
}
};
}
@@ -343,12 +363,22 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
map.str4 = "@ddd";
map.str5 = "";
map.str6 = "0000000004000000";
+ map.str7 = "true";
+ map.str8 = "FALSE";
+ map.str9 = "~";
+ map.str10 = "0.2e20";
+ map.str11 = "0x30";
map.stdstr1 = "'eee";
map.stdstr2 = "\"fff";
map.stdstr3 = "`ggg";
map.stdstr4 = "@hhh";
map.stdstr5 = "";
map.stdstr6 = "0000000004000000";
+ map.stdstr7 = "true";
+ map.stdstr8 = "FALSE";
+ map.stdstr9 = "~";
+ map.stdstr10 = "0.2e20";
+ map.stdstr11 = "0x30";
llvm::raw_string_ostream ostr(intermediate);
Output yout(ostr);
@@ -362,6 +392,11 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
EXPECT_NE(llvm::StringRef::npos, flowOut.find("'@ddd'"));
EXPECT_NE(llvm::StringRef::npos, flowOut.find("''\n"));
EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0000000004000000'\n"));
+ EXPECT_NE(llvm::StringRef::npos, flowOut.find("'true'\n"));
+ EXPECT_NE(llvm::StringRef::npos, flowOut.find("'FALSE'\n"));
+ EXPECT_NE(llvm::StringRef::npos, flowOut.find("'~'\n"));
+ EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0.2e20'\n"));
+ EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0x30'\n"));
EXPECT_NE(std::string::npos, flowOut.find("'''eee"));
EXPECT_NE(std::string::npos, flowOut.find("'\"fff'"));
EXPECT_NE(std::string::npos, flowOut.find("'`ggg'"));
@@ -612,6 +647,7 @@ namespace yaml {
return "malformed by";
}
}
+ static bool mustQuote(StringRef) { return true; }
};
}
}
@@ -673,6 +709,8 @@ namespace yaml {
value = n;
return StringRef();
}
+
+ static bool mustQuote(StringRef) { return false; }
};
}
}