Skip to content

Commit

Permalink
Merge pull request #1745 from hzeller/20230223-apply-clang-fixes
Browse files Browse the repository at this point in the history
Apply some automated clang fixes on tests.
  • Loading branch information
hzeller authored Feb 23, 2023
2 parents 64eafaa + bf47acf commit 87315bf
Show file tree
Hide file tree
Showing 28 changed files with 198 additions and 152 deletions.
4 changes: 2 additions & 2 deletions common/analysis/line_linter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using testing::SizeIs;
// Blank lines are considered bad for demonstration purposes.
class BlankLineRule : public LineLintRule {
public:
BlankLineRule() {}
BlankLineRule() = default;

void HandleLine(absl::string_view line) final {
if (line.empty()) {
Expand Down Expand Up @@ -90,7 +90,7 @@ TEST(LineLinterTest, OneRuleRejectsLine) {
// Mock rule that rejects empty files.
class EmptyFileRule : public LineLintRule {
public:
EmptyFileRule() {}
EmptyFileRule() = default;

void HandleLine(absl::string_view line) final { ++lines_; }

Expand Down
2 changes: 1 addition & 1 deletion common/analysis/line_linter_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace verible {
template <>
class LintRunner<LineLintRule> {
public:
explicit LintRunner(std::unique_ptr<LineLintRule> rule) : linter_() {
explicit LintRunner(std::unique_ptr<LineLintRule> rule) {
linter_.AddRule(std::move(rule));
}

Expand Down
8 changes: 2 additions & 6 deletions common/analysis/matcher/matcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,8 @@ TEST(MatcherTest, BindMatcherNested) {
static std::vector<const Symbol*> GetFirstChild(const Symbol& symbol) {
if (symbol.Kind() == SymbolKind::kNode) {
const auto& node = down_cast<const SyntaxTreeNode&>(symbol);

if (node.children().empty()) {
return {};
} else {
return {node.children()[0].get()};
}
if (node.children().empty()) return {};
return {node.children()[0].get()};
}

return {};
Expand Down
2 changes: 1 addition & 1 deletion common/analysis/syntax_tree_linter_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace verible {
template <>
class LintRunner<SyntaxTreeLintRule> {
public:
explicit LintRunner(std::unique_ptr<SyntaxTreeLintRule> rule) : linter_() {
explicit LintRunner(std::unique_ptr<SyntaxTreeLintRule> rule) {
linter_.AddRule(std::move(rule));
}

Expand Down
2 changes: 1 addition & 1 deletion common/analysis/text_structure_linter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using testing::SizeIs;
// Example lint rule that uses raw contents and lines array.
class RequireHelloRule : public TextStructureLintRule {
public:
RequireHelloRule() {}
RequireHelloRule() = default;

void Lint(const TextStructureView& text_structure,
absl::string_view filename) final {
Expand Down
2 changes: 1 addition & 1 deletion common/analysis/text_structure_linter_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace verible {
template <>
class LintRunner<TextStructureLintRule> {
public:
explicit LintRunner(std::unique_ptr<TextStructureLintRule> rule) : linter_() {
explicit LintRunner(std::unique_ptr<TextStructureLintRule> rule) {
linter_.AddRule(std::move(rule));
}

Expand Down
2 changes: 1 addition & 1 deletion common/analysis/token_stream_linter_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace verible {
template <>
class LintRunner<TokenStreamLintRule> {
public:
explicit LintRunner(std::unique_ptr<TokenStreamLintRule> rule) : linter_() {
explicit LintRunner(std::unique_ptr<TokenStreamLintRule> rule) {
linter_.AddRule(std::move(rule));
}

Expand Down
25 changes: 16 additions & 9 deletions common/formatting/align_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ class GetPartitionAlignmentSubrangesTestFixture : public AlignmentTestFixture {
partition.Value().TokensRange().front().Text();
if (text == "match") {
return AlignmentGroupAction::kMatch;
} else if (text == "nomatch") {
}
if (text == "nomatch") {
return AlignmentGroupAction::kNoMatch;
} else {
return AlignmentGroupAction::kIgnore;
Expand Down Expand Up @@ -804,7 +805,8 @@ class GetPartitionAlignmentSubrangesSubtypedTestFixture
absl::string_view last = *std::next(toks.begin());
// Use the first character after the : as the subtype, so 'X', 'Y', 'Z'.
return {AlignmentGroupAction::kMatch, static_cast<int>(last.front())};
} else if (text == "nomatch") {
}
if (text == "nomatch") {
return {AlignmentGroupAction::kNoMatch};
} else {
return {AlignmentGroupAction::kIgnore};
Expand Down Expand Up @@ -995,10 +997,11 @@ class SyntaxTreeColumnizer : public ColumnSchemaScanner {

void Visit(const SyntaxTreeNode& node) final {
ColumnPositionTree* column;
if (!current_column_)
if (!current_column_) {
column = ReserveNewColumn(node, props);
else
} else {
column = ReserveNewColumn(current_column_, node, props);
}

ValueSaver<ColumnPositionTree*> current_column_saver(&current_column_,
column);
Expand All @@ -1008,10 +1011,11 @@ class SyntaxTreeColumnizer : public ColumnSchemaScanner {
AlignmentColumnProperties local_props = props;
if (leaf.get().text() == ",") local_props.contains_delimiter = true;

if (!current_column_)
if (!current_column_) {
ReserveNewColumn(leaf, local_props);
else
} else {
ReserveNewColumn(current_column_, leaf, local_props);
}
}

private:
Expand Down Expand Up @@ -1093,7 +1097,8 @@ class SubcolumnsTreeAlignmentTest : public MatrixTreeAlignmentTestFixture {
SymbolPtr rp = Leaf(1, (*it)->Text());
++*it;
return TNode(1, std::move(lp), std::move(list), std::move(rp));
} else if ((*it)->Text() == ")") {
}
if ((*it)->Text() == ")") {
return SymbolPtr(nullptr);
} else {
SymbolPtr leaf = Leaf(0, (*it)->Text());
Expand Down Expand Up @@ -1448,11 +1453,13 @@ class OutsideCharPairs {
absl::string_view Find(absl::string_view text, size_t pos) const {
if (text[pos] == start_) {
const size_t stop_pos = text.find(stop_, pos + 1);
if (stop_pos == absl::string_view::npos)
if (stop_pos == absl::string_view::npos) {
return absl::string_view(text.data() + text.size(), 0);
}
const size_t start_pos = text.find(start_, stop_pos + 1);
if (start_pos == absl::string_view::npos)
if (start_pos == absl::string_view::npos) {
return text.substr(stop_pos + 1);
}
return text.substr(stop_pos + 1, start_pos - stop_pos - 1);
}
const size_t start_pos = text.find(start_, pos);
Expand Down
22 changes: 12 additions & 10 deletions common/formatting/layout_optimizer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ std::string ToString(const T& value) {

std::ostream& PrintIndented(std::ostream& stream, absl::string_view str,
int indentation) {
for (const auto& line : verible::SplitLinesKeepLineTerminator(str))
for (const auto& line : verible::SplitLinesKeepLineTerminator(str)) {
stream << verible::Spacer(indentation) << line;
}
return stream;
}

Expand Down Expand Up @@ -103,8 +104,9 @@ void ExpectLayoutFunctionsEqual(const LayoutFunction& actual,
*layout_diff.left, *layout_diff.right, 2, true);
}

if (auto str = segment_msg.str(); !str.empty())
if (auto str = segment_msg.str(); !str.empty()) {
msg << "segment[" << i << "]:\n" << str << "\n";
}
}

if (const auto str = msg.str(); !str.empty()) {
Expand Down Expand Up @@ -718,8 +720,9 @@ class LayoutFunctionFactoryTest : public ::testing::Test,

// First token in a line
if (absl::StrContains(leading_spaces, '\n')) {
if (first_on_line_must_wrap)
if (first_on_line_must_wrap) {
token->before.break_decision = SpacingOptions::MustWrap;
}
uwlines->back().SpanUpToToken(token);
uwlines->emplace_back(0, token);
}
Expand Down Expand Up @@ -2384,27 +2387,26 @@ class TokenPartitionsLayoutOptimizerTest : public ::testing::Test,
style_(CreateStyle()),
factory_(LayoutFunctionFactory(style_)) {
for (const auto token : tokens_) {
ftokens_.emplace_back(TokenInfo{1, token});
ftokens_.emplace_back(1, token);
}
CreateTokenInfosExternalStringBuffer(ftokens_);
ConnectPreFormatTokensPreservedSpaceStarts(sample_.data(),
&pre_format_tokens_);

// Set token properties
for (auto token_it = pre_format_tokens_.begin();
token_it != pre_format_tokens_.end(); ++token_it) {
const auto leading_spaces = token_it->OriginalLeadingSpaces();
for (auto& token : pre_format_tokens_) {
const auto leading_spaces = token.OriginalLeadingSpaces();

// First token in a line
if (absl::StrContains(leading_spaces, '\n')) {
token_it->before.break_decision = SpacingOptions::MustWrap;
token.before.break_decision = SpacingOptions::MustWrap;
auto last_non_space_offset = leading_spaces.find_last_not_of(' ');
if (last_non_space_offset != absl::string_view::npos) {
token_it->before.spaces_required =
token.before.spaces_required =
leading_spaces.size() - 1 - last_non_space_offset;
}
} else {
token_it->before.spaces_required = leading_spaces.size();
token.before.spaces_required = leading_spaces.size();
}
}
pre_format_tokens_.front().before.break_decision = SpacingOptions::MustWrap;
Expand Down
2 changes: 1 addition & 1 deletion common/lexer/lexer_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace verible {
// Modeled after the Lexer base class.
class FakeLexer {
protected:
explicit FakeLexer() {}
explicit FakeLexer() = default;

void SetTokensData(const std::vector<TokenInfo>& tokens);

Expand Down
2 changes: 1 addition & 1 deletion common/strings/diff_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::ostream& operator<<(std::ostream& out, const diff::Edit& edit) {

std::ostream& operator<<(std::ostream& out, const Edits& edits) {
out << "Edits{";
std::string outer_delim = "";
std::string outer_delim;
for (auto& edit : edits) {
out << outer_delim << edit;
outer_delim = ",";
Expand Down
2 changes: 1 addition & 1 deletion common/strings/rebase_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {

// Test that empty string token rebases correctly.
TEST(RebaseStringViewTest, EmptyStringsZeroOffset) {
const std::string text = "";
const std::string text;
// We want another empty string, but we need to trick too smart compilers
// to give us a different memory address.
std::string substr = "foo";
Expand Down
2 changes: 1 addition & 1 deletion common/text/token_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ TEST(TokenWithContextTest, StreamOutput) {

// Test that empty string token rebases correctly.
TEST(RebaseStringViewTest, EmptyStringsZeroOffset) {
const std::string text = "";
const std::string text;
// We want another empty string, but we need to trick too smart compilers
// to give us a different memory address.
std::string substr = "foo";
Expand Down
2 changes: 1 addition & 1 deletion common/text/token_stream_view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace verible {

class TokenStreamViewTest : public testing::Test {
protected:
TokenStreamViewTest() : tokens_() {
TokenStreamViewTest() {
// Generate with bogus token enums, with 0 at the end.
for (int i = 0; i < 10; ++i) {
tokens_.push_back(TokenInfo(i + 2, "moo"));
Expand Down
2 changes: 1 addition & 1 deletion common/util/container_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class ContainerProxy
template <class Proxy>
class ContainerProxyTest : public ::testing::Test {
public:
ContainerProxyTest() {}
ContainerProxyTest() = default;

using Container = typename Proxy::container_type;
Container container = {"zero", "one", "two"};
Expand Down
6 changes: 3 additions & 3 deletions common/util/tree_operations_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ testing::AssertionResult VerifyTree(const T& actual, const T& expected,
}
return err;
}
if (actual.Children().size() != 0) {
if (!actual.Children().empty()) {
auto actual_child = actual.Children().begin();
auto expected_child = expected.Children().begin();
auto child_path = path;
Expand Down Expand Up @@ -211,7 +211,7 @@ class NodeWithParentAndValue
// trees.
class IntNode {
public:
IntNode() {}
IntNode() = default;
explicit IntNode(int value, std::initializer_list<IntNode> children = {})
: value_(value), children_(children) {}

Expand Down Expand Up @@ -254,7 +254,7 @@ class IntNode {
template <class Node>
class TreeTest : public ::testing::Test {
public:
TreeTest() {}
TreeTest() = default;

using N = Node;
N root = N("root", {N("0"), //
Expand Down
2 changes: 1 addition & 1 deletion external_libs/editscript_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::ostream &operator<<(std::ostream &out, const Edit &edit) {

std::ostream &operator<<(std::ostream &out, const Edits &edits) {
out << "Edits{";
std::string outer_delim = "";
std::string outer_delim;
for (auto &edit : edits) {
out << outer_delim << edit;
outer_delim = ",";
Expand Down
Loading

0 comments on commit 87315bf

Please sign in to comment.