From 5ec2efb68677ccb5fd91c295cf6ae6039652ac73 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 22 Mar 2024 16:41:42 -0700 Subject: Move `DebugChar` into its own file Change-Id: Ia40549e5d0b78ece8dd0722c3a5a032b9915f24b --- .../libutil-support/tests/cli-literate-parser.cc | 4 ++-- tests/unit/libutil-support/tests/debug-char.hh | 24 ---------------------- .../libutil-support/tests/terminal-code-eater.cc | 6 +++--- 3 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 tests/unit/libutil-support/tests/debug-char.hh (limited to 'tests/unit') diff --git a/tests/unit/libutil-support/tests/cli-literate-parser.cc b/tests/unit/libutil-support/tests/cli-literate-parser.cc index b3830e32c..08ebddebc 100644 --- a/tests/unit/libutil-support/tests/cli-literate-parser.cc +++ b/tests/unit/libutil-support/tests/cli-literate-parser.cc @@ -1,6 +1,6 @@ #include "cli-literate-parser.hh" #include "libexpr/print.hh" -#include "debug-char.hh" +#include "escape-char.hh" #include "types.hh" #include "util.hh" #include @@ -77,7 +77,7 @@ CLILiterateParser::CLILiterateParser(std::string prompt, size_t indent) void CLILiterateParser::feed(char c) { if constexpr (DEBUG_PARSER) { - std::cout << stateDebug(state_) << " " << DebugChar{c} << "\n"; + std::cout << stateDebug(state_) << " " << MaybeHexEscapedChar{c} << "\n"; } if (c == '\n') { diff --git a/tests/unit/libutil-support/tests/debug-char.hh b/tests/unit/libutil-support/tests/debug-char.hh deleted file mode 100644 index 765d8553f..000000000 --- a/tests/unit/libutil-support/tests/debug-char.hh +++ /dev/null @@ -1,24 +0,0 @@ -///@file -#include -#include - -namespace nix { - -struct DebugChar -{ - char c; -}; - -inline std::ostream & operator<<(std::ostream & s, DebugChar c) -{ - boost::io::ios_flags_saver _ifs(s); - - if (isprint(c.c)) { - s << static_cast(c.c); - } else { - s << std::hex << "0x" << (static_cast(c.c) & 0xff); - } - return s; -} - -} diff --git a/tests/unit/libutil-support/tests/terminal-code-eater.cc b/tests/unit/libutil-support/tests/terminal-code-eater.cc index 51e1d565e..ad05ed1f6 100644 --- a/tests/unit/libutil-support/tests/terminal-code-eater.cc +++ b/tests/unit/libutil-support/tests/terminal-code-eater.cc @@ -1,5 +1,5 @@ #include "terminal-code-eater.hh" -#include "debug-char.hh" +#include "escape-char.hh" #include #include #include @@ -14,7 +14,7 @@ void TerminalCodeEater::feed(char c, std::function on_char) auto isIntermediateChar = [](char v) -> bool { return v >= 0x20 && v <= 0x2f; }; auto isFinalChar = [](char v) -> bool { return v >= 0x40 && v <= 0x7e; }; if constexpr (DEBUG_EATER) { - std::cerr << "eater" << DebugChar{c} << "\n"; + std::cerr << "eater" << MaybeHexEscapedChar{c} << "\n"; } switch (state) { @@ -28,7 +28,7 @@ void TerminalCodeEater::feed(char c, std::function on_char) return; } if constexpr (DEBUG_EATER) { - std::cerr << "eater uneat" << DebugChar{c} << "\n"; + std::cerr << "eater uneat" << MaybeHexEscapedChar{c} << "\n"; } on_char(c); break; -- cgit v1.2.3