Skip to content

Commit cc004ba

Browse files
committed
Add proper printing for pointer types
1 parent 652f07d commit cc004ba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/test.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#include <sstream>
44

55
std::string Value::print() const {
6-
return "static_cast<" + type.print() + ">(" + std::to_string(value) + ")";
6+
return type.printValue(std::to_string(value));
77
}
8+
89
std::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+
1829
std::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

src/test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

2930
struct TestSignature {

0 commit comments

Comments
 (0)