Fixed hex and oct emitting (it now adds the 0x or 0 prefix)

This commit is contained in:
Jesse Beder
2012-01-13 00:00:11 -06:00
parent a441e1a14c
commit d772361f15
2 changed files with 14 additions and 1 deletions

View File

@@ -670,9 +670,11 @@ namespace YAML
str << std::dec; str << std::dec;
break; break;
case Hex: case Hex:
str << "0x";
str << std::hex; str << std::hex;
break; break;
case Oct: case Oct:
str << "0";
str << std::oct; str << std::oct;
break; break;
default: default:

View File

@@ -901,6 +901,16 @@ namespace Test
desiredOutput = "key: \"-\""; desiredOutput = "key: \"-\"";
} }
void HexAndOct(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Flow << YAML::BeginSeq;
out << 31;
out << YAML::Hex << 31;
out << YAML::Oct << 31;
out << YAML::EndSeq;
desiredOutput = "[31, 0x1f, 037]";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
// incorrect emitting // incorrect emitting
@@ -1123,6 +1133,7 @@ namespace Test
RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed, total); RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed, total);
RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total); RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total);
RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total); RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total);
RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);