#include <src/string/memory_utils/algorithm.h>
#include <src/string/memory_utils/backends.h>
-#include <sstream>
+#include <string>
+#include <type_traits>
+#include <vector>
namespace __llvm_libc {
static Buffer buffer1;
static Buffer buffer2;
-static std::ostringstream LOG;
+struct Logger {
+ Logger &operator<<(const char *str) {
+ Buffer.append(str);
+ return *this;
+ }
+ Logger &operator<<(char c) {
+ Buffer.push_back(c);
+ return *this;
+ }
+ template <typename Scalar>
+ std::enable_if_t<std::is_integral<Scalar>::value, Logger &>
+ operator<<(Scalar number) {
+ Buffer.append(std::to_string(number));
+ return *this;
+ }
+ const std::string &str() const { return Buffer; }
+
+private:
+ std::string Buffer;
+} LOG;
struct TestBackend {
static constexpr bool IS_BACKEND_TYPE = true;
struct LlvmLibcAlgorithm : public testing::Test {
void SetUp() override {
- LOG = std::ostringstream();
+ LOG = Logger();
LOG << '\n';
}
return trace_.c_str();
}
- const char *stripComments(const char *expected) {
+ const char *stripComments(std::string expected) {
expected_.clear();
- std::stringstream ss(expected);
- std::string line;
- while (std::getline(ss, line, '\n')) {
+ // split expected by lines
+ std::vector<std::string> lines;
+ lines.emplace_back();
+ for (const char c : expected) {
+ if (c == '\n') {
+ lines.emplace_back();
+ } else {
+ lines.back().push_back(c);
+ }
+ }
+ // strip comment for each lines
+ for (const std::string &line : lines) {
const auto pos = line.find('#');
if (pos == std::string::npos) {
expected_ += line;
log.pop_back();
expected_ += log;
}
- expected_ += '\n';
+ if (expected_.back() != '\n')
+ expected_.push_back('\n');
}
return expected_.c_str();
}