Skip to content

Commit

Permalink
fix GetName for empty enums
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Sep 28, 2020
1 parent c027802 commit 08ad358
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 4 additions & 7 deletions clickhouse/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,14 @@ std::string Type::GetName() const {
} else {
result = "Enum16(";
}
for (auto ei = enum_->value_to_name.begin(); ; ) {
for (auto ei = enum_->value_to_name.begin(); ei != enum_->value_to_name.end(); ++ei) {
if (ei != enum_->value_to_name.begin()) {
result += ", ";
}
result += "'";
result += ei->second;
result += "' = ";
result += std::to_string(ei->first);

if (++ei != enum_->value_to_name.end()) {
result += ", ";
} else {
break;
}
}
result += ")";
return result;
Expand Down
9 changes: 9 additions & 0 deletions ut/types_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ TEST(TypesCase, TypeName) {
Type::CreateString()})->GetName(),
"Tuple(Int32, String)"
);

ASSERT_EQ(
Type::CreateEnum8({{"One", 1}})->GetName(),
"Enum8('One' = 1)"
);
ASSERT_EQ(
Type::CreateEnum8({})->GetName(),
"Enum8()"
);
}

TEST(TypesCase, NullableType) {
Expand Down

0 comments on commit 08ad358

Please sign in to comment.