diff options
author | Neil <nyamatongwe@gmail.com> | 2024-01-30 10:11:10 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2024-01-30 10:11:10 +1100 |
commit | 77d00274b4e729ba5eac3cda390d6aa9478567ca (patch) | |
tree | 01744884872093ea9406a206e554f9d569a3b0d2 | |
parent | 72689db0d549c0cb850012546c71117ea74c2f2c (diff) | |
download | scintilla-mirror-77d00274b4e729ba5eac3cda390d6aa9478567ca.tar.gz |
Avoid warnings in unit tests with const, nullptr, [[nodiscard]], initialisation,
and unnamed namespace.
-rw-r--r-- | test/unit/testCellBuffer.cxx | 2 | ||||
-rw-r--r-- | test/unit/testCharClassify.cxx | 8 | ||||
-rw-r--r-- | test/unit/testCharacterCategoryMap.cxx | 2 | ||||
-rw-r--r-- | test/unit/testDocument.cxx | 6 | ||||
-rw-r--r-- | test/unit/testPartitioning.cxx | 4 | ||||
-rw-r--r-- | test/unit/testPerLine.cxx | 4 | ||||
-rw-r--r-- | test/unit/testRESearch.cxx | 12 | ||||
-rw-r--r-- | test/unit/testRunStyles.cxx | 4 | ||||
-rw-r--r-- | test/unit/testSparseVector.cxx | 14 | ||||
-rw-r--r-- | test/unit/testSplitVector.cxx | 8 |
10 files changed, 34 insertions, 30 deletions
diff --git a/test/unit/testCellBuffer.cxx b/test/unit/testCellBuffer.cxx index 5e5b0b138..b6e03d2ee 100644 --- a/test/unit/testCellBuffer.cxx +++ b/test/unit/testCellBuffer.cxx @@ -1405,7 +1405,7 @@ TEST_CASE("CellBufferLong") { SECTION("Random") { RandomSequence rseq; - for (size_t i = 0l; i < 20000; i++) { + for (size_t i = 0; i < 20000; i++) { const int r = rseq.Next() % 10; if (r <= 2) { // 30% // Insert text diff --git a/test/unit/testCharClassify.cxx b/test/unit/testCharClassify.cxx index 5401b4ec6..20c3482f6 100644 --- a/test/unit/testCharClassify.cxx +++ b/test/unit/testCharClassify.cxx @@ -22,8 +22,6 @@ using namespace Scintilla::Internal; // Test CharClassify. class CharClassifyTest { - // Avoid warnings, deleted so never called. - CharClassifyTest(const CharClassifyTest &) = delete; protected: CharClassifyTest() { pcc = std::make_unique<CharClassify>(); @@ -38,9 +36,11 @@ protected: charClass[ch] = CharacterClass::punctuation; } } + // Avoid warnings, deleted so never called. + CharClassifyTest(const CharClassifyTest &) = delete; std::unique_ptr<CharClassify> pcc; - CharacterClass charClass[256]; + CharacterClass charClass[256] {}; static const char* GetClassName(CharacterClass charClass) noexcept { switch(charClass) { @@ -95,7 +95,7 @@ TEST_CASE_METHOD(CharClassifyTest, "CharsOfClass") { } for (int classVal = 0; classVal < 4; ++classVal) { const CharacterClass thisClass = static_cast<CharacterClass>(classVal % 4); - const int size = pcc->GetCharsOfClass(thisClass, NULL); + const int size = pcc->GetCharsOfClass(thisClass, nullptr); std::vector<unsigned char> buffer(size+1); const unsigned char *pBuffer = buffer.data(); pcc->GetCharsOfClass(thisClass, buffer.data()); diff --git a/test/unit/testCharacterCategoryMap.cxx b/test/unit/testCharacterCategoryMap.cxx index 8c5305cc7..cdc810b02 100644 --- a/test/unit/testCharacterCategoryMap.cxx +++ b/test/unit/testCharacterCategoryMap.cxx @@ -24,7 +24,7 @@ using namespace Scintilla::Internal; TEST_CASE("CharacterCategoryMap") { - CharacterCategoryMap ccm; + const CharacterCategoryMap ccm; SECTION("LowerCaseLetter") { const CharacterCategory cc = ccm.CategoryFor('a'); diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx index 147614637..3266b0a9d 100644 --- a/test/unit/testDocument.cxx +++ b/test/unit/testDocument.cxx @@ -57,7 +57,7 @@ struct Folding { }; // Table of case folding for non-ASCII bytes in Windows Latin code page 1252 -Folding foldings1252[] = { +const Folding foldings1252[] = { {0x8a, 0x9a, 0x01}, {0x8c, 0x9c, 0x01}, {0x8e, 0x9e, 0x01}, @@ -67,7 +67,7 @@ Folding foldings1252[] = { }; // Table of case folding for non-ASCII bytes in Windows Russian code page 1251 -Folding foldings1251[] = { +const Folding foldings1251[] = { {0x80, 0x90, 0x01}, {0x81, 0x83, 0x01}, {0x8a, 0x9a, 0x01}, @@ -83,7 +83,7 @@ Folding foldings1251[] = { {0xc0, 0xe0, 0x20}, }; -std::string ReadFile(std::string path) { +std::string ReadFile(const std::string &path) { std::ifstream ifs(path, std::ios::binary); std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); diff --git a/test/unit/testPartitioning.cxx b/test/unit/testPartitioning.cxx index 4ba470c82..5505715af 100644 --- a/test/unit/testPartitioning.cxx +++ b/test/unit/testPartitioning.cxx @@ -34,13 +34,13 @@ TEST_CASE("CompileCopying Partitioning") { Partitioning<int> s2; // Copy constructor - Partitioning<int> sa(s); + const Partitioning<int> sa(s); // Copy assignment Partitioning<int> sb; sb = s; // Move constructor - Partitioning<int> sc(std::move(s)); + const Partitioning<int> sc(std::move(s)); // Move assignment Partitioning<int> sd; sd = (std::move(s2)); diff --git a/test/unit/testPerLine.cxx b/test/unit/testPerLine.cxx index d9cf11ac6..47a60ce90 100644 --- a/test/unit/testPerLine.cxx +++ b/test/unit/testPerLine.cxx @@ -41,13 +41,13 @@ TEST_CASE("CompileCopying MarkerHandleSet") { MarkerHandleSet s2; // Copy constructor - MarkerHandleSet sa(s); + const MarkerHandleSet sa(s); // Copy assignment MarkerHandleSet sb; sb = s; // Move constructor - MarkerHandleSet sc(std::move(s)); + const MarkerHandleSet sc(std::move(s)); // Move assignment MarkerHandleSet sd; sd = (std::move(s2)); diff --git a/test/unit/testRESearch.cxx b/test/unit/testRESearch.cxx index 120bbdf15..4e041d47c 100644 --- a/test/unit/testRESearch.cxx +++ b/test/unit/testRESearch.cxx @@ -33,10 +33,10 @@ using namespace Scintilla::Internal; class StringCI : public CharacterIndexer { std::string s; public: - StringCI(std::string_view sv_) : s(sv_) { + explicit StringCI(std::string_view sv_) : s(sv_) { } virtual ~StringCI() = default; - Sci::Position Length() const noexcept { + [[nodiscard]] Sci::Position Length() const noexcept { return s.length(); } char CharAt(Sci::Position index) const override { @@ -45,7 +45,7 @@ public: Sci::Position MovePositionOutsideChar(Sci::Position pos, [[maybe_unused]] Sci::Position moveDir) const noexcept override { return pos; } - std::string GetCharRange(Sci::Position position, Sci::Position lengthRetrieve) const { + [[nodiscard]] std::string GetCharRange(Sci::Position position, Sci::Position lengthRetrieve) const { return s.substr(position, lengthRetrieve); } }; @@ -78,7 +78,7 @@ TEST_CASE("RESearch") { SECTION("Execute") { RESearch re(&cc); re.Compile(pattern.data(), pattern.length(), true, false); - StringCI sci(sTextSpace); + const StringCI sci(sTextSpace); const int x = re.Execute(sci, 0, sci.Length()); REQUIRE(x == 1); REQUIRE(re.bopat[0] == 1); @@ -88,9 +88,9 @@ TEST_CASE("RESearch") { SECTION("Grab") { RESearch re(&cc); re.Compile(pattern.data(), pattern.length(), true, false); - StringCI sci(sTextSpace); + const StringCI sci(sTextSpace); re.Execute(sci, 0, sci.Length()); - std::string pat = sci.GetCharRange(re.bopat[0], re.eopat[0] - re.bopat[0]); + const std::string pat = sci.GetCharRange(re.bopat[0], re.eopat[0] - re.bopat[0]); REQUIRE(pat == "cintilla"); } diff --git a/test/unit/testRunStyles.cxx b/test/unit/testRunStyles.cxx index 2a1c6b78a..9a9ca2f6e 100644 --- a/test/unit/testRunStyles.cxx +++ b/test/unit/testRunStyles.cxx @@ -37,13 +37,13 @@ TEST_CASE("CompileCopying RunStyles") { RunStyles<int, int> s2; // Copy constructor - RunStyles<int, int> sa(s); + const RunStyles<int, int> sa(s); // Copy assignment fails RunStyles<int, int> sb; sb = s; // Move constructor - RunStyles<int, int> sc(std::move(s)); + const RunStyles<int, int> sc(std::move(s)); // Move assignment RunStyles<int, int> sd; sd = (std::move(s2)); diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx index 3a9ac3123..157acfc2d 100644 --- a/test/unit/testSparseVector.cxx +++ b/test/unit/testSparseVector.cxx @@ -39,13 +39,13 @@ TEST_CASE("CompileCopying SparseVector") { SparseVector<int> s2; // Copy constructor - SparseVector<int> sa(s); + const SparseVector<int> sa(s); // Copy assignment SparseVector<int> sb; sb = s; // Move constructor - SparseVector<int> sc(std::move(s)); + const SparseVector<int> sc(std::move(s)); // Move assignment SparseVector<int> sd; sd = (std::move(s2)); @@ -64,7 +64,7 @@ TEST_CASE("CompileCopying SparseVector") { #endif // Move constructor - SparseVector<UniqueInt> sc(std::move(s)); + const SparseVector<UniqueInt> sc(std::move(s)); // Move assignment SparseVector<UniqueInt> s2; SparseVector<UniqueInt> sd; @@ -73,9 +73,11 @@ TEST_CASE("CompileCopying SparseVector") { } +namespace { + // Helper to produce a string representation of a SparseVector<const char *> // to simplify checks. -static std::string Representation(const SparseVector<UniqueString> &st) { +std::string Representation(const SparseVector<UniqueString> &st) { std::string ret; for (int i = 0;i <= st.Length();i++) { const char *value = st.ValueAt(i).get(); @@ -87,6 +89,8 @@ static std::string Representation(const SparseVector<UniqueString> &st) { return ret; } +} + TEST_CASE("SparseVector") { SparseVector<UniqueString> st; @@ -473,7 +477,7 @@ TEST_CASE("SparseTextString") { SECTION("SetAndMoveString") { st.InsertSpace(0, 2); REQUIRE(2u == st.Length()); - std::string s24("24"); + const std::string s24("24"); st.SetValueAt(0, s24); REQUIRE("24" == s24); // Not moved from REQUIRE("" == st.ValueAt(-1)); diff --git a/test/unit/testSplitVector.cxx b/test/unit/testSplitVector.cxx index b5559a6af..5125eb55f 100644 --- a/test/unit/testSplitVector.cxx +++ b/test/unit/testSplitVector.cxx @@ -37,13 +37,13 @@ TEST_CASE("CompileCopying SplitVector") { SplitVector<int> s2; // Copy constructor fails - SplitVector<int> sa(s); + const SplitVector<int> sa(s); // Copy assignment fails SplitVector<int> sb; sb = s; // Move constructor fails - SplitVector<int> sc(std::move(s)); + const SplitVector<int> sc(std::move(s)); // Move assignment fails SplitVector<int> sd; sd = (std::move(s2)); @@ -62,7 +62,7 @@ TEST_CASE("CompileCopying SplitVector") { #endif // Move constructor fails - SplitVector<UniqueInt> sc(std::move(s)); + const SplitVector<UniqueInt> sc(std::move(s)); // Move assignment fails SplitVector<UniqueInt> sd; sd = (std::move(s)); @@ -72,7 +72,7 @@ TEST_CASE("CompileCopying SplitVector") { struct StringSetHolder { SplitVector<std::string> sa; - bool Check() const noexcept { + [[nodiscard]] bool Check() const noexcept { for (int i = 0; i < sa.Length(); i++) { if (sa[i].empty()) { return false; |