Add EscapeStringOptions and escapeString tests
Change-Id: I86ead2f969c9e03c9edfa51bbc92ee06393fd7d6
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include "escape-string.hh"
|
||||
#include "ansicolor.hh"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
TEST(EscapeString, simple) {
|
||||
auto escaped = escapeString("puppy");
|
||||
ASSERT_EQ(escaped, "\"puppy\"");
|
||||
}
|
||||
|
||||
TEST(EscapeString, escaping) {
|
||||
auto escaped = escapeString("\n\r\t \" \\ ${ooga booga}");
|
||||
ASSERT_EQ(escaped, R"RAW("\n\r\t \" \\ \${ooga booga}")RAW");
|
||||
}
|
||||
|
||||
TEST(EscapeString, maxLength) {
|
||||
auto escaped = escapeString("puppy", {.maxLength = 5});
|
||||
ASSERT_EQ(escaped, "\"puppy\"");
|
||||
|
||||
escaped = escapeString("puppy doggy", {.maxLength = 5});
|
||||
ASSERT_EQ(escaped, "\"puppy\" «6 bytes elided»");
|
||||
}
|
||||
|
||||
TEST(EscapeString, ansiColors) {
|
||||
auto escaped = escapeString("puppy doggy", {.maxLength = 5, .outputAnsiColors = true});
|
||||
ASSERT_EQ(escaped, ANSI_MAGENTA "\"puppy\" " ANSI_FAINT "«6 bytes elided»" ANSI_NORMAL);
|
||||
}
|
||||
|
||||
TEST(EscapeString, escapeNonPrinting) {
|
||||
auto escaped = escapeString("puppy\u0005doggy", {.escapeNonPrinting = true});
|
||||
ASSERT_EQ(escaped, "\"puppy\\x05doggy\"");
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
@@ -39,6 +39,7 @@ libutil_tests_sources = files(
|
||||
'libutil/closure.cc',
|
||||
'libutil/compression.cc',
|
||||
'libutil/config.cc',
|
||||
'libutil/escape-string.cc',
|
||||
'libutil/git.cc',
|
||||
'libutil/hash.cc',
|
||||
'libutil/hilite.cc',
|
||||
|
||||
Reference in New Issue
Block a user