2013-01-25 00:46:29 +00:00
|
|
|
// Unit Tests for Scintilla internal data structures
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
#include <stdexcept>
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <algorithm>
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2013-01-25 00:46:29 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
|
|
|
|
#include "SplitVector.h"
|
|
|
|
#include "Partitioning.h"
|
|
|
|
#include "RunStyles.h"
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "catch.hpp"
|
2013-01-25 00:46:29 +00:00
|
|
|
|
|
|
|
// Test RunStyles.
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
TEST_CASE("RunStyles") {
|
|
|
|
|
|
|
|
RunStyles rs;
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("IsEmptyInitially") {
|
|
|
|
REQUIRE(0 == rs.Length());
|
|
|
|
REQUIRE(1 == rs.Runs());
|
2013-01-25 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("SimpleInsert") {
|
|
|
|
rs.InsertSpace(0, 1);
|
|
|
|
REQUIRE(1 == rs.Length());
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
REQUIRE(0 == rs.ValueAt(0));
|
|
|
|
REQUIRE(1 == rs.FindNextChange(0, rs.Length()));
|
|
|
|
REQUIRE(2 == rs.FindNextChange(1, rs.Length()));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("TwoRuns") {
|
|
|
|
rs.InsertSpace(0, 2);
|
|
|
|
REQUIRE(2 == rs.Length());
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
rs.SetValueAt(0, 2);
|
|
|
|
REQUIRE(2 == rs.Runs());
|
|
|
|
REQUIRE(2 == rs.ValueAt(0));
|
|
|
|
REQUIRE(0 == rs.ValueAt(1));
|
|
|
|
REQUIRE(1 == rs.FindNextChange(0, rs.Length()));
|
|
|
|
REQUIRE(2 == rs.FindNextChange(1, rs.Length()));
|
|
|
|
REQUIRE(3 == rs.FindNextChange(2, rs.Length()));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("LongerRuns") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
rs.SetValueAt(0, 3);
|
|
|
|
rs.SetValueAt(1, 3);
|
|
|
|
REQUIRE(3 == rs.ValueAt(0));
|
|
|
|
REQUIRE(3 == rs.ValueAt(1));
|
|
|
|
REQUIRE(0 == rs.ValueAt(2));
|
|
|
|
REQUIRE(2 == rs.Runs());
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(0 == rs.StartRun(0));
|
|
|
|
REQUIRE(2 == rs.EndRun(0));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(0 == rs.StartRun(1));
|
|
|
|
REQUIRE(2 == rs.EndRun(1));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(2 == rs.StartRun(2));
|
|
|
|
REQUIRE(5 == rs.EndRun(2));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(2 == rs.StartRun(3));
|
|
|
|
REQUIRE(5 == rs.EndRun(3));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(2 == rs.StartRun(4));
|
|
|
|
REQUIRE(5 == rs.EndRun(4));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// At end
|
|
|
|
REQUIRE(2 == rs.StartRun(5));
|
|
|
|
REQUIRE(5 == rs.EndRun(5));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// After end is same as end
|
|
|
|
REQUIRE(2 == rs.StartRun(6));
|
|
|
|
REQUIRE(5 == rs.EndRun(6));
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
REQUIRE(2 == rs.FindNextChange(0, rs.Length()));
|
|
|
|
REQUIRE(5 == rs.FindNextChange(2, rs.Length()));
|
|
|
|
REQUIRE(6 == rs.FindNextChange(5, rs.Length()));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("FillRange") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 3;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(1 == startFill);
|
|
|
|
REQUIRE(3 == lengthFill);
|
|
|
|
|
|
|
|
REQUIRE(0 == rs.ValueAt(0));
|
|
|
|
REQUIRE(99 == rs.ValueAt(1));
|
|
|
|
REQUIRE(99 == rs.ValueAt(2));
|
|
|
|
REQUIRE(99 == rs.ValueAt(3));
|
|
|
|
REQUIRE(0 == rs.ValueAt(4));
|
|
|
|
|
|
|
|
REQUIRE(0 == rs.StartRun(0));
|
|
|
|
REQUIRE(1 == rs.EndRun(0));
|
|
|
|
|
|
|
|
REQUIRE(1 == rs.StartRun(1));
|
|
|
|
REQUIRE(4 == rs.EndRun(1));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("FillRangeAlreadyFilled") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 3;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(1 == startFill);
|
|
|
|
REQUIRE(3 == lengthFill);
|
|
|
|
|
|
|
|
int startFill2 = 2;
|
|
|
|
int lengthFill2 = 1;
|
|
|
|
// Compiler warnings if 'false' used instead of '0' as expected value:
|
|
|
|
REQUIRE(0 == rs.FillRange(startFill2, 99, lengthFill2));
|
|
|
|
REQUIRE(2 == startFill2);
|
|
|
|
REQUIRE(1 == lengthFill2);
|
|
|
|
REQUIRE(0 == rs.ValueAt(0));
|
|
|
|
REQUIRE(99 == rs.ValueAt(1));
|
|
|
|
REQUIRE(99 == rs.ValueAt(2));
|
|
|
|
REQUIRE(99 == rs.ValueAt(3));
|
|
|
|
REQUIRE(0 == rs.ValueAt(4));
|
|
|
|
REQUIRE(3 == rs.Runs());
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("FillRangeAlreadyPartFilled") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 2;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(1 == startFill);
|
|
|
|
REQUIRE(2 == lengthFill);
|
|
|
|
|
|
|
|
int startFill2 = 2;
|
|
|
|
int lengthFill2 = 2;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill2, 99, lengthFill2));
|
|
|
|
REQUIRE(3 == startFill2);
|
|
|
|
REQUIRE(1 == lengthFill2);
|
|
|
|
REQUIRE(3 == rs.Runs());
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("DeleteRange") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
rs.SetValueAt(0, 3);
|
|
|
|
REQUIRE(2 == rs.Runs());
|
|
|
|
rs.SetValueAt(1, 3);
|
|
|
|
REQUIRE(2 == rs.Runs());
|
|
|
|
rs.DeleteRange(1, 1);
|
|
|
|
REQUIRE(4 == rs.Length());
|
|
|
|
REQUIRE(2 == rs.Runs());
|
|
|
|
REQUIRE(3 == rs.ValueAt(0));
|
|
|
|
REQUIRE(0 == rs.ValueAt(1));
|
|
|
|
|
|
|
|
REQUIRE(0 == rs.StartRun(0));
|
|
|
|
REQUIRE(1 == rs.EndRun(0));
|
|
|
|
|
|
|
|
REQUIRE(1 == rs.StartRun(1));
|
|
|
|
REQUIRE(4 == rs.EndRun(1));
|
|
|
|
|
|
|
|
REQUIRE(1 == rs.StartRun(2));
|
|
|
|
REQUIRE(4 == rs.EndRun(2));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("Find") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 3;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(1 == startFill);
|
|
|
|
REQUIRE(3 == lengthFill);
|
|
|
|
|
|
|
|
REQUIRE(0 == rs.Find(0,0));
|
|
|
|
REQUIRE(1 == rs.Find(99,0));
|
|
|
|
REQUIRE(-1 == rs.Find(3,0));
|
|
|
|
|
|
|
|
REQUIRE(4 == rs.Find(0,1));
|
|
|
|
REQUIRE(1 == rs.Find(99,1));
|
|
|
|
REQUIRE(-1 == rs.Find(3,1));
|
|
|
|
|
|
|
|
REQUIRE(4 == rs.Find(0,2));
|
|
|
|
REQUIRE(2 == rs.Find(99,2));
|
|
|
|
REQUIRE(-1 == rs.Find(3, 2));
|
|
|
|
|
|
|
|
REQUIRE(4 == rs.Find(0,4));
|
|
|
|
REQUIRE(-1 == rs.Find(99,4));
|
|
|
|
REQUIRE(-1 == rs.Find(3,4));
|
|
|
|
|
|
|
|
REQUIRE(-1 == rs.Find(0,5));
|
|
|
|
REQUIRE(-1 == rs.Find(99,5));
|
|
|
|
REQUIRE(-1 == rs.Find(3,5));
|
|
|
|
|
|
|
|
REQUIRE(-1 == rs.Find(0,6));
|
|
|
|
REQUIRE(-1 == rs.Find(99,6));
|
|
|
|
REQUIRE(-1 == rs.Find(3,6));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("AllSame") {
|
|
|
|
REQUIRE(true == rs.AllSame());
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
REQUIRE(true == rs.AllSame());
|
|
|
|
REQUIRE(0 == rs.AllSameAs(88));
|
|
|
|
REQUIRE(true == rs.AllSameAs(0));
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 3;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(0 == rs.AllSame());
|
|
|
|
REQUIRE(0 == rs.AllSameAs(88));
|
|
|
|
REQUIRE(0 == rs.AllSameAs(0));
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 0, lengthFill));
|
|
|
|
REQUIRE(true == rs.AllSame());
|
|
|
|
REQUIRE(0 == rs.AllSameAs(88));
|
|
|
|
REQUIRE(true == rs.AllSameAs(0));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("FindWithReversion") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 1;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(1 == startFill);
|
|
|
|
REQUIRE(1 == lengthFill);
|
|
|
|
REQUIRE(3 == rs.Runs());
|
|
|
|
|
|
|
|
startFill = 2;
|
|
|
|
lengthFill = 1;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(2 == startFill);
|
|
|
|
REQUIRE(1 == lengthFill);
|
|
|
|
REQUIRE(3 == rs.Runs());
|
|
|
|
|
|
|
|
startFill = 1;
|
|
|
|
lengthFill = 1;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 0, lengthFill));
|
|
|
|
REQUIRE(3 == rs.Runs());
|
|
|
|
REQUIRE(1 == lengthFill);
|
|
|
|
|
|
|
|
startFill = 2;
|
|
|
|
lengthFill = 1;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 0, lengthFill));
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
REQUIRE(1 == lengthFill);
|
|
|
|
|
|
|
|
REQUIRE(-1 == rs.Find(0,6));
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("FinalRunInversion") {
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
rs.InsertSpace(0, 1);
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
rs.SetValueAt(0, 1);
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
rs.InsertSpace(1, 1);
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
rs.SetValueAt(1, 1);
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
rs.SetValueAt(1, 0);
|
|
|
|
REQUIRE(2 == rs.Runs());
|
|
|
|
rs.SetValueAt(1, 1);
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("DeleteAll") {
|
|
|
|
rs.InsertSpace(0, 5);
|
|
|
|
rs.SetValueAt(0, 3);
|
|
|
|
rs.SetValueAt(1, 3);
|
|
|
|
rs.DeleteAll();
|
|
|
|
REQUIRE(0 == rs.Length());
|
|
|
|
REQUIRE(0 == rs.ValueAt(0));
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("DeleteSecond") {
|
|
|
|
rs.InsertSpace(0, 3);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 1;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(3 == rs.Length());
|
|
|
|
REQUIRE(3 == rs.Runs());
|
|
|
|
rs.DeleteRange(1, 1);
|
|
|
|
REQUIRE(2 == rs.Length());
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
}
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("DeleteEndRun") {
|
|
|
|
rs.InsertSpace(0, 2);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 1;
|
|
|
|
REQUIRE(true == rs.FillRange(startFill, 99, lengthFill));
|
|
|
|
REQUIRE(2 == rs.Length());
|
|
|
|
REQUIRE(2 == rs.Runs());
|
|
|
|
REQUIRE(0 == rs.StartRun(0));
|
|
|
|
REQUIRE(1 == rs.EndRun(0));
|
|
|
|
REQUIRE(1 == rs.StartRun(1));
|
|
|
|
REQUIRE(2 == rs.EndRun(1));
|
|
|
|
rs.DeleteRange(1, 1);
|
|
|
|
REQUIRE(1 == rs.Length());
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
REQUIRE(0 == rs.StartRun(0));
|
|
|
|
REQUIRE(1 == rs.EndRun(0));
|
|
|
|
REQUIRE(0 == rs.StartRun(1));
|
|
|
|
REQUIRE(1 == rs.EndRun(1));
|
|
|
|
rs.Check();
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SECTION("OutsideBounds") {
|
|
|
|
rs.InsertSpace(0, 1);
|
|
|
|
int startFill = 1;
|
|
|
|
int lengthFill = 1;
|
|
|
|
rs.FillRange(startFill, 99, lengthFill);
|
|
|
|
REQUIRE(1 == rs.Length());
|
|
|
|
REQUIRE(1 == rs.Runs());
|
|
|
|
REQUIRE(0 == rs.StartRun(0));
|
|
|
|
REQUIRE(1 == rs.EndRun(0));
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
}
|