summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2017-12-21 17:14:13 +0000
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2017-12-21 17:14:13 +0000
commit79085a17d46b0876073cd484370c960cf1dff544 (patch)
treeb1f28a81b40e2a558e93c81014208dfa2c01fb22 /unittests
parentdd3d1e98e0e74721a0ae9493a41fbe3ec2dfbb20 (diff)
[YAML] Refactor escaping unittests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/YAMLIOTest.cpp135
1 files changed, 24 insertions, 111 deletions
diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp
index 650b02cdea9..914b22f0fcd 100644
--- a/unittests/Support/YAMLIOTest.cpp
+++ b/unittests/Support/YAMLIOTest.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Endian.h"
@@ -2450,122 +2451,34 @@ TEST(YAMLIO, TestCustomMappingStruct) {
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");
- std::vector<FooBar> Data;
- yin >> Data;
- EXPECT_TRUE((bool)yin.error());
-}
-
-TEST(YAMLIO, TestEscapedSingleQuote) {
- std::string Id = "@abc@";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("'@abc@'", out);
-}
-
-TEST(YAMLIO, TestEscapedNoQuote) {
- std::string Id = "abc/";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("abc/", out);
-}
-
-TEST(YAMLIO, TestEscapedDoubleQuoteNonPrintable) {
- std::string Id = "\01@abc@";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("\"\\x01@abc@\"", out);
-}
-
-TEST(YAMLIO, TestEscapedDoubleQuoteInsideSingleQuote) {
- std::string Id = "abc\"fdf";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("'abc\"fdf'", out);
-}
-
-TEST(YAMLIO, TestEscapedDoubleQuoteInsideDoubleQuote) {
- std::string Id = "\01bc\"fdf";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("\"\\x01bc\\\"fdf\"", out);
-}
-
-TEST(YAMLIO, TestEscapedSingleQuoteInsideSingleQuote) {
- std::string Id = "abc'fdf";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("'abc''fdf'", out);
-}
-
-TEST(YAMLIO, TestEscapedUTF8SingleQuoteInsideDoubleQuote) {
- std::string Id = "parameter 'параметр' is unused";
-
- std::string out;
- llvm::raw_string_ostream ostr(out);
- Output xout(ostr, nullptr, 0);
-
- llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
-
- ostr.flush();
- EXPECT_EQ("\"parameter 'параметр' is unused\"", out);
-}
-
-TEST(YAMLIO, TestEscapedUTF8) {
- std::string Id = "/*параметр*/";
-
+static void TestEscaped(llvm::StringRef Input, llvm::StringRef Expected) {
std::string out;
llvm::raw_string_ostream ostr(out);
Output xout(ostr, nullptr, 0);
llvm::yaml::EmptyContext Ctx;
- yamlize(xout, Id, true, Ctx);
+ yamlize(xout, Input, true, Ctx);
ostr.flush();
- EXPECT_EQ("\"/*параметр*/\"", out);
+ EXPECT_EQ(Expected, out);
+}
+
+TEST(YAMLIO, TestEscaped) {
+ // Single quote
+ TestEscaped("@abc@", "'@abc@'");
+ // No quote
+ TestEscaped("abc/", "abc/");
+ // Double quote non-printable
+ TestEscaped("\01@abc@", "\"\\x01@abc@\"");
+ // Double quote inside single quote
+ TestEscaped("abc\"fdf", "'abc\"fdf'");
+ // Double quote inside double quote
+ TestEscaped("\01bc\"fdf", "\"\\x01bc\\\"fdf\"");
+ // Single quote inside single quote
+ TestEscaped("abc'fdf", "'abc''fdf'");
+ // UTF8
+ TestEscaped("/*параметр*/", "\"/*параметр*/\"");
+ // UTF8 with single quote inside double quote
+ TestEscaped("parameter 'параметр' is unused",
+ "\"parameter 'параметр' is unused\"");
}