Blender V5.0
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"
9#include "BLI_vector.hh"
10
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
31
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 EXPECT_EQ(get_fuzzy_match_errors("bluir", "blur"), get_fuzzy_match_errors("blur", "bluir"));
40}
41
43{
44 LinearAllocator<> allocator;
46 Vector<int, 64> word_group_ids;
47 extract_normalized_words("hello world" UI_MENU_ARROW_SEP "test another test" UI_MENU_ARROW_SEP
48 " 3",
49 allocator,
50 words,
51 word_group_ids);
52 EXPECT_EQ(words.size(), 6);
53 EXPECT_EQ(words[0], "hello");
54 EXPECT_EQ(word_group_ids[0], 0);
55 EXPECT_EQ(words[1], "world");
56 EXPECT_EQ(word_group_ids[1], 0);
57 EXPECT_EQ(words[2], "test");
58 EXPECT_EQ(word_group_ids[2], 1);
59 EXPECT_EQ(words[3], "another");
60 EXPECT_EQ(word_group_ids[3], 1);
61 EXPECT_EQ(words[4], "test");
62 EXPECT_EQ(word_group_ids[4], 1);
63 EXPECT_EQ(words[5], "3");
64 EXPECT_EQ(word_group_ids[5], 2);
65}
66
67} // namespace blender::string_search::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int64_t size() const
TEST(string_search, damerau_levenshtein_distance)
int get_fuzzy_match_errors(StringRef query, StringRef full)
int damerau_levenshtein_distance(StringRef a, StringRef b)
void extract_normalized_words(StringRef str, LinearAllocator<> &allocator, Vector< StringRef, 64 > &r_words, Vector< int, 64 > &r_word_group_ids)
#define UI_MENU_ARROW_SEP