TEST(unescapeJsonCommandLine, UnescapesBackslashCharacters) { std::vector<std::string> Backslash = unescapeJsonCommandLine("a\\\\\\\\"); ASSERT_EQ(1ul, Backslash.size()); EXPECT_EQ("a\\", Backslash[0]); std::vector<std::string> Quote = unescapeJsonCommandLine("a\\\\\\\""); ASSERT_EQ(1ul, Quote.size()); EXPECT_EQ("a\"", Quote[0]); }
TEST(unescapeJsonCommandLine, ParsesQuotedStringWithoutClosingQuote) { std::vector<std::string> Unclosed = unescapeJsonCommandLine("\\\"abc"); ASSERT_EQ(1ul, Unclosed.size()); EXPECT_EQ("abc", Unclosed[0]); std::vector<std::string> Empty = unescapeJsonCommandLine("\\\""); ASSERT_EQ(1ul, Empty.size()); EXPECT_EQ("", Empty[0]); }
TEST(unescapeJsonCommandLine, ParsesStringsWithoutSpacesIntoSingleArgument) { std::vector<std::string> QuotedNoSpaces = unescapeJsonCommandLine( "\\\"a\\\"\\\"b\\\""); ASSERT_EQ(1ul, QuotedNoSpaces.size()); EXPECT_EQ("ab", QuotedNoSpaces[0]); std::vector<std::string> MixedNoSpaces = unescapeJsonCommandLine( "\\\"a\\\"bcd\\\"ef\\\"\\\"\\\"\\\"g\\\""); ASSERT_EQ(1ul, MixedNoSpaces.size()); EXPECT_EQ("abcdefg", MixedNoSpaces[0]); }
TEST(unescapeJsonCommandLine, AllowsMultipleQuotedArguments) { std::vector<std::string> Result = unescapeJsonCommandLine( " \\\" a \\\" \\\" b \\\" "); ASSERT_EQ(2ul, Result.size()); EXPECT_EQ(" a ", Result[0]); EXPECT_EQ(" b ", Result[1]); }
TEST(unescapeJsonCommandLine, SplitsOnSpaces) { std::vector<std::string> Result = unescapeJsonCommandLine("a b c"); ASSERT_EQ(3ul, Result.size()); EXPECT_EQ("a", Result[0]); EXPECT_EQ("b", Result[1]); EXPECT_EQ("c", Result[2]); }
TEST(unescapeJsonCommandLine, ParsesMultipleArgumentsWithEscapedCharacters) { std::vector<std::string> Result = unescapeJsonCommandLine( " \\\\\\\" \\\"a \\\\\\\" b \\\" \\\"and\\\\\\\\c\\\" \\\\\\\""); ASSERT_EQ(4ul, Result.size()); EXPECT_EQ("\"", Result[0]); EXPECT_EQ("a \" b ", Result[1]); EXPECT_EQ("and\\c", Result[2]); EXPECT_EQ("\"", Result[3]); }
TEST(unescapeJsonCommandLine, ParsesEscapedQuotesInQuotedStrings) { std::vector<std::string> Result = unescapeJsonCommandLine( "\\\"\\\\\\\"\\\""); ASSERT_EQ(1ul, Result.size()); EXPECT_EQ("\"", Result[0]); }
TEST(unescapeJsonCommandLine, AllowsEmptyArgumentsInQuotes) { std::vector<std::string> Result = unescapeJsonCommandLine( "\\\"\\\"\\\"\\\""); ASSERT_EQ(1ul, Result.size()); EXPECT_TRUE(Result[0].empty()) << Result[0]; }
TEST(unescapeJsonCommandLine, DoesNotMungeSpacesBetweenQuotes) { std::vector<std::string> Result = unescapeJsonCommandLine("\\\" a b \\\""); ASSERT_EQ(1ul, Result.size()); EXPECT_EQ(" a b ", Result[0]); }
TEST(unescapeJsonCommandLine, MungesMultipleSpaces) { std::vector<std::string> Result = unescapeJsonCommandLine(" a b "); ASSERT_EQ(2ul, Result.size()); EXPECT_EQ("a", Result[0]); EXPECT_EQ("b", Result[1]); }
TEST(unescapeJsonCommandLine, ReturnsEmptyArrayOnEmptyString) { std::vector<std::string> Result = unescapeJsonCommandLine(""); EXPECT_TRUE(Result.empty()); }
TEST(unescapeJsonCommandLine, ParsesSingleQuotedString) { std::vector<std::string> Args = unescapeJsonCommandLine("a'\\\\b \\\"c\\\"'"); ASSERT_EQ(1ul, Args.size()); EXPECT_EQ("a\\b \"c\"", Args[0]); }