aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-02-23 11:05:23 +1100
committerNeil <nyamatongwe@gmail.com>2025-02-23 11:05:23 +1100
commit47b91df0cadb92f0dbaae441926448308b450ea1 (patch)
tree40082e6f83516ddf14ffdefc0760350f7dfce707
parent6ae5e45a7a09ba2c83477abe3835f274a0b032e6 (diff)
downloadscintilla-mirror-47b91df0cadb92f0dbaae441926448308b450ea1.tar.gz
Silence some warnings in test code.rel-5-5-5
-rw-r--r--test/unit/testCharClassify.cxx33
-rw-r--r--test/unit/testRESearch.cxx4
-rw-r--r--test/unit/testSelection.cxx4
3 files changed, 24 insertions, 17 deletions
diff --git a/test/unit/testCharClassify.cxx b/test/unit/testCharClassify.cxx
index 20c3482f6..b783fb910 100644
--- a/test/unit/testCharClassify.cxx
+++ b/test/unit/testCharClassify.cxx
@@ -21,11 +21,16 @@ using namespace Scintilla::Internal;
// Test CharClassify.
+constexpr int byteValues = 256;
+
class CharClassifyTest {
+public:
+ // Avoid warnings, deleted so never called.
+ CharClassifyTest(const CharClassifyTest &) = delete;
protected:
CharClassifyTest() {
pcc = std::make_unique<CharClassify>();
- for (int ch = 0; ch < 256; ch++) {
+ for (int ch = 0; ch < byteValues; ch++) {
if (ch == '\r' || ch == '\n')
charClass[ch] = CharacterClass::newLine;
else if (ch < 0x20 || ch == ' ' || ch == '\x7f')
@@ -36,11 +41,9 @@ 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[byteValues] {};
static const char* GetClassName(CharacterClass charClass) noexcept {
switch(charClass) {
@@ -57,37 +60,39 @@ protected:
};
TEST_CASE_METHOD(CharClassifyTest, "Defaults") {
- for (int i = 0; i < 256; i++) {
- if (charClass[i] != pcc->GetClass(i))
+ for (int i = 0; i < byteValues; i++) {
+ if (charClass[i] != pcc->GetClass(i)) {
std::cerr
<< "Character " << i
<< " should be class " << GetClassName(charClass[i])
<< ", but got " << GetClassName(pcc->GetClass(i)) << std::endl;
+ }
REQUIRE(charClass[i] == pcc->GetClass(i));
}
}
TEST_CASE_METHOD(CharClassifyTest, "Custom") {
unsigned char buf[2] = {0, 0};
- for (int i = 0; i < 256; i++) {
+ for (int i = 0; i < byteValues; i++) {
const CharacterClass thisClass = static_cast<CharacterClass>(i % 4);
buf[0] = i;
pcc->SetCharClasses(buf, thisClass);
charClass[i] = thisClass;
}
- for (int i = 0; i < 256; i++) {
- if (charClass[i] != pcc->GetClass(i))
+ for (int i = 0; i < byteValues; i++) {
+ if (charClass[i] != pcc->GetClass(i)) {
std::cerr
<< "Character " << i
<< " should be class " << GetClassName(charClass[i])
<< ", but got " << GetClassName(pcc->GetClass(i)) << std::endl;
+ }
REQUIRE(charClass[i] == pcc->GetClass(i));
}
}
TEST_CASE_METHOD(CharClassifyTest, "CharsOfClass") {
unsigned char buf[2] = {0, 0};
- for (int i = 1; i < 256; i++) {
+ for (int i = 1; i < byteValues; i++) {
const CharacterClass thisClass = static_cast<CharacterClass>(i % 4);
buf[0] = i;
pcc->SetCharClasses(buf, thisClass);
@@ -99,24 +104,26 @@ TEST_CASE_METHOD(CharClassifyTest, "CharsOfClass") {
std::vector<unsigned char> buffer(size+1);
const unsigned char *pBuffer = buffer.data();
pcc->GetCharsOfClass(thisClass, buffer.data());
- for (int i = 1; i < 256; i++) {
+ for (int i = 1; i < byteValues; i++) {
if (charClass[i] == thisClass) {
- if (!memchr(pBuffer, i, size))
+ if (!memchr(pBuffer, i, size)) {
std::cerr
<< "Character " << i
<< " should be class " << GetClassName(thisClass)
<< ", but was not in GetCharsOfClass;"
<< " it is reported to be "
<< GetClassName(pcc->GetClass(i)) << std::endl;
+ }
REQUIRE(memchr(pBuffer, i, size));
} else {
- if (memchr(pBuffer, i, size))
+ if (memchr(pBuffer, i, size)) {
std::cerr
<< "Character " << i
<< " should not be class " << GetClassName(thisClass)
<< ", but was in GetCharsOfClass"
<< " it is reported to be "
<< GetClassName(pcc->GetClass(i)) << std::endl;
+ }
REQUIRE_FALSE(memchr(pBuffer, i, size));
}
}
diff --git a/test/unit/testRESearch.cxx b/test/unit/testRESearch.cxx
index cc356e796..925d1a532 100644
--- a/test/unit/testRESearch.cxx
+++ b/test/unit/testRESearch.cxx
@@ -40,10 +40,10 @@ public:
[[nodiscard]] Sci::Position Length() const noexcept {
return s.length();
}
- char CharAt(Sci::Position index) const override {
+ [[nodiscard]] char CharAt(Sci::Position index) const override {
return s.at(index);
}
- Sci::Position MovePositionOutsideChar(Sci::Position pos, [[maybe_unused]] Sci::Position moveDir) const noexcept override {
+ [[nodiscard]] Sci::Position MovePositionOutsideChar(Sci::Position pos, [[maybe_unused]] Sci::Position moveDir) const noexcept override {
return pos;
}
[[nodiscard]] std::string GetCharRange(Sci::Position position, Sci::Position lengthRetrieve) const {
diff --git a/test/unit/testSelection.cxx b/test/unit/testSelection.cxx
index d708607d2..609feaf00 100644
--- a/test/unit/testSelection.cxx
+++ b/test/unit/testSelection.cxx
@@ -135,7 +135,7 @@ TEST_CASE("SelectionPosition") {
TEST_CASE("SelectionSegment") {
SECTION("SelectionSegment") {
- SelectionSegment ss;
+ const SelectionSegment ss;
REQUIRE(ss.start == invalid);
REQUIRE(ss.end == invalid);
}
@@ -145,7 +145,7 @@ TEST_CASE("SelectionSegment") {
TEST_CASE("SelectionRange") {
SECTION("SelectionRange") {
- SelectionRange sr;
+ const SelectionRange sr;
REQUIRE(sr.anchor == invalid);
REQUIRE(sr.caret == invalid);
}