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 141 142 143 144 145 146 147 148
|
// 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 <gtest/gtest.h>
// Test ContractionState.
class ContractionStateTest : public ::testing::Test {
protected:
virtual void SetUp() {
pcs = new ContractionState();
}
virtual void TearDown() {
delete pcs;
pcs = 0;
}
ContractionState *pcs;
};
TEST_F(ContractionStateTest, IsEmptyInitially) {
EXPECT_EQ(1, pcs->LinesInDoc());
EXPECT_EQ(1, pcs->LinesDisplayed());
EXPECT_EQ(0, pcs->DisplayFromDoc(0));
EXPECT_EQ(0, pcs->DocFromDisplay(0));
}
TEST_F(ContractionStateTest, OneLine) {
pcs->InsertLine(0);
EXPECT_EQ(2, pcs->LinesInDoc());
EXPECT_EQ(2, pcs->LinesDisplayed());
EXPECT_EQ(0, pcs->DisplayFromDoc(0));
EXPECT_EQ(0, pcs->DocFromDisplay(0));
EXPECT_EQ(1, pcs->DisplayFromDoc(1));
EXPECT_EQ(1, pcs->DocFromDisplay(1));
}
TEST_F(ContractionStateTest, InsertionThenDeletions) {
pcs->InsertLines(0,4);
pcs->DeleteLine(1);
EXPECT_EQ(4, pcs->LinesInDoc());
EXPECT_EQ(4, pcs->LinesDisplayed());
for (int l=0;l<4;l++) {
EXPECT_EQ(l, pcs->DisplayFromDoc(l));
EXPECT_EQ(l, pcs->DocFromDisplay(l));
}
pcs->DeleteLines(0,2);
EXPECT_EQ(2, pcs->LinesInDoc());
EXPECT_EQ(2, pcs->LinesDisplayed());
for (int l=0;l<2;l++) {
EXPECT_EQ(l, pcs->DisplayFromDoc(l));
EXPECT_EQ(l, pcs->DocFromDisplay(l));
}
}
TEST_F(ContractionStateTest, ShowHide) {
pcs->InsertLines(0,4);
EXPECT_EQ(true, pcs->GetVisible(0));
EXPECT_EQ(true, pcs->GetVisible(1));
EXPECT_EQ(true, pcs->GetVisible(2));
EXPECT_EQ(5, pcs->LinesDisplayed());
pcs->SetVisible(1, 1, false);
EXPECT_EQ(true, pcs->GetVisible(0));
EXPECT_EQ(0, pcs->GetVisible(1));
EXPECT_EQ(true, pcs->GetVisible(2));
EXPECT_EQ(4, pcs->LinesDisplayed());
EXPECT_EQ(1, pcs->HiddenLines());
pcs->SetVisible(1, 2, true);
for (int l=0;l<4;l++) {
EXPECT_EQ(true, pcs->GetVisible(0));
}
pcs->SetVisible(1, 1, false);
EXPECT_EQ(0, pcs->GetVisible(1));
pcs->ShowAll();
for (int l=0;l<4;l++) {
EXPECT_EQ(true, pcs->GetVisible(0));
}
EXPECT_EQ(0, pcs->HiddenLines());
}
TEST_F(ContractionStateTest, Hidden) {
pcs->InsertLines(0,1);
for (int l=0;l<2;l++) {
EXPECT_EQ(true, pcs->GetVisible(0));
}
EXPECT_EQ(0, pcs->HiddenLines());
pcs->SetVisible(1, 1, false);
EXPECT_EQ(true, pcs->GetVisible(0));
EXPECT_EQ(0, pcs->GetVisible(1));
EXPECT_EQ(1, pcs->HiddenLines());
pcs->SetVisible(1, 1, true);
for (int l=0;l<2;l++) {
EXPECT_EQ(true, pcs->GetVisible(0));
}
EXPECT_EQ(0, pcs->HiddenLines());
}
TEST_F(ContractionStateTest, Contracting) {
pcs->InsertLines(0,4);
for (int l=0;l<4;l++) {
EXPECT_EQ(true, pcs->GetExpanded(l));
}
pcs->SetExpanded(2, false);
EXPECT_EQ(true, pcs->GetExpanded(1));
EXPECT_EQ(0, pcs->GetExpanded(2));
EXPECT_EQ(true, pcs->GetExpanded(3));
EXPECT_EQ(2, pcs->ContractedNext(0));
EXPECT_EQ(2, pcs->ContractedNext(1));
EXPECT_EQ(2, pcs->ContractedNext(2));
EXPECT_EQ(-1, pcs->ContractedNext(3));
pcs->SetExpanded(2, true);
EXPECT_EQ(true, pcs->GetExpanded(1));
EXPECT_EQ(true, pcs->GetExpanded(2));
EXPECT_EQ(true, pcs->GetExpanded(3));
}
TEST_F(ContractionStateTest, ChangeHeight) {
pcs->InsertLines(0,4);
for (int l=0;l<4;l++) {
EXPECT_EQ(1, pcs->GetHeight(l));
}
pcs->SetHeight(1, 2);
EXPECT_EQ(1, pcs->GetHeight(0));
EXPECT_EQ(2, pcs->GetHeight(1));
EXPECT_EQ(1, pcs->GetHeight(2));
}
|