Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
81 lines
3.8 KiB
C++
81 lines
3.8 KiB
C++
/**************************************************************************/
|
|
/* test_fuzzy_search.h */
|
|
/**************************************************************************/
|
|
/* This file is part of: */
|
|
/* GODOT ENGINE */
|
|
/* https://godotengine.org */
|
|
/**************************************************************************/
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
/* */
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
/* a copy of this software and associated documentation files (the */
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
/* the following conditions: */
|
|
/* */
|
|
/* The above copyright notice and this permission notice shall be */
|
|
/* included in all copies or substantial portions of the Software. */
|
|
/* */
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
/**************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include "core/string/fuzzy_search.h"
|
|
#include "tests/test_macros.h"
|
|
|
|
namespace TestFuzzySearch {
|
|
|
|
struct FuzzySearchTestCase {
|
|
String query;
|
|
String expected;
|
|
};
|
|
|
|
// Ideally each of these test queries should represent a different aspect, and potentially bottleneck, of the search process.
|
|
const FuzzySearchTestCase test_cases[] = {
|
|
// Short query, many matches, few adjacent characters
|
|
{ "///gd", "./menu/hud/hud.gd" },
|
|
// Filename match with typo
|
|
{ "sm.png", "./entity/blood_sword/sam.png" },
|
|
// Multipart filename word matches
|
|
{ "ham ", "./entity/game_trap/ha_missed_me.wav" },
|
|
// Single word token matches
|
|
{ "push background", "./entity/background_zone1/background/push.png" },
|
|
// Long token matches
|
|
{ "background_freighter background png", "./entity/background_freighter/background/background.png" },
|
|
// Many matches, many short tokens
|
|
{ "menu menu characters wav", "./menu/menu/characters/smoker/0.wav" },
|
|
// Maximize total matches
|
|
{ "entity gd", "./entity/entity_man.gd" }
|
|
};
|
|
|
|
Vector<String> load_test_data() {
|
|
Ref<FileAccess> fp = FileAccess::open(TestUtils::get_data_path("fuzzy_search/project_dir_tree.txt"), FileAccess::READ);
|
|
REQUIRE(fp.is_valid());
|
|
return fp->get_as_utf8_string().split("\n");
|
|
}
|
|
|
|
TEST_CASE("[FuzzySearch] Test fuzzy search results") {
|
|
FuzzySearch search;
|
|
Vector<FuzzySearchResult> results;
|
|
Vector<String> targets = load_test_data();
|
|
|
|
for (FuzzySearchTestCase test_case : test_cases) {
|
|
search.set_query(test_case.query);
|
|
search.search_all(targets, results);
|
|
CHECK_GT(results.size(), 0);
|
|
CHECK_EQ(results[0].target, test_case.expected);
|
|
}
|
|
}
|
|
|
|
} //namespace TestFuzzySearch
|