124 lines
2.7 KiB
C++
124 lines
2.7 KiB
C++
#include "test.h"
|
|
#include "files.h"
|
|
#include "util.h"
|
|
|
|
#include <list>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
using namespace mrbesen;
|
|
|
|
int testFiles_parent() {
|
|
std::string out, out2;
|
|
std::string testpath1 = "/asdf1/asdf2/test.png";
|
|
|
|
files::parent(testpath1, out);
|
|
ASSERT(out == "/asdf1/asdf2/", out);
|
|
|
|
files::parent(out, out2);
|
|
ASSERT(out2 == "/asdf1/", out2);
|
|
|
|
files::parent(out2, out);
|
|
ASSERT(out == "/", out);
|
|
|
|
testpath1 = "assets/tex/img1.png";
|
|
files::parent(testpath1, out);
|
|
ASSERT(out == "assets/tex/", out);
|
|
|
|
files::parent("asd", out);
|
|
ASSERT(out == "", out);
|
|
|
|
return TESTGOOD;
|
|
}
|
|
|
|
int testFiles_file() {
|
|
std::string a;
|
|
|
|
files::file("/abc/def/123.txt", a);
|
|
ASSERT(a == "123.txt", "normalfile" << a);
|
|
|
|
files::file("/abc/def/.gitignore", a);
|
|
ASSERT(a == ".gitignore", "dotfiles" << a);
|
|
|
|
files::file("/abc/def/executeable", a);
|
|
ASSERT(a == "executeable", "no extention" << a);
|
|
|
|
files::file("123.txt", a);
|
|
ASSERT(a == "123.txt", "normalfile - nopath" << a);
|
|
|
|
files::file(".gitignore", a);
|
|
ASSERT(a == ".gitignore", "dotfiles - nopath " << a);
|
|
|
|
files::file("executeable", a);
|
|
ASSERT(a == "executeable", "no extention - nopath " << a);
|
|
|
|
return TESTGOOD;
|
|
}
|
|
|
|
int testFiles_extention() {
|
|
std::string a;
|
|
|
|
files::extention("abc/asd/1.txt", a);
|
|
ASSERT(a == "txt", a);
|
|
|
|
files::extention("1.txt", a);
|
|
ASSERT(a == "txt", a);
|
|
|
|
files::extention("/1.txt", a);
|
|
ASSERT(a == "txt", "");
|
|
|
|
files::extention("/a.b.c/ad./1.txt", a);
|
|
ASSERT(a == "txt", "");
|
|
|
|
files::extention("a.b.c/ad./1.txt", a);
|
|
ASSERT(a == "txt", "");
|
|
|
|
files::extention("./1.txt", a);
|
|
ASSERT(a == "txt", "");
|
|
|
|
files::extention("/a/ad/1", a);
|
|
ASSERT(a == "", "");
|
|
|
|
files::extention("/a/ad/", a);
|
|
ASSERT(a == "", "");
|
|
|
|
files::extention("/", a);
|
|
ASSERT(a == "", "");
|
|
|
|
files::extention("/a", a);
|
|
ASSERT(a == "", "");
|
|
|
|
files::extention("/a.", a);
|
|
ASSERT(a == "", "");
|
|
|
|
files::extention("/a.b", a);
|
|
ASSERT(a == "b", "");
|
|
|
|
files::extention("/sad.asd/ab", a);
|
|
ASSERT(a == "", "");
|
|
|
|
files::extention("sad.asd/ab", a);
|
|
ASSERT(a == "", "");
|
|
|
|
return TESTGOOD;
|
|
}
|
|
|
|
|
|
int testFiles_scan() {
|
|
std::string path = "./tests";
|
|
std::list<std::string> out, out2;
|
|
|
|
ASSERT(files::scan(path, std::inserter(out, out.begin()), false), "");
|
|
ASSERT(files::scan(path, std::inserter(out2, out2.begin()), true), "");
|
|
|
|
ASSERT(out.size() == out2.size(), out.size() << " " << out2.size());
|
|
|
|
std::set<std::string> out3;
|
|
ASSERT(files::scan(path, std::inserter(out3, out3.begin()), false, [](const std::string& str, files::FileType t){ return mrbesen::util::startsWith(str, "."); }), "");
|
|
ASSERT(out3.size() == 2, out3.size());
|
|
ASSERT(out3.find(".") != out3.end(), "");
|
|
ASSERT(out3.find("..") != out3.end(), "");
|
|
|
|
return TESTGOOD;
|
|
}
|