PrintTo on WordVector should preserve the fill char

This commit is contained in:
David Neto 2015-11-30 18:10:13 -05:00
parent 5947c40483
commit 590ff131ac
2 changed files with 15 additions and 0 deletions

View File

@ -43,4 +43,17 @@ TEST(MakeVector, Samples) {
EXPECT_THAT(MakeVector("abcde"), Eq(Words{0x64636261, 0x0065}));
}
TEST(WordVectorPrintTo, PreservesFlagsAndFill) {
std::stringstream s;
s << std::setw(4) << std::oct << std::setfill('x') << 8 << " ";
PrintTo(spvtest::WordVector({10, 16}), &s);
// The octal setting and fill character should be preserved
// from before the PrintTo.
// Width is reset after each emission of a regular scalar type.
// So set it explicitly again.
s << std::setw(4) << 9;
EXPECT_THAT(s.str(), Eq("xx10 0x0000000a 0x00000010 xx11"));
}
} // anonymous namespace

View File

@ -100,6 +100,7 @@ class WordVector {
inline void PrintTo(const WordVector& words, ::std::ostream* os) {
size_t count = 0;
const auto saved_flags = os->flags();
const auto saved_fill = os->fill();
for (uint32_t value : words.value()) {
*os << "0x" << std::setw(8) << std::setfill('0') << std::hex << value
<< " ";
@ -108,6 +109,7 @@ inline void PrintTo(const WordVector& words, ::std::ostream* os) {
}
}
os->flags(saved_flags);
os->fill(saved_fill);
}
// Returns a vector of words representing a single instruction with the