From e030b1d56785405cb35531758d603be88af9b487 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 29 Jul 2022 11:16:28 +1000 Subject: Apply rule-of-zero to delete standard methods where possible as handled by contained types. This allows flexibility as most lower-level data types can be moved and SplitVector and Partitioning of non-move-only types may be copied. CellBuffer still needs destructor due to incomplete type so retains all standard operations. --- test/unit/testPartitioning.cxx | 24 +++++++++++++++++++++ test/unit/testPerLine.cxx | 24 +++++++++++++++++++++ test/unit/testRunStyles.cxx | 46 +++++++++++++++++++++++++++++++++++++++++ test/unit/testSparseVector.cxx | 45 ++++++++++++++++++++++++++++++++++++++++ test/unit/testSplitVector.cxx | 47 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 186 insertions(+) (limited to 'test/unit') diff --git a/test/unit/testPartitioning.cxx b/test/unit/testPartitioning.cxx index fc55b4da1..5eef60c39 100644 --- a/test/unit/testPartitioning.cxx +++ b/test/unit/testPartitioning.cxx @@ -27,6 +27,30 @@ static const int testArray[lengthTestArray] = {3, 4, 5, 6, 7, 8, 9, 10}; // Test Partitioning. +TEST_CASE("CompileCopying Partitioning") { + + // These are compile-time tests to check that basic copy and move + // operations are defined correctly. + + SECTION("CopyingMoving") { + Partitioning s; + Partitioning s2; + + // Copy constructor + Partitioning sa(s); + // Copy assignment + Partitioning sb; + sb = s; + + // Move constructor + Partitioning sc(std::move(s)); + // Move assignment + Partitioning sd; + sd = (std::move(s2)); + } + +} + TEST_CASE("Partitioning") { Partitioning part; diff --git a/test/unit/testPerLine.cxx b/test/unit/testPerLine.cxx index 74881f40e..d9cf11ac6 100644 --- a/test/unit/testPerLine.cxx +++ b/test/unit/testPerLine.cxx @@ -31,6 +31,30 @@ constexpr int FoldBase = static_cast(Scintilla::FoldLevel::Base); // Test MarkerHandleSet. +TEST_CASE("CompileCopying MarkerHandleSet") { + + // These are compile-time tests to check that basic copy and move + // operations are defined correctly. + + SECTION("CopyingMoving") { + MarkerHandleSet s; + MarkerHandleSet s2; + + // Copy constructor + MarkerHandleSet sa(s); + // Copy assignment + MarkerHandleSet sb; + sb = s; + + // Move constructor + MarkerHandleSet sc(std::move(s)); + // Move assignment + MarkerHandleSet sd; + sd = (std::move(s2)); + } + +} + TEST_CASE("MarkerHandleSet") { MarkerHandleSet mhs; diff --git a/test/unit/testRunStyles.cxx b/test/unit/testRunStyles.cxx index 92e6b9ae8..74be54dc7 100644 --- a/test/unit/testRunStyles.cxx +++ b/test/unit/testRunStyles.cxx @@ -25,6 +25,52 @@ using namespace Scintilla::Internal; // Test RunStyles. +using UniqueInt = std::unique_ptr; + +TEST_CASE("CompileCopying RunStyles") { + + // These are compile-time tests to check that basic copy and move + // operations are defined correctly. + + SECTION("CopyingMoving") { + RunStyles s; + RunStyles s2; + + // Copy constructor + RunStyles sa(s); + // Copy assignment fails + RunStyles sb; + sb = s; + + // Move constructor + RunStyles sc(std::move(s)); + // Move assignment + RunStyles sd; + sd = (std::move(s2)); + } + +#if defined(SHOW_COPY_BUILD_FAILURES) + // It should be reasonable to instantiate RunStyles where STYLE is move-only but fails + SECTION("MoveOnly") { + RunStyles s; + + // Copy is not defined for std::unique_ptr + // Copy constructor fails + RunStyles sa(s); + // Copy assignment fails + RunStyles sb; + sb = s; + + // Move constructor fails + RunStyles sc(std::move(s)); + // Move assignment fails + RunStyles sd; + sd = (std::move(s)); + } +#endif + +} + namespace Scintilla::Internal { // Xcode clang 9.0 doesn't like this when in the unnamed namespace bool operator==(const FillResult &fra, const FillResult &frb) { return fra.changed == frb.changed && diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx index 763fa027c..3a784d4c2 100644 --- a/test/unit/testSparseVector.cxx +++ b/test/unit/testSparseVector.cxx @@ -27,6 +27,51 @@ using namespace Scintilla::Internal; // Test SparseVector. +using UniqueInt = std::unique_ptr; + +TEST_CASE("CompileCopying SparseVector") { + + // These are compile-time tests to check that basic copy and move + // operations are defined correctly. + + SECTION("CopyingMoving") { + SparseVector s; + SparseVector s2; + + // Copy constructor + SparseVector sa(s); + // Copy assignment + SparseVector sb; + sb = s; + + // Move constructor + SparseVector sc(std::move(s)); + // Move assignment + SparseVector sd; + sd = (std::move(s2)); + } + + SECTION("MoveOnly") { + SparseVector s; + +#if defined(SHOW_COPY_BUILD_FAILURES) + // Copy is not defined for std::unique_ptr + // Copy constructor fails + SparseVector sa(s); + // Copy assignment fails + SparseVector sb; + sb = s; +#endif + + // Move constructor + SparseVector sc(std::move(s)); + // Move assignment + SparseVector sd; + sd = (std::move(s)); + } + +} + // Helper to produce a string representation of a SparseVector // to simplify checks. static std::string Representation(const SparseVector &st) { diff --git a/test/unit/testSplitVector.cxx b/test/unit/testSplitVector.cxx index aa855f1b1..c836a4ffe 100644 --- a/test/unit/testSplitVector.cxx +++ b/test/unit/testSplitVector.cxx @@ -23,6 +23,53 @@ using namespace Scintilla::Internal; // Test SplitVector. +using UniqueInt = std::unique_ptr; + +// Test SplitVector. + +TEST_CASE("CompileCopying SplitVector") { + + // These are compile-time tests to check that basic copy and move + // operations are defined correctly. + + SECTION("CopyingMoving") { + SplitVector s; + SplitVector s2; + + // Copy constructor fails + SplitVector sa(s); + // Copy assignment fails + SplitVector sb; + sb = s; + + // Move constructor fails + SplitVector sc(std::move(s)); + // Move assignment fails + SplitVector sd; + sd = (std::move(s2)); + } + + SECTION("MoveOnly") { + SplitVector s; + +#if defined(SHOW_COPY_BUILD_FAILURES) + // Copy is not defined for std::unique_ptr + // Copy constructor fails + SplitVector sa(s); + // Copy assignment fails + SplitVector sb; + sb = s; +#endif + + // Move constructor fails + SplitVector sc(std::move(s)); + // Move assignment fails + SplitVector sd; + sd = (std::move(s)); + } + +} + struct StringSetHolder { SplitVector sa; bool Check() const noexcept { -- cgit v1.2.3