|
7 | 7 | //
|
8 | 8 | //===----------------------------------------------------------------------===//
|
9 | 9 |
|
| 10 | +#include "llvm/ADT/StringRef.h" |
10 | 11 | #include "llvm/ADT/Twine.h"
|
11 | 12 | #include "llvm/Support/Casting.h"
|
12 | 13 | #include "llvm/Support/Endian.h"
|
@@ -2450,122 +2451,34 @@ TEST(YAMLIO, TestCustomMappingStruct) {
|
2450 | 2451 | EXPECT_EQ(4, y["bar"].bar);
|
2451 | 2452 | }
|
2452 | 2453 |
|
2453 |
| -TEST(YAMLIO, InvalidInput) { |
2454 |
| - // polluting 1 value in the sequence |
2455 |
| - Input yin("---\n- foo: 3\n bar: 5\n1\n- foo: 3\n bar: 5\n...\n"); |
2456 |
| - std::vector<FooBar> Data; |
2457 |
| - yin >> Data; |
2458 |
| - EXPECT_TRUE((bool)yin.error()); |
2459 |
| -} |
2460 |
| - |
2461 |
| -TEST(YAMLIO, TestEscapedSingleQuote) { |
2462 |
| - std::string Id = "@abc@"; |
2463 |
| - |
2464 |
| - std::string out; |
2465 |
| - llvm::raw_string_ostream ostr(out); |
2466 |
| - Output xout(ostr, nullptr, 0); |
2467 |
| - |
2468 |
| - llvm::yaml::EmptyContext Ctx; |
2469 |
| - yamlize(xout, Id, true, Ctx); |
2470 |
| - |
2471 |
| - ostr.flush(); |
2472 |
| - EXPECT_EQ("'@abc@'", out); |
2473 |
| -} |
2474 |
| - |
2475 |
| -TEST(YAMLIO, TestEscapedNoQuote) { |
2476 |
| - std::string Id = "abc/"; |
2477 |
| - |
2478 |
| - std::string out; |
2479 |
| - llvm::raw_string_ostream ostr(out); |
2480 |
| - Output xout(ostr, nullptr, 0); |
2481 |
| - |
2482 |
| - llvm::yaml::EmptyContext Ctx; |
2483 |
| - yamlize(xout, Id, true, Ctx); |
2484 |
| - |
2485 |
| - ostr.flush(); |
2486 |
| - EXPECT_EQ("abc/", out); |
2487 |
| -} |
2488 |
| - |
2489 |
| -TEST(YAMLIO, TestEscapedDoubleQuoteNonPrintable) { |
2490 |
| - std::string Id = "\01@abc@"; |
2491 |
| - |
2492 |
| - std::string out; |
2493 |
| - llvm::raw_string_ostream ostr(out); |
2494 |
| - Output xout(ostr, nullptr, 0); |
2495 |
| - |
2496 |
| - llvm::yaml::EmptyContext Ctx; |
2497 |
| - yamlize(xout, Id, true, Ctx); |
2498 |
| - |
2499 |
| - ostr.flush(); |
2500 |
| - EXPECT_EQ("\"\\x01@abc@\"", out); |
2501 |
| -} |
2502 |
| - |
2503 |
| -TEST(YAMLIO, TestEscapedDoubleQuoteInsideSingleQuote) { |
2504 |
| - std::string Id = "abc\"fdf"; |
2505 |
| - |
2506 |
| - std::string out; |
2507 |
| - llvm::raw_string_ostream ostr(out); |
2508 |
| - Output xout(ostr, nullptr, 0); |
2509 |
| - |
2510 |
| - llvm::yaml::EmptyContext Ctx; |
2511 |
| - yamlize(xout, Id, true, Ctx); |
2512 |
| - |
2513 |
| - ostr.flush(); |
2514 |
| - EXPECT_EQ("'abc\"fdf'", out); |
2515 |
| -} |
2516 |
| - |
2517 |
| -TEST(YAMLIO, TestEscapedDoubleQuoteInsideDoubleQuote) { |
2518 |
| - std::string Id = "\01bc\"fdf"; |
2519 |
| - |
2520 |
| - std::string out; |
2521 |
| - llvm::raw_string_ostream ostr(out); |
2522 |
| - Output xout(ostr, nullptr, 0); |
2523 |
| - |
2524 |
| - llvm::yaml::EmptyContext Ctx; |
2525 |
| - yamlize(xout, Id, true, Ctx); |
2526 |
| - |
2527 |
| - ostr.flush(); |
2528 |
| - EXPECT_EQ("\"\\x01bc\\\"fdf\"", out); |
2529 |
| -} |
2530 |
| - |
2531 |
| -TEST(YAMLIO, TestEscapedSingleQuoteInsideSingleQuote) { |
2532 |
| - std::string Id = "abc'fdf"; |
2533 |
| - |
2534 |
| - std::string out; |
2535 |
| - llvm::raw_string_ostream ostr(out); |
2536 |
| - Output xout(ostr, nullptr, 0); |
2537 |
| - |
2538 |
| - llvm::yaml::EmptyContext Ctx; |
2539 |
| - yamlize(xout, Id, true, Ctx); |
2540 |
| - |
2541 |
| - ostr.flush(); |
2542 |
| - EXPECT_EQ("'abc''fdf'", out); |
2543 |
| -} |
2544 |
| - |
2545 |
| -TEST(YAMLIO, TestEscapedUTF8SingleQuoteInsideDoubleQuote) { |
2546 |
| - std::string Id = "parameter 'параметр' is unused"; |
2547 |
| - |
2548 |
| - std::string out; |
2549 |
| - llvm::raw_string_ostream ostr(out); |
2550 |
| - Output xout(ostr, nullptr, 0); |
2551 |
| - |
2552 |
| - llvm::yaml::EmptyContext Ctx; |
2553 |
| - yamlize(xout, Id, true, Ctx); |
2554 |
| - |
2555 |
| - ostr.flush(); |
2556 |
| - EXPECT_EQ("\"parameter 'параметр' is unused\"", out); |
2557 |
| -} |
2558 |
| - |
2559 |
| -TEST(YAMLIO, TestEscapedUTF8) { |
2560 |
| - std::string Id = "/*параметр*/"; |
2561 |
| - |
| 2454 | +static void TestEscaped(llvm::StringRef Input, llvm::StringRef Expected) { |
2562 | 2455 | std::string out;
|
2563 | 2456 | llvm::raw_string_ostream ostr(out);
|
2564 | 2457 | Output xout(ostr, nullptr, 0);
|
2565 | 2458 |
|
2566 | 2459 | llvm::yaml::EmptyContext Ctx;
|
2567 |
| - yamlize(xout, Id, true, Ctx); |
| 2460 | + yamlize(xout, Input, true, Ctx); |
2568 | 2461 |
|
2569 | 2462 | ostr.flush();
|
2570 |
| - EXPECT_EQ("\"/*параметр*/\"", out); |
| 2463 | + EXPECT_EQ(Expected, out); |
| 2464 | +} |
| 2465 | + |
| 2466 | +TEST(YAMLIO, TestEscaped) { |
| 2467 | + // Single quote |
| 2468 | + TestEscaped("@abc@", "'@abc@'"); |
| 2469 | + // No quote |
| 2470 | + TestEscaped("abc/", "abc/"); |
| 2471 | + // Double quote non-printable |
| 2472 | + TestEscaped("\01@abc@", "\"\\x01@abc@\""); |
| 2473 | + // Double quote inside single quote |
| 2474 | + TestEscaped("abc\"fdf", "'abc\"fdf'"); |
| 2475 | + // Double quote inside double quote |
| 2476 | + TestEscaped("\01bc\"fdf", "\"\\x01bc\\\"fdf\""); |
| 2477 | + // Single quote inside single quote |
| 2478 | + TestEscaped("abc'fdf", "'abc''fdf'"); |
| 2479 | + // UTF8 |
| 2480 | + TestEscaped("/*параметр*/", "\"/*параметр*/\""); |
| 2481 | + // UTF8 with single quote inside double quote |
| 2482 | + TestEscaped("parameter 'параметр' is unused", |
| 2483 | + "\"parameter 'параметр' is unused\""); |
2571 | 2484 | }
|
0 commit comments