14 #include <spdlog/sinks/ostream_sink.h>
17 namespace test_utils {
20 auto const length =
text.size();
22 auto const num_whitespaces = length -
text.size();
23 assert(num_whitespaces <= std::numeric_limits<int>::max());
24 return static_cast<int>(num_whitespaces);
56 std::string indented_text;
57 int num_whitespaces = 0;
60 std::stringstream stream(
text);
61 std::string
indent(4 * indent_level,
' ');
63 while (std::getline(stream, line)) {
72 if (!
is_empty(line.substr(0, num_whitespaces))) {
73 throw std::runtime_error(
"Test nmodl input not correctly formatted");
76 line.erase(0, num_whitespaces);
77 indented_text +=
indent + line;
80 if (!stream.eof() && flag) {
81 indented_text +=
"\n";
90 auto capture_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(*
capture_stream);
91 auto test_logger = std::make_shared<spdlog::logger>(
"TEST_LOGGER", capture_sink);
92 test_logger->set_pattern(
"[%n] [%l] :: %v");
std::shared_ptr< std::ostringstream > capture_stream
std::string output() const
nmodl::logger_type original_logger
static std::string ltrim(std::string text)
static std::string trim(std::string text)
int count_leading_spaces(std::string text)
bool is_empty(const std::string &text)
check if string has only whitespaces
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
encapsulates code generation backend implementations
Implement logger based on spdlog library.
Implement string manipulation functions.