Skip to content

Commit

Permalink
AssetPath - initialization order fiasco fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Oct 11, 2019
1 parent ccff075 commit 9f1da40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 3 additions & 8 deletions ResourceManager/PathTranslators/AssetPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
namespace sw
{


namespace impl
{
std::regex sAssetPathRegex( "^(.*?)(?:::(.*))?$" );
}


// ================================ //
//
Nullable< AssetPath > AssetPath::FromString ( const std::string& assetPath )
{
static std::regex sAssetPathRegex( "^(.*?)(?:::(.*))?$" );

std::smatch match;

if( std::regex_match( assetPath, match, impl::sAssetPathRegex ) )
if( std::regex_match( assetPath, match, sAssetPathRegex ) )
{
// Ignore first match, it represents full match, that is full string.
return AssetPath( match[ 1 ], match[ 2 ] );
Expand Down
25 changes: 25 additions & 0 deletions Tests/TestResourceManager/TestAssetPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@ TEST_CASE( "GraphicAPI.AssetPath.FromString.TwoSeparators", "[GraphicAPI]" )
CHECK( path.GetInternalPath() == "materials::checker" );
}

// ================================ //
///
TEST_CASE( "GraphicAPI.AssetPath.FromString.3Separators", "[GraphicAPI]" )
{
auto nullablePath = AssetPath::FromString( "C://temp/newfolder/file.mesh::gui::materials::checker" );

REQUIRE( nullablePath.IsValid() == true );
auto path = nullablePath.Get();

CHECK( path.GetFile() == "C://temp/newfolder/file.mesh" );
CHECK( path.GetInternalPath() == "gui::materials::checker" );
}

// ================================ //
//
TEST_CASE( "GraphicAPI.AssetPath.FromString.OnlyInternalPath.3Separators", "[GraphicAPI]" )
{
auto nullablePath = AssetPath::FromString( "::gui::materials::checker" );

REQUIRE( nullablePath.IsValid() == true );
auto path = nullablePath.Get();

CHECK( path.GetFile() == "" );
CHECK( path.GetInternalPath() == "gui::materials::checker" );
}

//====================================================================================//
// Operators
Expand Down

0 comments on commit 9f1da40

Please sign in to comment.