openMSX
escape_newline_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2#include "escape_newline.hh"
3
4TEST_CASE("escape_newline")
5{
6 SECTION("round trip") {
7 auto test = [](std::string_view s) {
8 auto e = escape_newline::encode(s);
9 auto d = escape_newline::decode(e);
10 CHECK(e.size() >= d.size());
11 CHECK(d == s);
12 };
13 test("");
14 test("bla");
15 test("bla\nbla");
16 test("bla\\bla");
17 test("\n\n\\\\");
18 }
19 SECTION("errors") {
20 // * All inputs are valid for encode().
21 // * But some inputs should normally never be passed to decode()
22 // (as in: they can never have been the result of a prior
23 // encode()).
24 // Nevertheless we try to recover from such inputs.
25
26 // Single backslash at the end -> gets dropped.
27 CHECK(escape_newline::decode("bla\\") == "bla");
28
29 // Normally only "\\" or "\n" should occur, all other "<x>" are
30 // in principle invalid, but we decode them as 'x'
31 CHECK(escape_newline::decode("bl\\a") == "bla");
32 }
33}
void test(const IterableBitSet< N > &s, std::initializer_list< size_t > list)
TEST_CASE("escape_newline")
CHECK(m3==m3)
std::string decode(std::string_view input)
std::string encode(std::string_view input)