xo-indentlog: fix log_streambuf unit test + string_view operator
This commit is contained in:
parent
480294ae05
commit
67beec4ee4
2 changed files with 16 additions and 7 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "print/quoted_char.hpp"
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <cstring> // e.g. for std::memcpy()
|
||||
#include <cstdint>
|
||||
|
|
@ -71,6 +72,8 @@ namespace xo {
|
|||
|
||||
bool debug_flag() const { return debug_flag_; }
|
||||
|
||||
operator std::basic_string_view<CharT> () const { return std::basic_string_view<CharT>(this->pbase(), this->pptr()); }
|
||||
|
||||
void reset_stream() {
|
||||
char * p_lo = &(this->buf_v_[0]);
|
||||
char * p_hi = p_lo + this->capacity();
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@
|
|||
#include "print/tag.hpp"
|
||||
#include "print/quoted.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
#include <string_view>
|
||||
//#include <sstream>
|
||||
|
||||
namespace ut {
|
||||
using xo::xtag;
|
||||
using xo::scope;
|
||||
using xo::log_streambuf;
|
||||
using std::string_view;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
|
|
@ -68,28 +70,32 @@ namespace ut {
|
|||
log_streambuf<char, std::char_traits<char>> sbuf(z, false);
|
||||
std::ostream ss(&sbuf);
|
||||
|
||||
ss <<"empty log_streambuf";
|
||||
ss << xtag("sbuf.lo", (void*)sbuf.lo());
|
||||
ss << xtag("sbuf.hi", (void*)sbuf.hi());
|
||||
ss << "empty log_streambuf";
|
||||
ss << xtag("sbuf.lo", (void*)nullptr);
|
||||
ss << xtag("sbuf.hi", (void*)nullptr);
|
||||
ss << xtag("sbuf.color_escape_chars", sbuf._color_escape_chars());
|
||||
|
||||
//REQUIRE(sbuf.lo() == sbuf.pbase());
|
||||
|
||||
auto expected = string_view("empty log_streambuf :sbuf.lo 0 :sbuf.hi 0 :sbuf.color_escape_chars 0");
|
||||
|
||||
REQUIRE(string_view(sbuf) == expected);
|
||||
|
||||
/* sbuf size will have been expanded */
|
||||
REQUIRE(sbuf.capacity() == 128);
|
||||
REQUIRE(sbuf.pos() == 82);
|
||||
REQUIRE(sbuf.pos() == expected.size());
|
||||
REQUIRE(sbuf._solpos() == 0);
|
||||
REQUIRE(sbuf.lpos() == 82);
|
||||
REQUIRE(sbuf.lpos() == expected.size());
|
||||
|
||||
// note: log_streambuf doesn't get control on every character
|
||||
|
||||
ss << '\n';
|
||||
|
||||
REQUIRE(sbuf.capacity() == 128);
|
||||
REQUIRE(sbuf.pos() == 83);
|
||||
REQUIRE(sbuf.pos() == expected.size() + 1);
|
||||
REQUIRE(sbuf.lpos() == 0);
|
||||
// note: solpos: updated b/c of call to lazy sbuf.lpos()
|
||||
REQUIRE(sbuf._solpos() == 83);
|
||||
REQUIRE(sbuf._solpos() == expected.size() + 1);
|
||||
}
|
||||
|
||||
// write test cases with some random strings.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue