1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Unit Tests for Scintilla internal data structures
#include <string.h>
#include <algorithm>
#include "Platform.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "ContractionState.h"
#include "catch.hpp"
// Test ContractionState.
TEST_CASE("ContractionState") {
ContractionState cs;
SECTION("IsEmptyInitially") {
REQUIRE(1 == cs.LinesInDoc());
REQUIRE(1 == cs.LinesDisplayed());
REQUIRE(0 == cs.DisplayFromDoc(0));
REQUIRE(0 == cs.DocFromDisplay(0));
}
SECTION("OneLine") {
cs.InsertLine(0);
REQUIRE(2 == cs.LinesInDoc());
REQUIRE(2 == cs.LinesDisplayed());
REQUIRE(0 == cs.DisplayFromDoc(0));
REQUIRE(0 == cs.DocFromDisplay(0));
REQUIRE(1 == cs.DisplayFromDoc(1));
REQUIRE(1 == cs.DocFromDisplay(1));
}
SECTION("InsertionThenDeletions") {
cs.InsertLines(0,4);
cs.DeleteLine(1);
REQUIRE(4 == cs.LinesInDoc());
REQUIRE(4 == cs.LinesDisplayed());
for (int l=0;l<4;l++) {
REQUIRE(l == cs.DisplayFromDoc(l));
REQUIRE(l == cs.DocFromDisplay(l));
}
cs.DeleteLines(0,2);
REQUIRE(2 == cs.LinesInDoc());
REQUIRE(2 == cs.LinesDisplayed());
for (int l=0;l<2;l++) {
REQUIRE(l == cs.DisplayFromDoc(l));
REQUIRE(l == cs.DocFromDisplay(l));
}
}
SECTION("ShowHide") {
cs.InsertLines(0,4);
REQUIRE(true == cs.GetVisible(0));
REQUIRE(true == cs.GetVisible(1));
REQUIRE(true == cs.GetVisible(2));
REQUIRE(5 == cs.LinesDisplayed());
cs.SetVisible(1, 1, false);
REQUIRE(true == cs.GetVisible(0));
REQUIRE(0 == cs.GetVisible(1));
REQUIRE(true == cs.GetVisible(2));
REQUIRE(4 == cs.LinesDisplayed());
REQUIRE(1 == cs.HiddenLines());
cs.SetVisible(1, 2, true);
for (int l=0;l<4;l++) {
REQUIRE(true == cs.GetVisible(0));
}
cs.SetVisible(1, 1, false);
REQUIRE(0 == cs.GetVisible(1));
cs.ShowAll();
for (int l=0;l<4;l++) {
REQUIRE(true == cs.GetVisible(0));
}
REQUIRE(0 == cs.HiddenLines());
}
SECTION("Hidden") {
cs.InsertLines(0,1);
for (int l=0;l<2;l++) {
REQUIRE(true == cs.GetVisible(0));
}
REQUIRE(0 == cs.HiddenLines());
cs.SetVisible(1, 1, false);
REQUIRE(true == cs.GetVisible(0));
REQUIRE(0 == cs.GetVisible(1));
REQUIRE(1 == cs.HiddenLines());
cs.SetVisible(1, 1, true);
for (int l=0;l<2;l++) {
REQUIRE(true == cs.GetVisible(0));
}
REQUIRE(0 == cs.HiddenLines());
}
SECTION("Contracting") {
cs.InsertLines(0,4);
for (int l=0;l<4;l++) {
REQUIRE(true == cs.GetExpanded(l));
}
cs.SetExpanded(2, false);
REQUIRE(true == cs.GetExpanded(1));
REQUIRE(0 == cs.GetExpanded(2));
REQUIRE(true == cs.GetExpanded(3));
REQUIRE(2 == cs.ContractedNext(0));
REQUIRE(2 == cs.ContractedNext(1));
REQUIRE(2 == cs.ContractedNext(2));
REQUIRE(-1 == cs.ContractedNext(3));
cs.SetExpanded(2, true);
REQUIRE(true == cs.GetExpanded(1));
REQUIRE(true == cs.GetExpanded(2));
REQUIRE(true == cs.GetExpanded(3));
}
SECTION("ChangeHeight") {
cs.InsertLines(0,4);
for (int l=0;l<4;l++) {
REQUIRE(1 == cs.GetHeight(l));
}
cs.SetHeight(1, 2);
REQUIRE(1 == cs.GetHeight(0));
REQUIRE(2 == cs.GetHeight(1));
REQUIRE(1 == cs.GetHeight(2));
}
}
|