commit ce1a4b4936abc3ffd5844eefe2f2332e6fe06c89
parent fa57e4cf753acd71b484961af0000136e9b63b0e
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 6 Oct 2016 21:52:59 -0400
source: ignore AL section information of non-script files
Diffstat:
3 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -499,7 +499,7 @@ void AboutPackageDelegate::updateList(const int index)
int sections = src->sections();
string actionList;
- if(sections && src->type() == Package::ScriptType) {
+ if(sections) {
vector<string> sectionNames;
for(const auto &pair : sectionMap) {
diff --git a/src/source.cpp b/src/source.cpp
@@ -38,7 +38,7 @@ auto Source::getSection(const char *name) -> Section
auto Source::detectSection(const string &category) -> Section
{
- // this is for compatibility with v1.0
+ // this is for compatibility with indexes made for v1.0
string topcategory = Path(category).first();
boost::algorithm::to_lower(topcategory);
@@ -85,9 +85,12 @@ const string &Source::file() const
void Source::setSections(int sections)
{
- if(sections == ImplicitSection) {
+ if(type() != Package::ScriptType)
+ return;
+ else if(sections == ImplicitSection) {
const Package *pkg = package();
const Category *cat = pkg ? pkg->category() : nullptr;
+
if(!cat)
throw reapack_error("cannot resolve implicit section: category is unset");
diff --git a/test/source.cpp b/test/source.cpp
@@ -62,18 +62,42 @@ TEST_CASE("parse file section", M) {
REQUIRE(Source::MIDIEditorSection == Source::getSection("midi_editor"));
}
-TEST_CASE("main source", M) {
- Source source("filename", "url");
- REQUIRE(source.sections() == 0);
+TEST_CASE("explicit source section", M) {
+ SECTION("script type override") {
+ Source source("filename", "url");
+ REQUIRE(source.sections() == 0);
- source.setSections(Source::MainSection | Source::MIDIEditorSection);
- REQUIRE(source.sections() == (Source::MainSection | Source::MIDIEditorSection));
+ source.setTypeOverride(Package::ScriptType);
+ source.setSections(Source::MainSection | Source::MIDIEditorSection);
+ REQUIRE(source.sections() == (Source::MainSection | Source::MIDIEditorSection));
+ }
+
+ SECTION("other type override") {
+ Source source("filename", "url");
+ source.setTypeOverride(Package::EffectType);
+ source.setSections(Source::MainSection);
+ REQUIRE(source.sections() == 0);
+ }
+
+ SECTION("package type") {
+ Package pack(Package::ScriptType, "package name");
+ Version ver("1.0", &pack);
+ Source source("filename", "url", &ver);
+ source.setSections(Source::MainSection);
+ REQUIRE(source.sections() == Source::MainSection);
+ }
+
+ SECTION("no package, no type override") {
+ Source source("filename", "url");
+ source.setSections(Source::MainSection);
+ // should not crash!
+ }
}
TEST_CASE("implicit source section") {
SECTION("main") {
Category cat("Category Name");
- Package pack(Package::UnknownType, "package name", &cat);
+ Package pack(Package::ScriptType, "package name", &cat);
Version ver("1.0", &pack);
Source source("filename", "url", &ver);
@@ -83,7 +107,7 @@ TEST_CASE("implicit source section") {
SECTION("midi editor") {
Category cat("MIDI Editor");
- Package pack(Package::UnknownType, "package name", &cat);
+ Package pack(Package::ScriptType, "package name", &cat);
Version ver("1.0", &pack);
Source source("filename", "url", &ver);
@@ -93,6 +117,8 @@ TEST_CASE("implicit source section") {
SECTION("no category") {
Source source("filename", "url");
+ source.setTypeOverride(Package::ScriptType);
+
try {
source.setSections(Source::ImplicitSection);
FAIL(); // should throw (or crash if buggy, but not do nothing)