File: testRESearch.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 (97 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download | duplicates (2)
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
/** @file testRESearch.cxx
 ** Unit Tests for Scintilla internal data structures
 **/

#include <cstddef>
#include <cstring>
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>
#include <array>
#include <optional>
#include <algorithm>
#include <memory>

#include "ScintillaTypes.h"

#include "Debugging.h"

#include "Position.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "CellBuffer.h"
#include "CharClassify.h"
#include "RESearch.h"

#include "catch.hpp"

using namespace Scintilla;
using namespace Scintilla::Internal;

class StringCI : public CharacterIndexer {
	std::string s;
public:
	explicit StringCI(std::string_view sv_) : s(sv_) {
	}
	virtual ~StringCI() = default;
	[[nodiscard]] Sci::Position Length() const noexcept {
		return s.length();
	}
	char CharAt(Sci::Position index) const override {
		return s.at(index);
	}
	Sci::Position MovePositionOutsideChar(Sci::Position pos, [[maybe_unused]] Sci::Position moveDir) const noexcept override {
		return pos;
	}
	[[nodiscard]] std::string GetCharRange(Sci::Position position, Sci::Position lengthRetrieve) const {
		return s.substr(position, lengthRetrieve);
	}
};

// Test RESearch.

TEST_CASE("RESearch") {

	CharClassify cc;
	constexpr std::string_view sTextSpace = "Scintilla ";
	constexpr std::string_view pattern = "[a-z]+";

	SECTION("Compile") {
		RESearch re(&cc);
		const char *msg = re.Compile(pattern.data(), pattern.length(), true, false);
		REQUIRE(nullptr == msg);
	}

	SECTION("Bug2413") {
		// Check for https://sourceforge.net/p/scintilla/bugs/2413/
		RESearch re(&cc);
		constexpr std::string_view BOW = "\\<";
		constexpr std::string_view EOW = "\\>";
		const char *msg = re.Compile(BOW.data(), BOW.length(), true, false);
		REQUIRE(nullptr == msg);
		msg = re.Compile(EOW.data(), EOW.length(), true, false);
		REQUIRE(nullptr == msg);
	}

	SECTION("Execute") {
		RESearch re(&cc);
		re.Compile(pattern.data(), pattern.length(), true, false);
		const StringCI sci(sTextSpace);
		const int x = re.Execute(sci, 0, sci.Length());
		REQUIRE(x == 1);
		REQUIRE(re.bopat[0] == 1);
		REQUIRE(re.eopat[0] == sci.Length() - 1);
	}

	SECTION("Grab") {
		RESearch re(&cc);
		re.Compile(pattern.data(), pattern.length(), true, false);
		const StringCI sci(sTextSpace);
		re.Execute(sci, 0, sci.Length());
		const std::string pat = sci.GetCharRange(re.bopat[0], re.eopat[0] - re.bopat[0]);
		REQUIRE(pat == "cintilla");
	}

}