From e4c33e539eabd2126d88e148d891fd9d5a6c288b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 4 Feb 2025 12:53:05 +0300 Subject: [PATCH] fix io::path.parent() & update tests --- src/io/path.hpp | 8 ++------ test/coders/lua_parsing.cpp | 6 +++++- test/coders/vec3.cpp | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/io/path.hpp b/src/io/path.hpp index f106b226..6c6dea14 100644 --- a/src/io/path.hpp +++ b/src/io/path.hpp @@ -110,13 +110,9 @@ namespace io { path parent() const { size_t slashpos = str.rfind('/'); if (slashpos == std::string::npos) { - return colonPos == std::string::npos - ? path() - : path(str.substr(0, colonPos)); + return colonPos == std::string::npos ? "" : str; } - return colonPos == std::string::npos - ? path(str.substr(0, slashpos)) - : path(str.substr(0, colonPos) + str.substr(slashpos)); + return str.substr(0, slashpos); } std::string string() const { diff --git a/test/coders/lua_parsing.cpp b/test/coders/lua_parsing.cpp index 64b15d44..17492d7a 100644 --- a/test/coders/lua_parsing.cpp +++ b/test/coders/lua_parsing.cpp @@ -3,10 +3,14 @@ #include "coders/commons.hpp" #include "coders/lua_parsing.hpp" #include "io/io.hpp" +#include "io/devices/StdfsDevice.hpp" #include "util/stringutil.hpp" +namespace fs = std::filesystem; + TEST(lua_parsing, Tokenizer) { - auto filename = "../../res/scripts/stdlib.lua"; + io::set_device("res", std::make_shared(fs::u8path("../../res"))); + auto filename = "res:scripts/stdlib.lua"; auto source = io::read_string(filename); try { auto tokens = lua::tokenize(filename, source); diff --git a/test/coders/vec3.cpp b/test/coders/vec3.cpp index b7c8e37e..a1dd330b 100644 --- a/test/coders/vec3.cpp +++ b/test/coders/vec3.cpp @@ -2,9 +2,13 @@ #include "coders/vec3.hpp" #include "io/io.hpp" +#include "io/devices/StdfsDevice.hpp" + +namespace fs = std::filesystem; TEST(VEC3, Decode) { - io::path file = "res/models/block.vec3"; + io::set_device("res", std::make_shared(fs::u8path("../../res"))); + io::path file = "res:models/block.vec3"; auto bytes = io::read_bytes_buffer(file); auto model = vec3::load(file.string(), bytes); }