mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 23:46:00 -06:00
#4589 Recursive Import Dialog: Add a method to extract the root path from a search path string. Also added unit test for this
This commit is contained in:
parent
9a21ceb74f
commit
19126d96ec
@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include <QDir>
|
||||
#include <set>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -128,3 +129,36 @@ QString RiaFilePathTools::removeDuplicatePathSeparators(const QString& path)
|
||||
|
||||
return correctedPath;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::rootSearchPathFromSearchFilter(const QString& searchFilter)
|
||||
{
|
||||
std::set<QChar> globStartCharacters = {'*', '?', '['}; // ']' not needed
|
||||
|
||||
QStringList pathPartList = searchFilter.split(SEPARATOR);
|
||||
|
||||
QStringList::iterator pathPartIt= pathPartList.begin();
|
||||
|
||||
for ( ; pathPartIt != pathPartList.end(); ++pathPartIt)
|
||||
{
|
||||
QString pathPart = *pathPartIt;
|
||||
|
||||
// Remove allowed escaping of wildcards
|
||||
|
||||
pathPart.replace("[[]", "");
|
||||
pathPart.replace("[]]", "");
|
||||
pathPart.replace("[?]", "");
|
||||
pathPart.replace("[*]", "");
|
||||
|
||||
if (pathPart.contains("*")) break;
|
||||
if (pathPart.contains("?")) break;
|
||||
if (pathPart.contains("[")) break;
|
||||
|
||||
}
|
||||
|
||||
pathPartList.erase(pathPartIt, pathPartList.end());
|
||||
|
||||
return pathPartList.join(SEPARATOR);
|
||||
}
|
||||
|
@ -41,4 +41,5 @@ public:
|
||||
static QString canonicalPath(const QString& path);
|
||||
static std::pair<QString, QString> toFolderAndFileName(const QString& absFileName);
|
||||
static QString removeDuplicatePathSeparators(const QString& path);
|
||||
static QString rootSearchPathFromSearchFilter(const QString& searchFilter);
|
||||
};
|
||||
|
@ -51,6 +51,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMean-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCellDividingTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFilePathTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/Intersect-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifPerforationIntervalReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathCompletions-Test.cpp
|
||||
|
85
ApplicationCode/UnitTests/RiaFilePathTools-Test.cpp
Normal file
85
ApplicationCode/UnitTests/RiaFilePathTools-Test.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::ostream& operator<< (std::ostream& out, const QString & text)
|
||||
{
|
||||
out << text.toStdString();
|
||||
return out;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RiaFilePathTools, rootSearchPathFromSearchFilter)
|
||||
{
|
||||
{
|
||||
QString testPath("");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString(""), resultRootPath);
|
||||
}
|
||||
|
||||
{
|
||||
QString testPath("D:/");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("D:/"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("D:/A");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("D:/A"), resultRootPath);
|
||||
}
|
||||
|
||||
{
|
||||
QString testPath("D:/A/B[cd]/E");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("D:/A"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("/A/B[cd]/E");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("/A"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("/A/B?/E");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("/A"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("//A/B/E*");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("//A/B/E");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B/E"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("//A/B/E/");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B/E/"), resultRootPath);
|
||||
}
|
||||
|
||||
{
|
||||
QString testPath("//A/B[[]/E/");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B[[]/E/"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("//A/B[]]/E/");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B[]]/E/"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("//A/B[*]/E/");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B[*]/E/"), resultRootPath);
|
||||
}
|
||||
{
|
||||
QString testPath("//A/B[?]/E/");
|
||||
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter(testPath);
|
||||
EXPECT_EQ(QString("//A/B[?]/E/"), resultRootPath);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user