Skip to content

Commit

Permalink
#175 #176 Include empty entries for SCI_DESCRIBEKEYWORDSETS
Browse files Browse the repository at this point in the history
Add tests for implementation of OptionSet.

Closes #175
  • Loading branch information
dail8859 authored and nyamatongwe committed Jun 10, 2023
1 parent a6b8fca commit a9487e0
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
13 changes: 13 additions & 0 deletions doc/LexillaHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,19 @@ <h2>Contributors</h2>
</tr>
</table>
<h2>Releases</h2>
<h3>
<a href="https://www.scintilla.org/lexilla526.zip">Release 5.2.6</a>
</h3>
<ul>
<li>
Released 31 May 2023.
</li>
<li>
Include empty word list names in value returned by DescribeWordListSets and SCI_DESCRIBEKEYWORDSETS.
<a href="https://github.com/ScintillaOrg/lexilla/issues/175">Issue #175</a>,
<a href="https://github.com/ScintillaOrg/lexilla/pull/176">Pull request #176</a>.
</li>
</ul>
<h3>
<a href="https://www.scintilla.org/lexilla525.zip">Release 5.2.5</a>
</h3>
Expand Down
2 changes: 1 addition & 1 deletion lexlib/OptionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class OptionSet {
void DefineWordListSets(const char * const wordListDescriptions[]) {
if (wordListDescriptions) {
for (size_t wl = 0; wordListDescriptions[wl]; wl++) {
if (!wordLists.empty())
if (wl > 0)
wordLists += "\n";
wordLists += wordListDescriptions[wl];
}
Expand Down
126 changes: 126 additions & 0 deletions test/unit/testOptionSet.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/** @file testOptionSet.cxx
** Unit Tests for Lexilla internal data structures
** Tests OptionSet.
**/

#include <string>
#include <string_view>
#include <vector>
#include <map>

#include "Scintilla.h"

#include "OptionSet.h"

#include "catch.hpp"

using namespace Lexilla;

// Test OptionSet.

namespace {

// Simple example options structure with each type: string, bool, int
struct Options {
std::string so;
bool bo = false;
int io = 0;
};

const char *const denseWordLists[] = {
"Keywords 1",
"Keywords 2",
"Keywords 3",
"Keywords 4",
nullptr,
};

const char *const sparseWordLists[] = {
"",
"",
"Keywords 1",
"",
"Keywords 2",
nullptr,
};

}

using Catch::Matchers::Equals;

TEST_CASE("OptionSet") {

OptionSet<Options> os;
Options options;

SECTION("IsEmptyInitially") {
REQUIRE_THAT(os.PropertyNames(), Equals(""));
}

SECTION("MissingOption") {
// Check for not present option
REQUIRE_FALSE(os.PropertyGet("missing"));
REQUIRE(SC_TYPE_BOOLEAN == os.PropertyType("missing"));
REQUIRE_FALSE(os.PropertySet(&options, "missing", "1"));
}

SECTION("Define") {
os.DefineProperty("string.option", &Options::so, "StringOption");
REQUIRE_THAT(os.PropertyGet("string.option"), Equals(""));
REQUIRE(SC_TYPE_STRING == os.PropertyType("string.option"));
REQUIRE_THAT(os.DescribeProperty("string.option"), Equals("StringOption"));

os.DefineProperty("bool.option", &Options::bo, "BoolOption");
REQUIRE_THAT(os.PropertyGet("bool.option"), Equals(""));
REQUIRE(SC_TYPE_BOOLEAN == os.PropertyType("bool.option"));
REQUIRE_THAT(os.DescribeProperty("bool.option"), Equals("BoolOption"));

os.DefineProperty("int.option", &Options::io, "IntOption");
REQUIRE_THAT(os.PropertyGet("int.option"), Equals(""));
REQUIRE(SC_TYPE_INTEGER == os.PropertyType("int.option"));
REQUIRE_THAT(os.DescribeProperty("int.option"), Equals("IntOption"));

// This is really a set and could be reordered but is currently in definition order
REQUIRE_THAT(os.PropertyNames(), Equals("string.option\nbool.option\nint.option"));
}

SECTION("Set") {
os.DefineProperty("string.option", &Options::so, "StringOption");
REQUIRE_THAT(os.PropertyGet("string.option"), Equals(""));
REQUIRE(os.PropertySet(&options, "string.option", "string"));
REQUIRE_THAT(os.PropertyGet("string.option"), Equals("string"));
// Setting to same as before returns false
REQUIRE_FALSE(os.PropertySet(&options, "string.option", "string"));
REQUIRE(os.PropertySet(&options, "string.option", "anotherString"));
REQUIRE_THAT(os.PropertyGet("string.option"), Equals("anotherString"));

os.DefineProperty("bool.option", &Options::so, "BoolOption");
REQUIRE(os.PropertySet(&options, "bool.option", "1"));
REQUIRE_THAT(os.PropertyGet("bool.option"), Equals("1"));
// Setting to same as before returns false
REQUIRE_FALSE(os.PropertySet(&options, "bool.option", "1"));
REQUIRE(os.PropertySet(&options, "bool.option", "0"));

os.DefineProperty("int.option", &Options::so, "IntOption");
REQUIRE(os.PropertySet(&options, "int.option", "2"));
REQUIRE_THAT(os.PropertyGet("int.option"), Equals("2"));
// Setting to same as before returns false
REQUIRE_FALSE(os.PropertySet(&options, "int.option", "2"));
REQUIRE(os.PropertySet(&options, "int.option", "3"));
}

// WordListSets feature is really completely separate from options

SECTION("WordListSets") {
REQUIRE_THAT(os.DescribeWordListSets(), Equals(""));
os.DefineWordListSets(denseWordLists);
REQUIRE_THAT(os.DescribeWordListSets(),
Equals("Keywords 1\nKeywords 2\nKeywords 3\nKeywords 4"));

OptionSet<Options> os2;
REQUIRE_THAT(os2.DescribeWordListSets(), Equals(""));
os2.DefineWordListSets(sparseWordLists);
REQUIRE_THAT(os2.DescribeWordListSets(),
Equals("\n\nKeywords 1\n\nKeywords 2"));
}
}

0 comments on commit a9487e0

Please sign in to comment.