2022-01-05 00:07:50 +01:00
|
|
|
/** @file testSparseVector.cxx
|
|
|
|
** Unit Tests for Scintilla internal data structures
|
|
|
|
**/
|
2019-05-04 20:14:48 +02:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
2022-01-05 00:07:50 +01:00
|
|
|
#include <optional>
|
2019-05-04 20:14:48 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
|
|
|
|
2022-01-05 00:07:50 +01:00
|
|
|
#include "Debugging.h"
|
2019-05-04 20:14:48 +02:00
|
|
|
|
|
|
|
#include "Position.h"
|
|
|
|
#include "UniqueString.h"
|
|
|
|
#include "SplitVector.h"
|
|
|
|
#include "Partitioning.h"
|
|
|
|
#include "SparseVector.h"
|
|
|
|
|
|
|
|
#include "catch.hpp"
|
|
|
|
|
2022-01-05 00:07:50 +01:00
|
|
|
using namespace Scintilla::Internal;
|
2019-05-04 20:14:48 +02:00
|
|
|
|
|
|
|
// Test SparseVector.
|
|
|
|
|
2022-08-27 09:35:52 +02:00
|
|
|
using UniqueInt = std::unique_ptr<int>;
|
|
|
|
|
|
|
|
TEST_CASE("CompileCopying SparseVector") {
|
|
|
|
|
|
|
|
// These are compile-time tests to check that basic copy and move
|
|
|
|
// operations are defined correctly.
|
|
|
|
|
|
|
|
SECTION("CopyingMoving") {
|
|
|
|
SparseVector<int> s;
|
|
|
|
SparseVector<int> s2;
|
|
|
|
|
|
|
|
// Copy constructor
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
const SparseVector<int> sa(s);
|
2022-08-27 09:35:52 +02:00
|
|
|
// Copy assignment
|
|
|
|
SparseVector<int> sb;
|
|
|
|
sb = s;
|
|
|
|
|
|
|
|
// Move constructor
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
const SparseVector<int> sc(std::move(s));
|
2022-08-27 09:35:52 +02:00
|
|
|
// Move assignment
|
|
|
|
SparseVector<int> sd;
|
|
|
|
sd = (std::move(s2));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("MoveOnly") {
|
|
|
|
SparseVector<UniqueInt> s;
|
|
|
|
|
|
|
|
#if defined(SHOW_COPY_BUILD_FAILURES)
|
|
|
|
// Copy is not defined for std::unique_ptr
|
|
|
|
// Copy constructor fails
|
|
|
|
SparseVector<UniqueInt> sa(s);
|
|
|
|
// Copy assignment fails
|
|
|
|
SparseVector<UniqueInt> sb;
|
|
|
|
sb = s;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Move constructor
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
const SparseVector<UniqueInt> sc(std::move(s));
|
2022-08-27 09:35:52 +02:00
|
|
|
// Move assignment
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
SparseVector<UniqueInt> s2;
|
2022-08-27 09:35:52 +02:00
|
|
|
SparseVector<UniqueInt> sd;
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
sd = (std::move(s2));
|
2022-08-27 09:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
namespace {
|
|
|
|
|
2019-05-04 20:14:48 +02:00
|
|
|
// Helper to produce a string representation of a SparseVector<const char *>
|
|
|
|
// to simplify checks.
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
std::string Representation(const SparseVector<UniqueString> &st) {
|
2019-05-04 20:14:48 +02:00
|
|
|
std::string ret;
|
2021-02-21 05:53:09 +01:00
|
|
|
for (int i = 0;i <= st.Length();i++) {
|
2019-05-04 20:14:48 +02:00
|
|
|
const char *value = st.ValueAt(i).get();
|
|
|
|
if (value && *value)
|
|
|
|
ret += value;
|
|
|
|
else
|
|
|
|
ret += "-";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
}
|
|
|
|
|
2019-05-04 20:14:48 +02:00
|
|
|
TEST_CASE("SparseVector") {
|
|
|
|
|
|
|
|
SparseVector<UniqueString> st;
|
|
|
|
|
|
|
|
SECTION("IsEmptyInitially") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(0 == st.Length());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("-" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertSpace") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(static_cast<const char *>(nullptr) == st.ValueAt(0).get());
|
|
|
|
REQUIRE(static_cast<const char *>(nullptr) == st.ValueAt(1).get());
|
|
|
|
REQUIRE(static_cast<const char *>(nullptr) == st.ValueAt(4).get());
|
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertValue") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("---3--" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertAndChangeAndDeleteValue") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
REQUIRE(5 == st.Length());
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("4"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
st.DeletePosition(3);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(4 == st.Length());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("-----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertAndDeleteAtStart") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(1 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("3-----" == Representation(st));
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("-----" == Representation(st));
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("4"));
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("4----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("----" == Representation(st));
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("4"));
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("4---" == Representation(st));
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("---" == Representation(st));
|
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertStringAtStartThenInsertSpaceAtStart") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(1 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("3-----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.InsertSpace(0, 1);
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("-3-----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertSpaceAfterStart") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("1"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("-1----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.InsertSpace(1, 1);
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("--1----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertStringAt1ThenInsertLettersAt1") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("9"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("-9----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.InsertSpace(0, 1);
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("--9----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
// Initial st has allocation of 9 values so this should cause reallocation
|
|
|
|
const std::string letters("ABCDEFGHIJKLMNOP"); // 16 letters
|
|
|
|
for (const char letter : letters) {
|
|
|
|
const char sLetter[] = { letter, 0 };
|
|
|
|
st.InsertSpace(0, 1);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy(sLetter));
|
|
|
|
}
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("-PONMLKJIHGFEDCBA-9----" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("InsertAndDeleteAtEnd") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("5"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("----5-" == Representation(st));
|
|
|
|
st.SetValueAt(5, UniqueStringCopy("6"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE("----56" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.DeletePosition(4);
|
|
|
|
REQUIRE(1 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("----6" == Representation(st));
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("7"));
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("----7" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("SetNULL") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("5"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("----5-" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.SetValueAt(4, nullptr);
|
|
|
|
REQUIRE(1 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("------" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
2022-08-27 09:35:52 +02:00
|
|
|
st.SetValueAt(5, nullptr);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("------" == Representation(st));
|
|
|
|
st.Check();
|
2019-05-04 20:14:48 +02:00
|
|
|
}
|
|
|
|
|
2021-02-21 05:53:09 +01:00
|
|
|
SECTION("CheckDeletionLeavesOrdered") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 1);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("1"));
|
|
|
|
REQUIRE("1-" == Representation(st));
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(1, 1);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("2"));
|
|
|
|
REQUIRE("12-" == Representation(st));
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE("2-" == Representation(st));
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE("-" == Representation(st));
|
|
|
|
}
|
|
|
|
|
2019-05-04 20:14:48 +02:00
|
|
|
SECTION("DeleteAll") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 10);
|
|
|
|
st.SetValueAt(9, UniqueStringCopy("9"));
|
|
|
|
st.SetValueAt(7, UniqueStringCopy("7"));
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("4"));
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(5 == st.Elements());
|
2021-02-21 05:53:09 +01:00
|
|
|
REQUIRE("---34--7-9-" == Representation(st));
|
2022-08-27 09:35:52 +02:00
|
|
|
st.DeleteAll();
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE("-" == Representation(st));
|
2019-05-04 20:14:48 +02:00
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
2021-02-21 05:53:09 +01:00
|
|
|
SECTION("DeleteStarting") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 2);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("1"));
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("2"));
|
|
|
|
REQUIRE("12-" == Representation(st));
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE("2-" == Representation(st));
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE("-" == Representation(st));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("DeleteRange") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 10);
|
|
|
|
st.SetValueAt(9, UniqueStringCopy("9"));
|
|
|
|
st.SetValueAt(7, UniqueStringCopy("7"));
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("4"));
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(5 == st.Elements());
|
|
|
|
REQUIRE(10 == st.Length());
|
|
|
|
REQUIRE("---34--7-9-" == Representation(st));
|
|
|
|
// Delete in space
|
|
|
|
st.DeleteRange(1, 1);
|
|
|
|
REQUIRE(5 == st.Elements());
|
|
|
|
REQUIRE(9 == st.Length());
|
|
|
|
REQUIRE("--34--7-9-" == Representation(st));
|
|
|
|
// Delete 2 values
|
|
|
|
st.DeleteRange(3, 4);
|
|
|
|
REQUIRE(3 == st.Elements());
|
|
|
|
REQUIRE(5 == st.Length());
|
|
|
|
REQUIRE("--3-9-" == Representation(st));
|
|
|
|
// Deletion at start
|
|
|
|
st.DeleteRange(0, 1);
|
|
|
|
REQUIRE(3 == st.Elements());
|
|
|
|
REQUIRE(4 == st.Length());
|
|
|
|
REQUIRE("-3-9-" == Representation(st));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("DeleteRangeAtEnds") {
|
|
|
|
// There are always elements at start and end although they can be nulled
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 4);
|
|
|
|
REQUIRE(4 == st.Length());
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("3"));
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("9"));
|
|
|
|
REQUIRE("-3--9" == Representation(st));
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
// Empty deletion at end -> no effect
|
|
|
|
st.DeleteRange(4, 0);
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(4 == st.Length());
|
|
|
|
REQUIRE("-3--9" == Representation(st));
|
|
|
|
// Delete value at start
|
|
|
|
st.InsertSpace(0, 1);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("0"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(5 == st.Length());
|
|
|
|
REQUIRE("0-3--9" == Representation(st));
|
|
|
|
st.DeleteRange(0, 1);
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(4 == st.Length());
|
|
|
|
REQUIRE("03--9" == Representation(st));
|
|
|
|
// Empty deletion at start -> no effect
|
|
|
|
st.InsertSpace(0, 1);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("1"));
|
|
|
|
REQUIRE(3 == st.Elements());
|
|
|
|
REQUIRE(5 == st.Length());
|
|
|
|
REQUIRE("103--9" == Representation(st));
|
|
|
|
st.DeleteRange(0, 0);
|
|
|
|
REQUIRE(3 == st.Elements());
|
|
|
|
REQUIRE(5 == st.Length());
|
|
|
|
REQUIRE("103--9" == Representation(st));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("DeleteStartingRange") {
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
st.InsertSpace(0, 2);
|
|
|
|
st.SetValueAt(0, UniqueStringCopy("1"));
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("2"));
|
|
|
|
REQUIRE(2 == st.Length());
|
|
|
|
REQUIRE("12-" == Representation(st));
|
|
|
|
st.DeleteRange(0,1);
|
|
|
|
REQUIRE(1 == st.Length());
|
|
|
|
REQUIRE("2-" == Representation(st));
|
|
|
|
st.DeleteRange(0,1);
|
|
|
|
REQUIRE(0 == st.Length());
|
|
|
|
REQUIRE("-" == Representation(st));
|
|
|
|
st.InsertSpace(0, 2);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("1"));
|
|
|
|
REQUIRE(2 == st.Length());
|
|
|
|
REQUIRE("-1-" == Representation(st));
|
|
|
|
st.DeleteRange(0, 2);
|
|
|
|
REQUIRE("-" == Representation(st));
|
|
|
|
st.InsertSpace(0, 4);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("1"));
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE(4 == st.Length());
|
|
|
|
REQUIRE("-1-3-" == Representation(st));
|
|
|
|
st.DeleteRange(0, 3);
|
|
|
|
REQUIRE("3-" == Representation(st));
|
|
|
|
st.DeleteRange(0, 1);
|
|
|
|
REQUIRE("-" == Representation(st));
|
|
|
|
st.InsertSpace(0, 4);
|
|
|
|
st.SetValueAt(1, UniqueStringCopy("1"));
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("4"));
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE("-1-34" == Representation(st));
|
|
|
|
st.DeleteRange(1, 3);
|
|
|
|
REQUIRE("-4" == Representation(st));
|
|
|
|
st.InsertSpace(1, 3);
|
|
|
|
REQUIRE("----4" == Representation(st));
|
|
|
|
st.SetValueAt(4, UniqueStringCopy("4"));
|
|
|
|
st.SetValueAt(3, UniqueStringCopy("3"));
|
|
|
|
REQUIRE("---34" == Representation(st));
|
|
|
|
st.DeleteRange(1, 3);
|
|
|
|
REQUIRE("-4" == Representation(st));
|
|
|
|
}
|
2019-05-04 20:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("SparseTextInt") {
|
|
|
|
|
|
|
|
SparseVector<int> st;
|
|
|
|
|
|
|
|
SECTION("InsertAndDeleteValue") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
st.SetValueAt(3, 3);
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(0 == st.ValueAt(0));
|
|
|
|
REQUIRE(0 == st.ValueAt(1));
|
|
|
|
REQUIRE(0 == st.ValueAt(2));
|
|
|
|
REQUIRE(3 == st.ValueAt(3));
|
|
|
|
REQUIRE(0 == st.ValueAt(4));
|
|
|
|
st.SetValueAt(3, -3);
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(0 == st.ValueAt(0));
|
|
|
|
REQUIRE(0 == st.ValueAt(1));
|
|
|
|
REQUIRE(0 == st.ValueAt(2));
|
|
|
|
REQUIRE(-3 == st.ValueAt(3));
|
|
|
|
REQUIRE(0 == st.ValueAt(4));
|
|
|
|
st.SetValueAt(3, 0);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(0 == st.ValueAt(0));
|
|
|
|
REQUIRE(0 == st.ValueAt(1));
|
|
|
|
REQUIRE(0 == st.ValueAt(2));
|
|
|
|
REQUIRE(0 == st.ValueAt(3));
|
|
|
|
REQUIRE(0 == st.ValueAt(4));
|
|
|
|
st.Check();
|
|
|
|
}
|
2021-02-21 05:53:09 +01:00
|
|
|
|
|
|
|
SECTION("IndexAfter") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(0 == st.IndexAfter(-1));
|
|
|
|
REQUIRE(0 == st.PositionOfElement(0));
|
|
|
|
REQUIRE(1 == st.IndexAfter(0));
|
|
|
|
REQUIRE(5 == st.PositionOfElement(1));
|
|
|
|
st.SetValueAt(3, 3);
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(0 == st.IndexAfter(-1));
|
|
|
|
REQUIRE(0 == st.PositionOfElement(0));
|
|
|
|
REQUIRE(1 == st.IndexAfter(0));
|
|
|
|
REQUIRE(3 == st.PositionOfElement(1));
|
|
|
|
REQUIRE(2 == st.IndexAfter(3));
|
|
|
|
REQUIRE(5 == st.PositionOfElement(2));
|
2022-08-27 09:35:52 +02:00
|
|
|
REQUIRE(2 == st.IndexAfter(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("PositionNext") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(5 == st.PositionNext(-1));
|
|
|
|
REQUIRE(5 == st.PositionNext(0));
|
|
|
|
REQUIRE(6 == st.PositionNext(5));
|
|
|
|
st.SetValueAt(3, 3);
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE(3 == st.PositionNext(-1));
|
|
|
|
REQUIRE(3 == st.PositionNext(0));
|
|
|
|
REQUIRE(5 == st.PositionNext(3));
|
|
|
|
REQUIRE(6 == st.PositionNext(5));
|
2021-02-21 05:53:09 +01:00
|
|
|
}
|
2019-05-04 20:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("SparseTextString") {
|
|
|
|
|
|
|
|
SparseVector<std::string> st;
|
|
|
|
|
|
|
|
SECTION("InsertAndDeleteValue") {
|
|
|
|
st.InsertSpace(0, 5);
|
|
|
|
REQUIRE(5 == st.Length());
|
|
|
|
st.SetValueAt(3, std::string("3"));
|
|
|
|
REQUIRE(2 == st.Elements());
|
|
|
|
REQUIRE("" == st.ValueAt(0));
|
|
|
|
REQUIRE("" == st.ValueAt(2));
|
|
|
|
REQUIRE("3" == st.ValueAt(3));
|
|
|
|
REQUIRE("" == st.ValueAt(4));
|
|
|
|
st.DeletePosition(0);
|
|
|
|
REQUIRE(4 == st.Length());
|
|
|
|
REQUIRE("3" == st.ValueAt(2));
|
|
|
|
st.DeletePosition(2);
|
|
|
|
REQUIRE(1 == st.Elements());
|
|
|
|
REQUIRE(3 == st.Length());
|
|
|
|
REQUIRE("" == st.ValueAt(0));
|
|
|
|
REQUIRE("" == st.ValueAt(1));
|
|
|
|
REQUIRE("" == st.ValueAt(2));
|
|
|
|
st.Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("SetAndMoveString") {
|
|
|
|
st.InsertSpace(0, 2);
|
|
|
|
REQUIRE(2u == st.Length());
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
const std::string s24("24");
|
2019-05-04 20:14:48 +02:00
|
|
|
st.SetValueAt(0, s24);
|
|
|
|
REQUIRE("24" == s24); // Not moved from
|
|
|
|
REQUIRE("" == st.ValueAt(-1));
|
|
|
|
REQUIRE("24" == st.ValueAt(0));
|
|
|
|
REQUIRE("" == st.ValueAt(1));
|
|
|
|
std::string s25("25");
|
|
|
|
st.SetValueAt(1, std::move(s25));
|
Updated to Scintilla 5.4.2 & Lexilla 5.3.1
https://www.scintilla.org/scintilla542.zip
Release 5.4.2
Released 5 March 2024.
Significantly reduce memory used for undo actions, often to a half or quarter of previous versions. Feature #1458.
Add APIs for saving and restoring undo history.
For GTK, when laying out text, detect runs with both left-to-right and right-to-left ranges and divide into an ASCII prefix and more complex suffix. Lay out the ASCII prefix in the standard manner but, for the suffix, measure the whole width and spread that over the suffix bytes. This produces more usable results where the caret moves over the ASCII prefix correctly and over the suffix reasonably but not accurately.
For ScintillaEdit on Qt, fix reference from ScintillaDocument to Document to match change in 5.4.1 using IDocumentEditable for SCI_GETDOCPOINTER and SCI_SETDOCPOINTER.
For Direct2D on Win32, use the multi-threaded option to avoid crashes when Scintilla instances created on different threads. There may be more problems with this scenario so it should be avoided. Bug #2420.
For Win32, ensure keyboard-initiated context menu appears in multi-screen situations.
https://www.scintilla.org/lexilla531.zip
Release 5.3.1
Released 5 March 2024.
Assembler: After comments, treat \r\n line ends the same as \n. This makes testing easier.
Bash: Fix folding when line changed to/from comment and previous line is comment. Issue #224.
Batch: Fix handling ':' next to keywords. Issue #222.
JavaScript: in cpp lexer, add lexer.cpp.backquoted.strings=2 mode to treat ` back-quoted strings as template literals which allow embedded ${expressions}. Issue #94.
Python: fix lexing of rb'' and rf'' strings. Issue #223, Pull request #227.
Ruby: fix lexing of methods on numeric literals like '3.times' so the '.' and method name do not appear in numeric style. Issue #225.
2024-03-06 22:05:54 +01:00
|
|
|
// Deliberate check of moved from: provokes warning from Visual C++ code analysis
|
|
|
|
REQUIRE("" == s25);
|
2019-05-04 20:14:48 +02:00
|
|
|
REQUIRE("25" == st.ValueAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|