notepad-plus-plus-legacy/scintilla/test/unit/testDecoration.cxx

96 lines
2.2 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>
#include <stdexcept>
2019-05-04 18:14:48 +00:00
#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 "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "Decoration.h"
#include "catch.hpp"
const int indicator=4;
2019-05-04 18:14:48 +00:00
using namespace Scintilla;
// Test Decoration.
TEST_CASE("Decoration") {
2019-05-04 18:14:48 +00:00
std::unique_ptr<IDecoration> deco = DecorationCreate(false, indicator);
SECTION("HasCorrectIndicator") {
2019-05-04 18:14:48 +00:00
REQUIRE(indicator == deco->Indicator());
}
SECTION("IsEmptyInitially") {
2019-05-04 18:14:48 +00:00
REQUIRE(0 == deco->Length());
REQUIRE(1 == deco->Runs());
REQUIRE(deco->Empty());
}
SECTION("SimpleSpace") {
2019-05-04 18:14:48 +00:00
deco->InsertSpace(0, 1);
REQUIRE(deco->Empty());
}
SECTION("SimpleRun") {
2019-05-04 18:14:48 +00:00
deco->InsertSpace(0, 1);
deco->SetValueAt(0, 2);
REQUIRE(!deco->Empty());
}
}
// Test DecorationList.
TEST_CASE("DecorationList") {
2019-05-04 18:14:48 +00:00
std::unique_ptr<IDecorationList> decol = DecorationListCreate(false);
SECTION("HasCorrectIndicator") {
2019-05-04 18:14:48 +00:00
decol->SetCurrentIndicator(indicator);
REQUIRE(indicator == decol->GetCurrentIndicator());
}
SECTION("HasCorrectCurrentValue") {
const int value = 55;
2019-05-04 18:14:48 +00:00
decol->SetCurrentValue(value);
REQUIRE(value == decol->GetCurrentValue());
}
SECTION("ExpandSetValues") {
2019-05-04 18:14:48 +00:00
decol->SetCurrentIndicator(indicator);
decol->InsertSpace(0, 9);
const int value = 59;
2019-05-04 18:14:48 +00:00
const Sci::Position position = 4;
const Sci::Position fillLength = 3;
auto fr = decol->FillRange(position, value, fillLength);
REQUIRE(fr.changed);
REQUIRE(fr.position == 4);
REQUIRE(fr.fillLength == 3);
REQUIRE(decol->ValueAt(indicator, 5) == value);
REQUIRE(decol->AllOnFor(5) == (1 << indicator));
REQUIRE(decol->Start(indicator, 5) == 4);
REQUIRE(decol->End(indicator, 5) == 7);
const int indicatorB=6;
2019-05-04 18:14:48 +00:00
decol->SetCurrentIndicator(indicatorB);
fr = decol->FillRange(position, value, fillLength);
REQUIRE(fr.changed);
REQUIRE(decol->AllOnFor(5) == ((1 << indicator) | (1 << indicatorB)));
decol->DeleteRange(5, 1);
REQUIRE(decol->Start(indicatorB, 5) == 4);
REQUIRE(decol->End(indicatorB, 5) == 6);
}
}