File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 33#include < sstream>
44
55std::string Value::print () const {
6- return " static_cast< " + type.print () + " >( " + std::to_string (value) + " ) " ;
6+ return type.printValue ( std::to_string (value)) ;
77}
8+
89std::string Type::print () const {
910 if (auto primitiveType = std::get_if<PrimitiveType>(&type)) {
1011 return printPrimitiveType (*primitiveType);
@@ -15,6 +16,16 @@ std::string Type::print() const {
1516 return " <unknown>" ;
1617}
1718
19+ std::string Type::printValue (const std::string& value) const {
20+ if (auto primitiveType = std::get_if<PrimitiveType>(&type)) {
21+ return " static_cast<" + print () + " >(" + value + " )" ;
22+ } else if (auto pointerTo = std::get_if<PointerTo>(&type)) {
23+ return " new " + pointerTo->type ->print () + " {" + pointerTo->type ->printValue (value) + " }" ;
24+ }
25+
26+ return " <unknown>" ;
27+ }
28+
1829std::string printPrimitiveType (PrimitiveType type) {
1930 switch (type) {
2031 case PrimitiveType::CHAR: return " char" ;
@@ -27,7 +38,7 @@ void Test::print(std::ostream &ss) const {
2738 ss << " TEST(" << signature.name << " Test, " << name << " ) {\n " ;
2839 ss << " ASSERT_EQ(" ;
2940 printFunctionCall (ss);
30- ss << " , " << resultMacroName () << " );\n " ;
41+ ss << " , " << signature. returnType . printValue ( resultMacroName () ) << " );\n " ;
3142 ss << " }\n " ;
3243}
3344
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ struct Type {
2424 std::variant<PrimitiveType, PointerTo> type;
2525
2626 [[nodiscard]] std::string print () const ;
27+ [[nodiscard]] std::string printValue (const std::string &value) const ;
2728};
2829
2930struct TestSignature {
You can’t perform that action at this time.
0 commit comments