mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add PluginMetadata::AsYaml()
For use in LOOT's "Copy Metadata" feature.
This commit is contained in:
@@ -184,7 +184,8 @@ public:
|
||||
* @param incompatibilities
|
||||
* The files to set.
|
||||
*/
|
||||
LOOT_API void SetIncompatibilities(const std::vector<File>& incompatibilities);
|
||||
LOOT_API void SetIncompatibilities(
|
||||
const std::vector<File>& incompatibilities);
|
||||
|
||||
/**
|
||||
* Set the plugin's messages.
|
||||
@@ -243,11 +244,17 @@ public:
|
||||
* matched against it, otherwise the strings will be compared
|
||||
* case-insensitively. The given plugin name must be literal, i.e. not a
|
||||
* regular expression.
|
||||
* @returns True if the given plugin name matches this metadata's plugin
|
||||
* @returns True if the given plugin name matches this metadata's plugin
|
||||
* name, false otherwise.
|
||||
*/
|
||||
LOOT_API bool NameMatches(const std::string& pluginName) const;
|
||||
|
||||
/**
|
||||
* @brief Serialises the plugin metadata as YAML.
|
||||
* @returns The serialised plugin metadata.
|
||||
*/
|
||||
LOOT_API std::string AsYaml() const;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::optional<std::string> group_;
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "api/game/game.h"
|
||||
#include "api/helpers/collections.h"
|
||||
#include "api/helpers/logging.h"
|
||||
#include "api/helpers/text.h"
|
||||
#include "api/metadata/yaml/plugin_metadata.h"
|
||||
|
||||
using std::inserter;
|
||||
using std::regex;
|
||||
@@ -59,7 +59,8 @@ void PluginMetadata::MergeMetadata(const PluginMetadata& plugin) {
|
||||
|
||||
loadAfter_ = mergeVectors(loadAfter_, plugin.loadAfter_);
|
||||
requirements_ = mergeVectors(requirements_, plugin.requirements_);
|
||||
incompatibilities_ = mergeVectors(incompatibilities_, plugin.incompatibilities_);
|
||||
incompatibilities_ =
|
||||
mergeVectors(incompatibilities_, plugin.incompatibilities_);
|
||||
|
||||
tags_ = mergeVectors(tags_, plugin.tags_);
|
||||
|
||||
@@ -86,7 +87,8 @@ PluginMetadata PluginMetadata::NewMetadata(const PluginMetadata& plugin) const {
|
||||
// Compare this plugin against the given plugin.
|
||||
p.SetLoadAfterFiles(diffVectors(loadAfter_, plugin.loadAfter_));
|
||||
p.SetRequirements(diffVectors(requirements_, plugin.requirements_));
|
||||
p.SetIncompatibilities(diffVectors(incompatibilities_, plugin.incompatibilities_));
|
||||
p.SetIncompatibilities(
|
||||
diffVectors(incompatibilities_, plugin.incompatibilities_));
|
||||
|
||||
vector<Message> msgs1 = plugin.GetMessages();
|
||||
vector<Message> msgs2 = messages_;
|
||||
@@ -116,7 +118,9 @@ std::vector<File> PluginMetadata::GetLoadAfterFiles() const {
|
||||
return loadAfter_;
|
||||
}
|
||||
|
||||
std::vector<File> PluginMetadata::GetRequirements() const { return requirements_; }
|
||||
std::vector<File> PluginMetadata::GetRequirements() const {
|
||||
return requirements_;
|
||||
}
|
||||
|
||||
std::vector<File> PluginMetadata::GetIncompatibilities() const {
|
||||
return incompatibilities_;
|
||||
@@ -209,4 +213,12 @@ bool PluginMetadata::NameMatches(const std::string& pluginName) const {
|
||||
|
||||
return CompareFilenames(name_, pluginName) == 0;
|
||||
}
|
||||
|
||||
LOOT_API std::string PluginMetadata::AsYaml() const {
|
||||
YAML::Emitter emitter;
|
||||
emitter.SetIndent(2);
|
||||
emitter << *this;
|
||||
|
||||
return std::string(emitter.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,9 @@ along with LOOT. If not, see
|
||||
#ifndef LOOT_TESTS_API_INTERNALS_METADATA_PLUGIN_METADATA_TEST
|
||||
#define LOOT_TESTS_API_INTERNALS_METADATA_PLUGIN_METADATA_TEST
|
||||
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
|
||||
#include "tests/common_game_test_fixture.h"
|
||||
|
||||
#include "api/metadata/yaml/plugin_metadata.h"
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
#include "tests/common_game_test_fixture.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
@@ -46,8 +44,8 @@ protected:
|
||||
// Pass an empty first argument, as it's a prefix for the test instantation,
|
||||
// but we only have the one so no prefix is necessary.
|
||||
INSTANTIATE_TEST_SUITE_P(,
|
||||
PluginMetadataTest,
|
||||
::testing::Values(GameType::tes5));
|
||||
PluginMetadataTest,
|
||||
::testing::Values(GameType::tes5));
|
||||
|
||||
TEST_P(
|
||||
PluginMetadataTest,
|
||||
@@ -83,7 +81,8 @@ TEST_P(PluginMetadataTest,
|
||||
EXPECT_FALSE(plugin.NameMatches(regex));
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest, nameMatchesShouldUseCaseInsensitiveRegexMatchingForARegexName) {
|
||||
TEST_P(PluginMetadataTest,
|
||||
nameMatchesShouldUseCaseInsensitiveRegexMatchingForARegexName) {
|
||||
PluginMetadata plugin("Blan.\\.esm");
|
||||
|
||||
EXPECT_TRUE(plugin.NameMatches(boost::to_lower_copy(blankEsm)));
|
||||
@@ -588,6 +587,18 @@ TEST_P(PluginMetadataTest,
|
||||
EXPECT_TRUE(plugin.IsRegexPlugin());
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest,
|
||||
asYamlShouldReturnAStringContainingTheMetadataEmittedAsYaml) {
|
||||
PluginMetadata plugin(blankEsm);
|
||||
plugin.SetLoadAfterFiles({File(blankEsm)});
|
||||
|
||||
EXPECT_EQ(
|
||||
"name: 'Blank.esm'\n"
|
||||
"after:\n"
|
||||
" - 'Blank.esm'",
|
||||
plugin.AsYaml());
|
||||
}
|
||||
|
||||
TEST_P(PluginMetadataTest,
|
||||
emittingAsYamlShouldOutputAPluginWithNoMetadataAsABlankString) {
|
||||
PluginMetadata plugin(blankEsm);
|
||||
|
||||
Reference in New Issue
Block a user