aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/testCharClassify.cxx12
-rw-r--r--test/unit/testDocument.cxx4
-rw-r--r--test/unit/testRESearch.cxx29
-rw-r--r--test/unit/testRunStyles.cxx42
-rw-r--r--test/unit/testSparseVector.cxx6
-rw-r--r--test/unit/testSplitVector.cxx2
-rw-r--r--test/unit/testUniConversion.cxx48
7 files changed, 73 insertions, 70 deletions
diff --git a/test/unit/testCharClassify.cxx b/test/unit/testCharClassify.cxx
index 8a9279848..5401b4ec6 100644
--- a/test/unit/testCharClassify.cxx
+++ b/test/unit/testCharClassify.cxx
@@ -42,7 +42,7 @@ protected:
std::unique_ptr<CharClassify> pcc;
CharacterClass charClass[256];
- static const char* GetClassName(CharacterClass charClass) {
+ static const char* GetClassName(CharacterClass charClass) noexcept {
switch(charClass) {
#define CASE(c) case CharacterClass::c: return #c
CASE(space);
@@ -70,7 +70,7 @@ TEST_CASE_METHOD(CharClassifyTest, "Defaults") {
TEST_CASE_METHOD(CharClassifyTest, "Custom") {
unsigned char buf[2] = {0, 0};
for (int i = 0; i < 256; i++) {
- CharacterClass thisClass = CharacterClass(i % 4);
+ const CharacterClass thisClass = static_cast<CharacterClass>(i % 4);
buf[0] = i;
pcc->SetCharClasses(buf, thisClass);
charClass[i] = thisClass;
@@ -88,16 +88,16 @@ TEST_CASE_METHOD(CharClassifyTest, "Custom") {
TEST_CASE_METHOD(CharClassifyTest, "CharsOfClass") {
unsigned char buf[2] = {0, 0};
for (int i = 1; i < 256; i++) {
- CharacterClass thisClass = CharacterClass(i % 4);
+ const CharacterClass thisClass = static_cast<CharacterClass>(i % 4);
buf[0] = i;
pcc->SetCharClasses(buf, thisClass);
charClass[i] = thisClass;
}
for (int classVal = 0; classVal < 4; ++classVal) {
- CharacterClass thisClass = CharacterClass(classVal % 4);
- int size = pcc->GetCharsOfClass(thisClass, NULL);
+ const CharacterClass thisClass = static_cast<CharacterClass>(classVal % 4);
+ const int size = pcc->GetCharsOfClass(thisClass, NULL);
std::vector<unsigned char> buffer(size+1);
- void *pBuffer = static_cast<void *>(buffer.data());
+ const unsigned char *pBuffer = buffer.data();
pcc->GetCharsOfClass(thisClass, buffer.data());
for (int i = 1; i < 256; i++) {
if (charClass[i] == thisClass) {
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx
index ab65130e3..147614637 100644
--- a/test/unit/testDocument.cxx
+++ b/test/unit/testDocument.cxx
@@ -273,7 +273,7 @@ TEST_CASE("Document") {
DocPlus doc("_abcdef", 0); // _ a b c d e f
constexpr std::string_view finding = "cd";
Sci::Position lengthFinding = finding.length();
- size_t docLength = doc.document.Length() - 1;
+ const size_t docLength = doc.document.Length() - 1;
Sci::Position location = doc.document.FindText(1, docLength, finding.data(), FindOption::MatchCase, &lengthFinding);
REQUIRE(location == 3);
location = doc.document.FindText(docLength, 1, finding.data(), FindOption::MatchCase, &lengthFinding);
@@ -840,7 +840,7 @@ TEST_CASE("SafeSegment") {
const DocPlus doc("", 0);
// all encoding: break before or after last space
constexpr std::string_view text = "12 ";
- size_t length = doc.document.SafeSegment(text);
+ const size_t length = doc.document.SafeSegment(text);
REQUIRE(length <= text.length());
REQUIRE(text[length - 1] == '2');
REQUIRE(text[length] == ' ');
diff --git a/test/unit/testRESearch.cxx b/test/unit/testRESearch.cxx
index 1902fdb2b..120bbdf15 100644
--- a/test/unit/testRESearch.cxx
+++ b/test/unit/testRESearch.cxx
@@ -35,6 +35,7 @@ class StringCI : public CharacterIndexer {
public:
StringCI(std::string_view sv_) : s(sv_) {
}
+ virtual ~StringCI() = default;
Sci::Position Length() const noexcept {
return s.length();
}
@@ -58,38 +59,38 @@ TEST_CASE("RESearch") {
constexpr std::string_view pattern = "[a-z]+";
SECTION("Compile") {
- std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
- const char *msg = re->Compile(pattern.data(), pattern.length(), true, false);
+ RESearch re(&cc);
+ const char *msg = re.Compile(pattern.data(), pattern.length(), true, false);
REQUIRE(nullptr == msg);
}
SECTION("Bug2413") {
// Check for https://sourceforge.net/p/scintilla/bugs/2413/
- std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
+ RESearch re(&cc);
constexpr std::string_view BOW = "\\<";
constexpr std::string_view EOW = "\\>";
- const char *msg = re->Compile(BOW.data(), BOW.length(), true, false);
+ const char *msg = re.Compile(BOW.data(), BOW.length(), true, false);
REQUIRE(nullptr == msg);
- msg = re->Compile(EOW.data(), EOW.length(), true, false);
+ msg = re.Compile(EOW.data(), EOW.length(), true, false);
REQUIRE(nullptr == msg);
}
SECTION("Execute") {
- std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
- re->Compile(pattern.data(), pattern.length(), true, false);
+ RESearch re(&cc);
+ re.Compile(pattern.data(), pattern.length(), true, false);
StringCI sci(sTextSpace);
- const int x = re->Execute(sci, 0, sci.Length());
+ const int x = re.Execute(sci, 0, sci.Length());
REQUIRE(x == 1);
- REQUIRE(re->bopat[0] == 1);
- REQUIRE(re->eopat[0] == sci.Length() - 1);
+ REQUIRE(re.bopat[0] == 1);
+ REQUIRE(re.eopat[0] == sci.Length() - 1);
}
SECTION("Grab") {
- std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
- re->Compile(pattern.data(), pattern.length(), true, false);
+ RESearch re(&cc);
+ re.Compile(pattern.data(), pattern.length(), true, false);
StringCI sci(sTextSpace);
- re->Execute(sci, 0, sci.Length());
- std::string pat = sci.GetCharRange(re->bopat[0], re->eopat[0] - re->bopat[0]);
+ re.Execute(sci, 0, sci.Length());
+ 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 74be54dc7..2a1c6b78a 100644
--- a/test/unit/testRunStyles.cxx
+++ b/test/unit/testRunStyles.cxx
@@ -72,7 +72,7 @@ TEST_CASE("CompileCopying RunStyles") {
}
namespace Scintilla::Internal { // Xcode clang 9.0 doesn't like this when in the unnamed namespace
- bool operator==(const FillResult<int> &fra, const FillResult<int> &frb) {
+ bool operator==(const FillResult<int> &fra, const FillResult<int> &frb) noexcept {
return fra.changed == frb.changed &&
fra.position == frb.position &&
fra.fillLength == frb.fillLength;
@@ -149,8 +149,8 @@ TEST_CASE("RunStyles") {
SECTION("FillRange") {
rs.InsertSpace(0, 5);
- int startFill = 1;
- int lengthFill = 3;
+ const int startFill = 1;
+ const int lengthFill = 3;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(FillResult<int>{true, 1, 3} == fr);
@@ -169,13 +169,13 @@ TEST_CASE("RunStyles") {
SECTION("FillRangeAlreadyFilled") {
rs.InsertSpace(0, 5);
- int startFill = 1;
- int lengthFill = 3;
+ const int startFill = 1;
+ const int lengthFill = 3;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(FillResult<int>{true, 1, 3} == fr);
- int startFill2 = 2;
- int lengthFill2 = 1;
+ const int startFill2 = 2;
+ const int lengthFill2 = 1;
// Compiler warnings if 'false' used instead of '0' as expected value:
const auto fr2 = rs.FillRange(startFill2, 99, lengthFill2);
REQUIRE(FillResult<int>{false, 2, 1} == fr2);
@@ -189,13 +189,13 @@ TEST_CASE("RunStyles") {
SECTION("FillRangeAlreadyPartFilled") {
rs.InsertSpace(0, 5);
- int startFill = 1;
- int lengthFill = 2;
+ const int startFill = 1;
+ const int lengthFill = 2;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(FillResult<int>{true, 1, 2} == fr);
- int startFill2 = 2;
- int lengthFill2 = 2;
+ const int startFill2 = 2;
+ const int lengthFill2 = 2;
const auto fr2 = rs.FillRange(startFill2, 99, lengthFill2);
REQUIRE(FillResult<int>{true, 3, 1} == fr2);
REQUIRE(3 == rs.Runs());
@@ -225,8 +225,8 @@ TEST_CASE("RunStyles") {
SECTION("Find") {
rs.InsertSpace(0, 5);
- int startFill = 1;
- int lengthFill = 3;
+ const int startFill = 1;
+ const int lengthFill = 3;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(FillResult<int>{true, 1, 3} == fr);
@@ -261,8 +261,8 @@ TEST_CASE("RunStyles") {
REQUIRE(true == rs.AllSame());
REQUIRE(false == rs.AllSameAs(88));
REQUIRE(true == rs.AllSameAs(0));
- int startFill = 1;
- int lengthFill = 3;
+ const int startFill = 1;
+ const int lengthFill = 3;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(true == fr.changed);
REQUIRE(false == rs.AllSame());
@@ -334,8 +334,8 @@ TEST_CASE("RunStyles") {
SECTION("DeleteSecond") {
rs.InsertSpace(0, 3);
- int startFill = 1;
- int lengthFill = 1;
+ const int startFill = 1;
+ const int lengthFill = 1;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(true == fr.changed);
REQUIRE(3 == rs.Length());
@@ -347,8 +347,8 @@ TEST_CASE("RunStyles") {
SECTION("DeleteEndRun") {
rs.InsertSpace(0, 2);
- int startFill = 1;
- int lengthFill = 1;
+ const int startFill = 1;
+ const int lengthFill = 1;
const auto fr = rs.FillRange(startFill, 99, lengthFill);
REQUIRE(true == fr.changed);
REQUIRE(2 == rs.Length());
@@ -369,8 +369,8 @@ TEST_CASE("RunStyles") {
SECTION("OutsideBounds") {
rs.InsertSpace(0, 1);
- int startFill = 1;
- int lengthFill = 1;
+ const int startFill = 1;
+ const int lengthFill = 1;
rs.FillRange(startFill, 99, lengthFill);
REQUIRE(1 == rs.Length());
REQUIRE(1 == rs.Runs());
diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx
index 3a784d4c2..3a9ac3123 100644
--- a/test/unit/testSparseVector.cxx
+++ b/test/unit/testSparseVector.cxx
@@ -66,8 +66,9 @@ TEST_CASE("CompileCopying SparseVector") {
// Move constructor
SparseVector<UniqueInt> sc(std::move(s));
// Move assignment
+ SparseVector<UniqueInt> s2;
SparseVector<UniqueInt> sd;
- sd = (std::move(s));
+ sd = (std::move(s2));
}
}
@@ -480,7 +481,8 @@ TEST_CASE("SparseTextString") {
REQUIRE("" == st.ValueAt(1));
std::string s25("25");
st.SetValueAt(1, std::move(s25));
- REQUIRE("" == s25); // moved from
+ // Deliberate check of moved from: provokes warning from Visual C++ code analysis
+ REQUIRE("" == s25);
REQUIRE("25" == st.ValueAt(1));
}
diff --git a/test/unit/testSplitVector.cxx b/test/unit/testSplitVector.cxx
index c836a4ffe..b5559a6af 100644
--- a/test/unit/testSplitVector.cxx
+++ b/test/unit/testSplitVector.cxx
@@ -374,7 +374,7 @@ TEST_CASE("SplitVector") {
SECTION("DeleteBackAndForth") {
sv.InsertValue(0, 10, 87);
for (int i=0; i<10; i+=2) {
- int len = 10 - i;
+ const int len = 10 - i;
REQUIRE(len == sv.Length());
for (int j=0; j<sv.Length(); j++) {
REQUIRE(87 == sv.ValueAt(j));
diff --git a/test/unit/testUniConversion.cxx b/test/unit/testUniConversion.cxx
index 9c313390a..0327db7e1 100644
--- a/test/unit/testUniConversion.cxx
+++ b/test/unit/testUniConversion.cxx
@@ -28,53 +28,53 @@ TEST_CASE("UTF16Length") {
SECTION("UTF16Length ASCII") {
// Latin Small Letter A
const char *s = "a";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 1U);
}
SECTION("UTF16Length Example1") {
// Dollar Sign
const char *s = "\x24";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 1U);
}
SECTION("UTF16Length Example2") {
// Cent Sign
const char *s = "\xC2\xA2";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 1U);
}
SECTION("UTF16Length Example3") {
// Euro Sign
const char *s = "\xE2\x82\xAC";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 1U);
}
SECTION("UTF16Length Example4") {
// Gothic Letter Hwair
const char *s = "\xF0\x90\x8D\x88";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 2U);
}
SECTION("UTF16Length Invalid Trail byte in lead position") {
const char *s = "a\xB5yz";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 4U);
}
SECTION("UTF16Length Invalid Lead byte at end") {
const char *s = "a\xC2";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 2U);
}
SECTION("UTF16Length Invalid Lead byte implies 3 trails but only 2") {
const char *s = "a\xF1yz";
- size_t len = UTF16Length(s);
+ const size_t len = UTF16Length(s);
REQUIRE(len == 2U);
}
}
@@ -113,7 +113,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 ASCII") {
const char s[] = {'a', 0};
wchar_t tbuf[1] = {0};
- size_t tlen = UTF16FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 'a');
}
@@ -121,7 +121,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Example1") {
const char s[] = {'\x24', 0};
wchar_t tbuf[1] = {0};
- size_t tlen = UTF16FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0x24);
}
@@ -129,7 +129,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Example2") {
const char s[] = {'\xC2', '\xA2', 0};
wchar_t tbuf[1] = {0};
- size_t tlen = UTF16FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0xA2);
}
@@ -137,7 +137,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Example3") {
const char s[] = {'\xE2', '\x82', '\xAC', 0};
wchar_t tbuf[1] = {0};
- size_t tlen = UTF16FromUTF8(s, tbuf, 1);;
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 1);;
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0x20AC);
}
@@ -145,7 +145,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Example4") {
const char s[] = {'\xF0', '\x90', '\x8D', '\x88', 0};
wchar_t tbuf[2] = {0, 0};
- size_t tlen = UTF16FromUTF8(s, tbuf, 2);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 2);
REQUIRE(tlen == 2U);
REQUIRE(tbuf[0] == 0xD800);
REQUIRE(tbuf[1] == 0xDF48);
@@ -154,7 +154,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Invalid Trail byte in lead position") {
const char s[] = "a\xB5yz";
wchar_t tbuf[4] = {};
- size_t tlen = UTF16FromUTF8(s, tbuf, 4);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 4);
REQUIRE(tlen == 4U);
REQUIRE(tbuf[0] == 'a');
REQUIRE(tbuf[1] == 0xB5);
@@ -165,7 +165,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Invalid Lead byte at end") {
const char s[] = "a\xC2";
wchar_t tbuf[2] = {};
- size_t tlen = UTF16FromUTF8(s, tbuf, 2);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 2);
REQUIRE(tlen == 2U);
REQUIRE(tbuf[0] == 'a');
REQUIRE(tbuf[1] == 0xC2);
@@ -174,7 +174,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF16FromUTF8 Invalid Lead byte implies 3 trails but only 2") {
const char *s = "a\xF1yz";
wchar_t tbuf[4] = {};
- size_t tlen = UTF16FromUTF8(s, tbuf, 4);
+ const size_t tlen = UTF16FromUTF8(s, tbuf, 4);
REQUIRE(tlen == 2U);
REQUIRE(tbuf[0] == 'a');
REQUIRE(tbuf[1] == 0xF1);
@@ -185,7 +185,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 ASCII") {
const char s[] = {'a', 0};
unsigned int tbuf[1] = {0};
- size_t tlen = UTF32FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == static_cast<unsigned int>('a'));
}
@@ -193,7 +193,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Example1") {
const char s[] = {'\x24', 0};
unsigned int tbuf[1] = {0};
- size_t tlen = UTF32FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0x24);
}
@@ -201,7 +201,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Example2") {
const char s[] = {'\xC2', '\xA2', 0};
unsigned int tbuf[1] = {0};
- size_t tlen = UTF32FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0xA2);
}
@@ -209,7 +209,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Example3") {
const char s[] = {'\xE2', '\x82', '\xAC', 0};
unsigned int tbuf[1] = {0};
- size_t tlen = UTF32FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0x20AC);
}
@@ -217,7 +217,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Example4") {
const char s[] = {'\xF0', '\x90', '\x8D', '\x88', 0};
unsigned int tbuf[1] = {0};
- size_t tlen = UTF32FromUTF8(s, tbuf, 1);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 1);
REQUIRE(tlen == 1U);
REQUIRE(tbuf[0] == 0x10348);
}
@@ -225,7 +225,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Invalid Trail byte in lead position") {
const char s[] = "a\xB5yz";
unsigned int tbuf[4] = {};
- size_t tlen = UTF32FromUTF8(s, tbuf, 4);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 4);
REQUIRE(tlen == 4U);
REQUIRE(tbuf[0] == static_cast<unsigned int>('a'));
REQUIRE(tbuf[1] == 0xB5);
@@ -236,7 +236,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Invalid Lead byte at end") {
const char s[] = "a\xC2";
unsigned int tbuf[2] = {};
- size_t tlen = UTF32FromUTF8(s, tbuf, 2);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 2);
REQUIRE(tlen == 2U);
REQUIRE(tbuf[0] == static_cast<unsigned int>('a'));
REQUIRE(tbuf[1] == 0xC2);
@@ -245,7 +245,7 @@ TEST_CASE("UniConversion") {
SECTION("UTF32FromUTF8 Invalid Lead byte implies 3 trails but only 2") {
const char *s = "a\xF1yz";
unsigned int tbuf[4] = {};
- size_t tlen = UTF32FromUTF8(s, tbuf, 4);
+ const size_t tlen = UTF32FromUTF8(s, tbuf, 4);
REQUIRE(tlen == 2U);
REQUIRE(tbuf[0] == static_cast<unsigned int>('a'));
REQUIRE(tbuf[1] == 0xF1);