2013-01-25 00:46:29 +00:00
|
|
|
// Unit Tests for Scintilla internal data structures
|
|
|
|
|
|
|
|
#include <string>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <string_view>
|
2013-01-25 00:46:29 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <memory>
|
2013-01-25 00:46:29 +00:00
|
|
|
|
|
|
|
#include "Platform.h"
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "Sci_Position.h"
|
|
|
|
|
2013-01-25 00:46:29 +00:00
|
|
|
#include "SparseState.h"
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "catch.hpp"
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
using namespace Scintilla;
|
|
|
|
|
2013-01-25 00:46:29 +00:00
|
|
|
// Test SparseState.
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
TEST_CASE("SparseState") {
|
|
|
|
|
|
|
|
SparseState<int> ss;
|
|
|
|
|
|
|
|
SECTION("IsEmptyInitially") {
|
|
|
|
REQUIRE(0u == ss.size());
|
|
|
|
int val = ss.ValueAt(0);
|
|
|
|
REQUIRE(0 == val);
|
2013-01-25 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("SimpleSetAndGet") {
|
|
|
|
ss.Set(0, 22);
|
|
|
|
ss.Set(1, 23);
|
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE(0 == ss.ValueAt(-1));
|
|
|
|
REQUIRE(22 == ss.ValueAt(0));
|
|
|
|
REQUIRE(23 == ss.ValueAt(1));
|
|
|
|
REQUIRE(23 == ss.ValueAt(2));
|
2013-01-25 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("RetrieveBetween") {
|
|
|
|
ss.Set(0, 10);
|
|
|
|
ss.Set(2, 12);
|
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE(0 == ss.ValueAt(-1));
|
|
|
|
REQUIRE(10 == ss.ValueAt(0));
|
|
|
|
REQUIRE(10 == ss.ValueAt(1));
|
|
|
|
REQUIRE(12 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("RetrieveBefore") {
|
|
|
|
ss.Set(2, 12);
|
|
|
|
REQUIRE(1u == ss.size());
|
|
|
|
REQUIRE(0 == ss.ValueAt(-1));
|
|
|
|
REQUIRE(0 == ss.ValueAt(0));
|
|
|
|
REQUIRE(0 == ss.ValueAt(1));
|
|
|
|
REQUIRE(12 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("Delete") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Delete(2);
|
|
|
|
REQUIRE(1u == ss.size());
|
|
|
|
REQUIRE(0 == ss.ValueAt(-1));
|
|
|
|
REQUIRE(30 == ss.ValueAt(0));
|
|
|
|
REQUIRE(30 == ss.ValueAt(1));
|
|
|
|
REQUIRE(30 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("DeleteBetween") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Delete(1);
|
|
|
|
REQUIRE(1u == ss.size());
|
|
|
|
REQUIRE(0 == ss.ValueAt(-1));
|
|
|
|
REQUIRE(30 == ss.ValueAt(0));
|
|
|
|
REQUIRE(30 == ss.ValueAt(1));
|
|
|
|
REQUIRE(30 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("ReplaceLast") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 31);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE(0 == ss.ValueAt(-1));
|
|
|
|
REQUIRE(30 == ss.ValueAt(0));
|
|
|
|
REQUIRE(30 == ss.ValueAt(1));
|
|
|
|
REQUIRE(32 == ss.ValueAt(2));
|
|
|
|
REQUIRE(32 == ss.ValueAt(3));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("OnlyChangeAppended") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 31);
|
|
|
|
ss.Set(3, 31);
|
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("MergeBetween") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Set(4, 34);
|
|
|
|
REQUIRE(3u == ss.size());
|
|
|
|
|
|
|
|
SparseState<int> ssAdditions(3);
|
|
|
|
ssAdditions.Set(4, 34);
|
|
|
|
REQUIRE(1u == ssAdditions.size());
|
|
|
|
bool mergeChanged = ss.Merge(ssAdditions,5);
|
2019-05-04 18:14:48 +00:00
|
|
|
REQUIRE(false == mergeChanged);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
ssAdditions.Set(4, 44);
|
|
|
|
REQUIRE(1u == ssAdditions.size());
|
|
|
|
mergeChanged = ss.Merge(ssAdditions,5);
|
|
|
|
REQUIRE(true == mergeChanged);
|
|
|
|
REQUIRE(3u == ss.size());
|
|
|
|
REQUIRE(44 == ss.ValueAt(4));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("MergeAtExisting") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Set(4, 34);
|
|
|
|
REQUIRE(3u == ss.size());
|
|
|
|
|
|
|
|
SparseState<int> ssAdditions(4);
|
|
|
|
ssAdditions.Set(4, 34);
|
|
|
|
REQUIRE(1u == ssAdditions.size());
|
|
|
|
bool mergeChanged = ss.Merge(ssAdditions,5);
|
2019-05-04 18:14:48 +00:00
|
|
|
REQUIRE(false == mergeChanged);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
ssAdditions.Set(4, 44);
|
|
|
|
REQUIRE(1u == ssAdditions.size());
|
|
|
|
mergeChanged = ss.Merge(ssAdditions,5);
|
|
|
|
REQUIRE(true == mergeChanged);
|
|
|
|
REQUIRE(3u == ss.size());
|
|
|
|
REQUIRE(44 == ss.ValueAt(4));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("MergeWhichRemoves") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Set(4, 34);
|
|
|
|
REQUIRE(3u == ss.size());
|
|
|
|
|
|
|
|
SparseState<int> ssAdditions(2);
|
|
|
|
ssAdditions.Set(2, 22);
|
|
|
|
REQUIRE(1u == ssAdditions.size());
|
|
|
|
REQUIRE(22 == ssAdditions.ValueAt(2));
|
|
|
|
bool mergeChanged = ss.Merge(ssAdditions,5);
|
|
|
|
REQUIRE(true == mergeChanged);
|
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE(22 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("MergeIgnoreSome") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Set(4, 34);
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SparseState<int> ssAdditions(2);
|
|
|
|
ssAdditions.Set(2, 32);
|
|
|
|
bool mergeChanged = ss.Merge(ssAdditions,3);
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
REQUIRE(false == mergeChanged);
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE(32 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("MergeIgnoreSomeStart") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Set(4, 34);
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SparseState<int> ssAdditions(2);
|
|
|
|
ssAdditions.Set(2, 32);
|
|
|
|
bool mergeChanged = ss.Merge(ssAdditions,2);
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
REQUIRE(false == mergeChanged);
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE(32 == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("MergeIgnoreRepeat") {
|
|
|
|
ss.Set(0, 30);
|
|
|
|
ss.Set(2, 32);
|
|
|
|
ss.Set(4, 34);
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SparseState<int> ssAdditions(5);
|
|
|
|
// Appending same value as at end of pss.
|
|
|
|
ssAdditions.Set(5, 34);
|
|
|
|
bool mergeChanged = ss.Merge(ssAdditions,6);
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
REQUIRE(false == mergeChanged);
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(3u == ss.size());
|
|
|
|
REQUIRE(34 == ss.ValueAt(4));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
TEST_CASE("SparseStateString") {
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SparseState<std::string> ss;
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("IsEmptyInitially") {
|
|
|
|
REQUIRE(0u == ss.size());
|
|
|
|
std::string val = ss.ValueAt(0);
|
|
|
|
REQUIRE("" == val);
|
2013-01-25 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("SimpleSetAndGet") {
|
|
|
|
REQUIRE(0u == ss.size());
|
|
|
|
ss.Set(0, "22");
|
|
|
|
ss.Set(1, "23");
|
|
|
|
REQUIRE(2u == ss.size());
|
|
|
|
REQUIRE("" == ss.ValueAt(-1));
|
|
|
|
REQUIRE("22" == ss.ValueAt(0));
|
|
|
|
REQUIRE("23" == ss.ValueAt(1));
|
|
|
|
REQUIRE("23" == ss.ValueAt(2));
|
2013-01-25 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("DeleteBetween") {
|
|
|
|
ss.Set(0, "30");
|
|
|
|
ss.Set(2, "32");
|
|
|
|
ss.Delete(1);
|
|
|
|
REQUIRE(1u == ss.size());
|
|
|
|
REQUIRE("" == ss.ValueAt(-1));
|
|
|
|
REQUIRE("30" == ss.ValueAt(0));
|
|
|
|
REQUIRE("30" == ss.ValueAt(1));
|
|
|
|
REQUIRE("30" == ss.ValueAt(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
|
|
|
}
|