Cleanup branches and add more unit tests

This commit is contained in:
Antonio SJ Musumeci 2026-03-16 20:02:56 -05:00
parent 2cf92c92ad
commit 1cf52cae1f
4 changed files with 970 additions and 15 deletions

View file

@ -17,11 +17,10 @@
*/
#include "branch.hpp"
#include "ef.hpp"
#include "errno.hpp"
#include "num.hpp"
Branch::Branch()
: mode(Branch::Mode::RW)
{
}
@ -37,12 +36,6 @@ Branch::Branch(const u64 &default_minfreespace_)
{
}
int
Branch::from_string(const std::string_view str_)
{
return -EINVAL;
}
std::string
Branch::to_string(void) const
{
@ -64,7 +57,6 @@ Branch::to_string(void) const
break;
}
if(std::holds_alternative<u64>(_minfreespace))
{
rv += ',';

View file

@ -20,7 +20,6 @@
#include "base_types.h"
#include "strvec.hpp"
#include "tofrom_string.hpp"
#include "fs_path.hpp"
#include <cstdint>
@ -31,12 +30,11 @@
#include <variant>
class Branch final : public ToFromString
class Branch final
{
public:
enum class Mode
{
INVALID,
RO,
RW,
NC
@ -61,8 +59,7 @@ public:
bool ro_or_nc(void) const;
public:
int from_string(const std::string_view str) final;
std::string to_string(void) const final;
std::string to_string(void) const;
public:
u64 minfreespace() const;

View file

@ -82,7 +82,10 @@ namespace l
offset = s_.find_first_not_of("+<>-=");
if(offset == std::string::npos)
return;
{
*instr_ = s_.substr(0, std::min(s_.size(), (size_t)2));
return;
}
if(offset > 1)
offset = 2;
@ -293,6 +296,9 @@ namespace l
int
erase_begin(Branches::Impl *branches_)
{
if(branches_->empty())
return -ENOENT;
branches_->erase(branches_->begin());
return 0;
@ -302,6 +308,9 @@ namespace l
int
erase_end(Branches::Impl *branches_)
{
if(branches_->empty())
return -ENOENT;
branches_->pop_back();
return 0;