1 #include "../../../tests/catch2/catch.hpp"
4 #include "../ttyIOUtils.hpp"
9 SCENARIO(
"A string needs to be telnet-ified",
"[libMagAOX::tty]" )
11 GIVEN(
"Strings in non-telnet format with single chars")
13 std::string telnetStr, inputStr;
16 WHEN(
"A single \\r char at end")
21 REQUIRE(telnetStr ==
"test\r\n");
24 WHEN(
"A single \\n char at end")
29 REQUIRE(telnetStr ==
"test\r\n");
32 WHEN(
"A single \\r char in the middle")
34 inputStr =
"test\rtest";
37 REQUIRE(telnetStr ==
"test\r\ntest");
40 WHEN(
"A single \\n char in the middle")
42 inputStr =
"test\ntest";
45 REQUIRE(telnetStr ==
"test\r\ntest");
48 WHEN(
"A single \\r char at the beginning")
53 REQUIRE(telnetStr ==
"\r\ntest");
56 WHEN(
"A single \\n char at the beginning")
61 REQUIRE(telnetStr ==
"\r\ntest");
65 GIVEN(
"Strings in non-telnet format with two split chars")
67 std::string telnetStr, inputStr;
70 WHEN(
"A single \\r char at end, a \\n at beginning")
72 inputStr =
"\ntest\r";
75 REQUIRE(telnetStr ==
"\r\ntest\r\n");
78 WHEN(
"A single \\n char at end, a \\r at beginning")
80 inputStr =
"\rtest\n";
83 REQUIRE(telnetStr ==
"\r\ntest\r\n");
86 WHEN(
"A single \\r char in the middle, a \n at beginning")
88 inputStr =
"\ntest\rtset";
91 REQUIRE(telnetStr ==
"\r\ntest\r\ntset");
94 WHEN(
"A single \\n char in the middle, a \r at beginning")
96 inputStr =
"\rtest\ntest";
99 REQUIRE(telnetStr ==
"\r\ntest\r\ntest");
102 WHEN(
"A single \\r char at the beginning, a \\r at end")
104 inputStr =
"\rtest\r";
107 REQUIRE(telnetStr ==
"\r\ntest\r\n");
110 WHEN(
"A single \\n char at the beginning, a \\n at end")
112 inputStr =
"\ntest\r\n";
115 REQUIRE(telnetStr ==
"\r\ntest\r\n");
119 GIVEN(
"Strings already in telnet format")
121 std::string telnetStr, inputStr;
124 WHEN(
"A \\r\\n at end")
126 inputStr =
"test\r\n";
129 REQUIRE(telnetStr ==
"test\r\n");
132 WHEN(
"A \\r\\n char in the middle")
134 inputStr =
"test\r\ntest";
137 REQUIRE(telnetStr ==
"test\r\ntest");
140 WHEN(
"A \\r\\n char at the beginning")
142 inputStr =
"\r\ntest";
145 REQUIRE(telnetStr ==
"\r\ntest");
int telnetCRLF(std::string &telnetStr, const std::string &inputStr)
Replace lone \r and \n with \r\n for telnet-ness.
SCENARIO("A string needs to be telnet-ified", "[libMagAOX::tty]")