File: testOptionSet.cxx

package info (click to toggle)
codequery 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,860 kB
  • sloc: cpp: 151,420; xml: 16,576; python: 5,602; ansic: 5,487; makefile: 559; perl: 496; ruby: 209; sql: 194; sh: 106; php: 53; vhdl: 51; erlang: 47; objc: 22; lisp: 18; cobol: 18; modula3: 17; asm: 14; fortran: 12; ml: 11; tcl: 6
file content (126 lines) | stat: -rw-r--r-- 3,802 bytes parent folder | download | duplicates (3)
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
/** @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"));
	}
}