test/TestFs: move to test/fs/

This commit is contained in:
Max Kellermann
2022-07-14 17:55:58 +02:00
parent 2670bbdcc8
commit 0514f25c61
4 changed files with 16 additions and 15 deletions

79
test/fs/TestFs.cxx Normal file
View File

@@ -0,0 +1,79 @@
/*
* Unit tests for src/fs/
*/
#include "config.h"
#include "fs/Glob.hxx"
#include <gtest/gtest.h>
#ifdef HAVE_CLASS_GLOB
TEST(Glob, Basic)
{
const Glob glob("foo");
EXPECT_TRUE(glob.Check("foo"));
EXPECT_FALSE(glob.Check("fooo"));
EXPECT_FALSE(glob.Check("_foo"));
EXPECT_FALSE(glob.Check("a/foo"));
EXPECT_FALSE(glob.Check(""));
EXPECT_FALSE(glob.Check("*"));
}
TEST(Glob, Asterisk)
{
const Glob glob("*");
EXPECT_TRUE(glob.Check("foo"));
EXPECT_TRUE(glob.Check("bar"));
EXPECT_TRUE(glob.Check("*"));
EXPECT_TRUE(glob.Check("?"));
}
TEST(Glob, QuestionMark)
{
const Glob glob("foo?bar");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_FALSE(glob.Check("foobar"));
EXPECT_FALSE(glob.Check("foo__bar"));
}
TEST(Glob, Wildcard)
{
const Glob glob("foo*bar");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_TRUE(glob.Check("foobar"));
EXPECT_TRUE(glob.Check("foo__bar"));
EXPECT_FALSE(glob.Check("_foobar"));
EXPECT_FALSE(glob.Check("foobar_"));
}
TEST(Glob, PrefixWildcard)
{
const Glob glob("*bar");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_TRUE(glob.Check("foobar"));
EXPECT_TRUE(glob.Check("foo__bar"));
EXPECT_TRUE(glob.Check("_foobar"));
EXPECT_TRUE(glob.Check("bar"));
EXPECT_FALSE(glob.Check("foobar_"));
}
TEST(Glob, SuffixWildcard)
{
const Glob glob("foo*");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_TRUE(glob.Check("foobar"));
EXPECT_TRUE(glob.Check("foo__bar"));
EXPECT_TRUE(glob.Check("foobar_"));
EXPECT_TRUE(glob.Check("foo"));
}
#endif

View File

@@ -0,0 +1,30 @@
#include "fs/LookupFile.hxx"
#include "util/Compiler.h"
#include <gtest/gtest.h>
#include <string.h>
#include <stdlib.h>
TEST(ArchiveTest, Lookup)
{
EXPECT_THROW(LookupFile(Path::FromFS(PATH_LITERAL(""))), std::system_error);
EXPECT_FALSE(LookupFile(Path::FromFS(PATH_LITERAL("."))));
EXPECT_FALSE(LookupFile(Path::FromFS(PATH_LITERAL("config.h"))));
EXPECT_THROW(LookupFile(Path::FromFS(PATH_LITERAL("src/foo/bar"))), std::system_error);
fclose(fopen("dummy", "w"));
auto result = LookupFile(Path::FromFS(PATH_LITERAL("dummy/foo/bar")));
EXPECT_TRUE(result);
EXPECT_STREQ(result.archive.c_str(), PATH_LITERAL("dummy"));
EXPECT_STREQ(result.inside.c_str(), PATH_LITERAL("foo/bar"));
result = LookupFile(Path::FromFS(PATH_LITERAL("config.h/foo/bar")));
EXPECT_TRUE(result);
EXPECT_STREQ(result.archive.c_str(), PATH_LITERAL("config.h"));
EXPECT_STREQ(result.inside.c_str(), PATH_LITERAL("foo/bar"));
}

14
test/fs/meson.build Normal file
View File

@@ -0,0 +1,14 @@
test(
'TestFs',
executable(
'TestFs',
'TestFs.cxx',
'TestLookupFile.cxx',
include_directories: inc,
dependencies: [
fs_dep,
gtest_dep,
],
),
protocol: 'gtest',
)