Increase test coverage (#1661)

This commit is contained in:
Rangi
2025-02-16 15:29:16 +01:00
committed by GitHub
parent 993879a2ed
commit c9060c7f2d
5 changed files with 12 additions and 20 deletions

View File

@@ -18,12 +18,10 @@
#include "gfx/main.hpp"
class File {
// Construct a `std::streambuf *` by default, since it's probably lighter than a `filebuf`.
Either<std::streambuf *, std::filebuf> _file;
public:
File() {}
~File() { close(); }
File() : _file(nullptr) {}
// This should only be called once, and before doing any `->` operations.
// Returns `nullptr` on error, and a non-null pointer otherwise.
@@ -61,20 +59,6 @@ public:
return const_cast<File *>(this)->operator->();
}
File *close() {
if (_file.holds<std::filebuf>()) {
// This is called by the destructor, and an explicit `close` shouldn't close twice.
std::filebuf fileBuf = std::move(_file.get<std::filebuf>());
_file.emplace<std::streambuf *>(nullptr);
if (fileBuf.close() != nullptr) {
return this;
}
} else if (_file.get<std::streambuf *>() != nullptr) {
return this;
}
return nullptr;
}
char const *c_str(std::string const &path) const {
return _file.holds<std::filebuf>() ? path.c_str()
: _file.get<std::streambuf *>() == std::cin.rdbuf() ? "<stdin>"