notepad-plus-plus/scintilla/test/unit/testContractionState.cxx

160 lines
4.0 KiB
C++
Raw Normal View History

// Unit Tests for Scintilla internal data structures
2019-05-04 18:14:48 +00:00
#include <cstddef>
#include <cstring>
2019-05-04 18:14:48 +00:00
#include <stdexcept>
#include <string_view>
#include <vector>
#include <algorithm>
2019-05-04 18:14:48 +00:00
#include <memory>
#include "Platform.h"
2019-05-04 18:14:48 +00:00
#include "Position.h"
#include "UniqueString.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "ContractionState.h"
#include "catch.hpp"
2019-05-04 18:14:48 +00:00
using namespace Scintilla;
// Test ContractionState.
TEST_CASE("ContractionState") {
2019-05-04 18:14:48 +00:00
std::unique_ptr<IContractionState> pcs = ContractionStateCreate(false);
SECTION("IsEmptyInitially") {
2019-05-04 18:14:48 +00:00
REQUIRE(1 == pcs->LinesInDoc());
REQUIRE(1 == pcs->LinesDisplayed());
REQUIRE(0 == pcs->DisplayFromDoc(0));
REQUIRE(0 == pcs->DocFromDisplay(0));
}
SECTION("OneLine") {
2019-05-04 18:14:48 +00:00
pcs->InsertLines(0, 1);
REQUIRE(2 == pcs->LinesInDoc());
REQUIRE(2 == pcs->LinesDisplayed());
REQUIRE(0 == pcs->DisplayFromDoc(0));
REQUIRE(0 == pcs->DocFromDisplay(0));
REQUIRE(1 == pcs->DisplayFromDoc(1));
REQUIRE(1 == pcs->DocFromDisplay(1));
}
SECTION("InsertionThenDeletions") {
2019-05-04 18:14:48 +00:00
pcs->InsertLines(0,4);
pcs->DeleteLines(1, 1);
2019-05-04 18:14:48 +00:00
REQUIRE(4 == pcs->LinesInDoc());
REQUIRE(4 == pcs->LinesDisplayed());
for (int l=0;l<4;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(l == pcs->DisplayFromDoc(l));
REQUIRE(l == pcs->DocFromDisplay(l));
}
2019-05-04 18:14:48 +00:00
pcs->DeleteLines(0,2);
REQUIRE(2 == pcs->LinesInDoc());
REQUIRE(2 == pcs->LinesDisplayed());
for (int l=0;l<2;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(l == pcs->DisplayFromDoc(l));
REQUIRE(l == pcs->DocFromDisplay(l));
}
}
SECTION("ShowHide") {
2019-05-04 18:14:48 +00:00
pcs->InsertLines(0,4);
REQUIRE(true == pcs->GetVisible(0));
REQUIRE(true == pcs->GetVisible(1));
REQUIRE(true == pcs->GetVisible(2));
REQUIRE(5 == pcs->LinesDisplayed());
pcs->SetVisible(1, 1, false);
REQUIRE(true == pcs->GetVisible(0));
REQUIRE(false == pcs->GetVisible(1));
REQUIRE(true == pcs->GetVisible(2));
REQUIRE(4 == pcs->LinesDisplayed());
REQUIRE(true == pcs->HiddenLines());
pcs->SetVisible(1, 2, true);
for (int l=0;l<4;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(true == pcs->GetVisible(0));
}
2019-05-04 18:14:48 +00:00
pcs->SetVisible(1, 1, false);
REQUIRE(false == pcs->GetVisible(1));
pcs->ShowAll();
for (int l=0;l<4;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(true == pcs->GetVisible(0));
}
2019-05-04 18:14:48 +00:00
REQUIRE(false == pcs->HiddenLines());
}
SECTION("Hidden") {
2019-05-04 18:14:48 +00:00
pcs->InsertLines(0,1);
for (int l=0;l<2;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(true == pcs->GetVisible(0));
}
2019-05-04 18:14:48 +00:00
REQUIRE(false == pcs->HiddenLines());
2019-05-04 18:14:48 +00:00
pcs->SetVisible(1, 1, false);
REQUIRE(true == pcs->GetVisible(0));
REQUIRE(false == pcs->GetVisible(1));
REQUIRE(true == pcs->HiddenLines());
2019-05-04 18:14:48 +00:00
pcs->SetVisible(1, 1, true);
for (int l=0;l<2;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(true == pcs->GetVisible(0));
}
2019-05-04 18:14:48 +00:00
REQUIRE(false == pcs->HiddenLines());
}
SECTION("Contracting") {
2019-05-04 18:14:48 +00:00
pcs->InsertLines(0,4);
for (int l=0;l<4;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(true == pcs->GetExpanded(l));
}
2019-05-04 18:14:48 +00:00
pcs->SetExpanded(2, false);
REQUIRE(true == pcs->GetExpanded(1));
REQUIRE(false == pcs->GetExpanded(2));
REQUIRE(true == pcs->GetExpanded(3));
2019-05-04 18:14:48 +00:00
REQUIRE(2 == pcs->ContractedNext(0));
REQUIRE(2 == pcs->ContractedNext(1));
REQUIRE(2 == pcs->ContractedNext(2));
REQUIRE(-1 == pcs->ContractedNext(3));
2019-05-04 18:14:48 +00:00
pcs->SetExpanded(2, true);
REQUIRE(true == pcs->GetExpanded(1));
REQUIRE(true == pcs->GetExpanded(2));
REQUIRE(true == pcs->GetExpanded(3));
}
SECTION("ChangeHeight") {
2019-05-04 18:14:48 +00:00
pcs->InsertLines(0,4);
for (int l=0;l<4;l++) {
2019-05-04 18:14:48 +00:00
REQUIRE(1 == pcs->GetHeight(l));
}
2019-05-04 18:14:48 +00:00
pcs->SetHeight(1, 2);
REQUIRE(1 == pcs->GetHeight(0));
REQUIRE(2 == pcs->GetHeight(1));
REQUIRE(1 == pcs->GetHeight(2));
}
SECTION("SetFoldDisplayText") {
pcs->InsertLines(0, 4);
pcs->SetFoldDisplayText(1, "abc");
REQUIRE(strcmp(pcs->GetFoldDisplayText(1), "abc") == 0);
pcs->SetFoldDisplayText(1, "def");
REQUIRE(strcmp(pcs->GetFoldDisplayText(1), "def") == 0);
pcs->SetFoldDisplayText(1, nullptr);
REQUIRE(static_cast<const char *>(nullptr) == pcs->GetFoldDisplayText(1));
}
}