From 590ff131ac4c98f30ce50c9da3778a5c99db6b79 Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 30 Nov 2015 18:10:13 -0500 Subject: [PATCH] PrintTo on WordVector should preserve the fill char --- test/UnitSPIRV.cpp | 13 +++++++++++++ test/UnitSPIRV.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/test/UnitSPIRV.cpp b/test/UnitSPIRV.cpp index fed239d..690f476 100644 --- a/test/UnitSPIRV.cpp +++ b/test/UnitSPIRV.cpp @@ -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 diff --git a/test/UnitSPIRV.h b/test/UnitSPIRV.h index 6d19fa9..a5fb32d 100644 --- a/test/UnitSPIRV.h +++ b/test/UnitSPIRV.h @@ -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 -- 2.7.4