Skip to content

Commit

Permalink
Apply clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
davschneller committed Jul 29, 2024
1 parent 1b9de80 commit 0da6c65
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/BlockParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BlockParser {
std::smatch Match;
if (std::regex_match(*Itr, Match, m_FieldExpr)) {
std::string Identifier = m_KeyModifier.apply(Match[1]);
std::string ValueStr = Match[2];
const std::string ValueStr = Match[2];

if (!Fields[Identifier]) {

Expand Down
4 changes: 2 additions & 2 deletions include/BlockProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class BlockProcessor {
void removeEmptyBlocks(std::list<BlockT>& Blocks) {

// NOTE: header + tail + at least one field
const std::list<BlockT>::iterator::difference_type MIN_NUM_STRINGS = 2;
const std::list<BlockT>::iterator::difference_type MinNumStrings = 2;

std::vector<std::list<BlockT>::iterator> Deletees;
for (auto Itr = Blocks.begin(); Itr != Blocks.end(); ++Itr) {
if (std::distance(Itr->first, Itr->second) < MIN_NUM_STRINGS) {
if (std::distance(Itr->first, Itr->second) < MinNumStrings) {
Deletees.push_back(Itr);
}
}
Expand Down
10 changes: 5 additions & 5 deletions include/StringProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StringProcessor {

for (auto& Item : Content) {
std::smatch Match;
if (std::regex_match(Item, Match, m_Comment_Expr)) {
if (std::regex_match(Item, Match, m_CommentExpr)) {
Item = Match[1];
}
}
Expand All @@ -41,14 +41,14 @@ class StringProcessor {
void removeEmptyLines(StringsT& Content) {

const std::string WHITESPACE = " \n\r\t\f\v";
auto isEmptyString = [&WHITESPACE](const std::string& String) -> bool {
size_t Start = String.find_first_not_of(WHITESPACE);
auto IsEmptyString = [&WHITESPACE](const std::string& String) -> bool {
const size_t Start = String.find_first_not_of(WHITESPACE);
return Start == std::string::npos;
};

std::vector<StringsT::iterator> Deletees;
for (auto Itr = Content.begin(); Itr != Content.end(); ++Itr) {
if (isEmptyString(*Itr))
if (IsEmptyString(*Itr))
Deletees.push_back(Itr);
}

Expand All @@ -58,7 +58,7 @@ class StringProcessor {
}

private:
std::regex m_Comment_Expr{"^([^!]*)!.*\\s?$"};
std::regex m_CommentExpr{"^([^!]*)!.*\\s?$"};
};
} // namespace fty

Expand Down
2 changes: 2 additions & 0 deletions tests/BlockParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// SPDX-License-Identifier: MIT

#include "BlockParser.hpp"
#include "FtyDataTypes.hpp"
#include "FtyExceptions.hpp"
#include "FtyPolicies.hpp"
#include "helper.hpp"
#include "gtest/gtest.h"
Expand Down
15 changes: 8 additions & 7 deletions tests/BlockProcessorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// SPDX-License-Identifier: MIT

#include "BlockProcessor.hpp"
#include "FtyPolicies.hpp"
#include "FtyDataTypes.hpp"
#include "FtyExceptions.hpp"
#include "helper.hpp"
#include "gtest/gtest.h"
#include <string>
#include <iostream>
#include <yaml-cpp/yaml.h>

using namespace fty;
Expand All @@ -21,7 +22,7 @@ bool isEqualBlocks(const BlockT& Left, const BlockT& Right) {

auto LeftItr = Left.first;
auto RightItr = Right.first;
for (int i = 0; i < LeftSize; ++i, ++LeftItr, ++RightItr) {
for (int I = 0; I < LeftSize; ++I, ++LeftItr, ++RightItr) {
if ((*LeftItr) != (*RightItr)) {
std::cout << "Left: " << *LeftItr << "; Right: " << *RightItr << ";" << std::endl;
return false;
Expand All @@ -42,11 +43,11 @@ TEST(BlockProcessorTest, RemoveEmptyBlocks) {
Factory.add({{"&Boundaries"}, {"Order=1 "}, {"BC_fs = 1.5"}, {"BC_of = 1"}, {"/"}});
Factory.add({{"&Empty"}, {"/"}});

StringsT Content = Factory.getContent();
const StringsT Content = Factory.getContent();
std::list<BlockT> Blocks = Factory.getBlocks();

BlockFactory TestFactory = Factory;
StringsT TestContent = TestFactory.getContent();
const StringsT TestContent = TestFactory.getContent();
std::list<BlockT> TestBlocks = TestFactory.getBlocks();

Processor.removeEmptyBlocks(TestBlocks);
Expand Down Expand Up @@ -96,7 +97,7 @@ TEST(BlockProcessorTest, EndsWithoutTerminator) {

auto Begin = Content.begin();
auto End = Content.end();
BlockT ValidBlock = Processor.getNextBlock(Begin, End);
const BlockT ValidBlock = Processor.getNextBlock(Begin, End);
ASSERT_TRUE(isEqualBlocks(ValidBlock, BlockScroll(Blocks)[0]));
ASSERT_THROW(Processor.getNextBlock(Begin, End), exception::CriticalTextBlockException);
}
Expand All @@ -116,7 +117,7 @@ TEST(BlockProcessorTest, EmptyLinesAfterLastBlock) {

auto Begin = Content.begin();
auto End = Content.end();
BlockT ValidBlock = Processor.getNextBlock(Begin, End);
const BlockT ValidBlock = Processor.getNextBlock(Begin, End);
ASSERT_TRUE(isEqualBlocks(ValidBlock, BlockScroll(Blocks)[1]));
ASSERT_THROW(Processor.getNextBlock(Begin, End), exception::TextBlockException);
}
1 change: 1 addition & 0 deletions tests/PolicyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

#include "BlockParser.hpp"
#include "FtyDataTypes.hpp"
#include "FtyPolicies.hpp"
#include "helper.hpp"
#include "gtest/gtest.h"
Expand Down
1 change: 0 additions & 1 deletion tests/StringProcessorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: MIT

#include "StringProcessor.hpp"
#include "helper.hpp"
#include "gtest/gtest.h"
#include <string>

Expand Down
2 changes: 2 additions & 0 deletions tests/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
// SPDX-License-Identifier: MIT

#include "helper.hpp"
#include "FtyDataTypes.hpp"
#include <utility>

BlockT make_block(StringsT& Content) { return std::make_pair(Content.begin(), --Content.end()); }

0 comments on commit 0da6c65

Please sign in to comment.