1 // Unit Tests for Scintilla internal data structures
2 
3 #include <string.h>
4 
5 #include "WordList.h"
6 
7 #include "catch.hpp"
8 
9 using namespace Scintilla;
10 
11 // Test WordList.
12 
13 TEST_CASE("WordList") {
14 
15 	WordList wl;
16 
17 	SECTION("IsEmptyInitially") {
18 		REQUIRE(0 == wl.Length());
19 		REQUIRE(!wl.InList("struct"));
20 	}
21 
22 	SECTION("InList") {
23 		wl.Set("else struct");
24 		REQUIRE(2 == wl.Length());
25 		REQUIRE(wl.InList("struct"));
26 		REQUIRE(!wl.InList("class"));
27 	}
28 
29 	SECTION("Set") {
30 		// Check whether Set returns whether it has changed correctly
31 		const bool changed = wl.Set("else struct");
32 		REQUIRE(changed);
33 		// Changing to same thing
34 		const bool changed2 = wl.Set("else struct");
35 		REQUIRE(!changed2);
36 		// Changed order shouldn't be seen as a change
37 		const bool changed3 = wl.Set("struct else");
38 		REQUIRE(!changed3);
39 		// Removing word is a change
40 		const bool changed4 = wl.Set("struct");
41 		REQUIRE(changed4);
42 	}
43 
44 	SECTION("WordAt") {
45 		wl.Set("else struct");
46 		REQUIRE(0 == strcmp(wl.WordAt(0), "else"));
47 	}
48 
49 	SECTION("InListAbbreviated") {
50 		wl.Set("else stru~ct w~hile");
51 		REQUIRE(wl.InListAbbreviated("else", '~'));
52 
53 		REQUIRE(wl.InListAbbreviated("struct", '~'));
54 		REQUIRE(wl.InListAbbreviated("stru", '~'));
55 		REQUIRE(wl.InListAbbreviated("struc", '~'));
56 		REQUIRE(!wl.InListAbbreviated("str", '~'));
57 
58 		REQUIRE(wl.InListAbbreviated("while", '~'));
59 		REQUIRE(wl.InListAbbreviated("wh", '~'));
60 		// TODO: Next line fails but should allow single character prefixes
61 		//REQUIRE(wl.InListAbbreviated("w", '~'));
62 		REQUIRE(!wl.InListAbbreviated("", '~'));
63 	}
64 
65 	SECTION("InListAbridged") {
66 		wl.Set("list w.~.active bo~k a~z ~_frozen");
67 		REQUIRE(wl.InListAbridged("list", '~'));
68 
69 		REQUIRE(wl.InListAbridged("w.front.active", '~'));
70 		REQUIRE(wl.InListAbridged("w.x.active", '~'));
71 		REQUIRE(wl.InListAbridged("w..active", '~'));
72 		REQUIRE(!wl.InListAbridged("w.active", '~'));
73 		REQUIRE(!wl.InListAbridged("w.x.closed", '~'));
74 
75 		REQUIRE(wl.InListAbridged("book", '~'));
76 		REQUIRE(wl.InListAbridged("bok", '~'));
77 		REQUIRE(!wl.InListAbridged("bk", '~'));
78 
79 		REQUIRE(wl.InListAbridged("a_frozen", '~'));
80 		REQUIRE(wl.InListAbridged("_frozen", '~'));
81 		REQUIRE(!wl.InListAbridged("frozen", '~'));
82 
83 		REQUIRE(wl.InListAbridged("abcz", '~'));
84 		REQUIRE(wl.InListAbridged("abz", '~'));
85 		REQUIRE(wl.InListAbridged("az", '~'));
86 	}
87 }
88