Blender
V4.3
source
blender
blenlib
tests
BLI_string_search_test.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include "testing/testing.h"
6
7
#include "
BLI_array.hh
"
8
#include "
BLI_string_search.hh
"
9
#include "
BLI_vector.hh
"
10
11
namespace
blender::string_search::tests
{
12
13
/* Right arrow, keep in sync with #UI_MENU_ARROW_SEP in `UI_interface.hh`. */
14
#define UI_MENU_ARROW_SEP "\xe2\x96\xb8"
15
16
TEST
(string_search,
damerau_levenshtein_distance
)
17
{
18
EXPECT_EQ
(
damerau_levenshtein_distance
(
"test"
,
"test"
), 0);
19
EXPECT_EQ
(
damerau_levenshtein_distance
(
"hello"
,
"ell"
), 2);
20
EXPECT_EQ
(
damerau_levenshtein_distance
(
"hello"
,
"hel"
), 2);
21
EXPECT_EQ
(
damerau_levenshtein_distance
(
"ell"
,
"hello"
), 2);
22
EXPECT_EQ
(
damerau_levenshtein_distance
(
"hell"
,
"hello"
), 1);
23
EXPECT_EQ
(
damerau_levenshtein_distance
(
"hello"
,
"hallo"
), 1);
24
EXPECT_EQ
(
damerau_levenshtein_distance
(
"test"
,
""
), 4);
25
EXPECT_EQ
(
damerau_levenshtein_distance
(
""
,
"hello"
), 5);
26
EXPECT_EQ
(
damerau_levenshtein_distance
(
"Test"
,
"test"
), 1);
27
EXPECT_EQ
(
damerau_levenshtein_distance
(
"ab"
,
"ba"
), 1);
28
EXPECT_EQ
(
damerau_levenshtein_distance
(
"what"
,
"waht"
), 1);
29
EXPECT_EQ
(
damerau_levenshtein_distance
(
"what"
,
"ahwt"
), 2);
30
}
31
32
TEST
(string_search,
get_fuzzy_match_errors
)
33
{
34
EXPECT_EQ
(
get_fuzzy_match_errors
(
"a"
,
"b"
), -1);
35
EXPECT_EQ
(
get_fuzzy_match_errors
(
""
,
"abc"
), 0);
36
EXPECT_EQ
(
get_fuzzy_match_errors
(
"hello"
,
"hallo"
), 1);
37
EXPECT_EQ
(
get_fuzzy_match_errors
(
"hap"
,
"hello"
), -1);
38
EXPECT_EQ
(
get_fuzzy_match_errors
(
"armature"
,
UI_MENU_ARROW_SEP
"restore"
), -1);
39
}
40
41
TEST
(string_search,
extract_normalized_words
)
42
{
43
LinearAllocator<>
allocator;
44
Vector<StringRef, 64>
words;
45
Vector<int, 64>
word_group_ids;
46
extract_normalized_words
(
"hello world"
UI_MENU_ARROW_SEP
"test another test"
UI_MENU_ARROW_SEP
47
" 3"
,
48
allocator,
49
words,
50
word_group_ids);
51
EXPECT_EQ
(words.
size
(), 6);
52
EXPECT_EQ
(words[0],
"hello"
);
53
EXPECT_EQ
(word_group_ids[0], 0);
54
EXPECT_EQ
(words[1],
"world"
);
55
EXPECT_EQ
(word_group_ids[1], 0);
56
EXPECT_EQ
(words[2],
"test"
);
57
EXPECT_EQ
(word_group_ids[2], 1);
58
EXPECT_EQ
(words[3],
"another"
);
59
EXPECT_EQ
(word_group_ids[3], 1);
60
EXPECT_EQ
(words[4],
"test"
);
61
EXPECT_EQ
(word_group_ids[4], 1);
62
EXPECT_EQ
(words[5],
"3"
);
63
EXPECT_EQ
(word_group_ids[5], 2);
64
}
65
66
}
// namespace blender::string_search::tests
BLI_array.hh
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
BLI_string_search.hh
BLI_vector.hh
blender::LinearAllocator
Definition
BLI_linear_allocator.hh:27
blender::Vector
Definition
BLI_vector.hh:65
blender::Vector::size
int64_t size() const
Definition
BLI_vector.hh:691
blender::string_search::tests
Definition
BLI_string_search_test.cc:11
blender::string_search::tests::TEST
TEST(string_search, damerau_levenshtein_distance)
Definition
BLI_string_search_test.cc:16
blender::string_search::get_fuzzy_match_errors
int get_fuzzy_match_errors(StringRef query, StringRef full)
Definition
string_search.cc:90
blender::string_search::damerau_levenshtein_distance
int damerau_levenshtein_distance(StringRef a, StringRef b)
Definition
string_search.cc:27
blender::string_search::extract_normalized_words
void extract_normalized_words(StringRef str, LinearAllocator<> &allocator, Vector< StringRef, 64 > &r_words, Vector< int, 64 > &r_word_group_ids)
Definition
string_search.cc:412
UI_MENU_ARROW_SEP
#define UI_MENU_ARROW_SEP
Definition
string_search.cc:17
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0