2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-06-15 09:45:45 -04:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
#include "file_util.h"
|
|
|
|
|
|
|
|
TEST(FileUtilTest, ReadFileToStringFileNotExist) {
|
|
|
|
std::string output;
|
|
|
|
EXPECT_FALSE(deno::ReadFileToString("/should_error_out.txt", &output));
|
|
|
|
}
|
|
|
|
|
2018-07-13 01:21:28 -04:00
|
|
|
TEST(FileUtilTest, Basename) {
|
|
|
|
EXPECT_EQ("foo.txt", deno::Basename("foo.txt"));
|
|
|
|
EXPECT_EQ("foo.txt", deno::Basename("/foo.txt"));
|
2018-08-25 19:37:15 -04:00
|
|
|
EXPECT_EQ("", deno::Basename("/foo/"));
|
|
|
|
EXPECT_EQ("", deno::Basename("foo/"));
|
2018-07-13 01:21:28 -04:00
|
|
|
EXPECT_EQ("", deno::Basename("/"));
|
|
|
|
EXPECT_EQ("foo.txt", deno::Basename(".\\foo.txt"));
|
|
|
|
EXPECT_EQ("foo.txt", deno::Basename("/home/ryan/foo.txt"));
|
|
|
|
EXPECT_EQ("foo.txt", deno::Basename("C:\\home\\ryan\\foo.txt"));
|
|
|
|
}
|
|
|
|
|
2018-08-25 19:37:15 -04:00
|
|
|
TEST(FileUtilTest, Dirname) {
|
|
|
|
EXPECT_EQ("home/dank/", deno::Dirname("home/dank/memes.gif"));
|
|
|
|
EXPECT_EQ("/home/dank/", deno::Dirname("/home/dank/memes.gif"));
|
|
|
|
EXPECT_EQ("/home/dank/", deno::Dirname("/home/dank/"));
|
|
|
|
EXPECT_EQ("home/dank/", deno::Dirname("home/dank/memes.gif"));
|
|
|
|
EXPECT_EQ("/", deno::Dirname("/"));
|
|
|
|
EXPECT_EQ(".\\", deno::Dirname(".\\memes.gif"));
|
|
|
|
EXPECT_EQ("c:\\", deno::Dirname("c:\\stuff"));
|
|
|
|
EXPECT_EQ("./", deno::Dirname("nothing"));
|
|
|
|
EXPECT_EQ("./", deno::Dirname(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileUtilTest, ExePath) {
|
|
|
|
std::string exe_path;
|
|
|
|
EXPECT_TRUE(deno::ExePath(&exe_path));
|
|
|
|
// Path is absolute.
|
|
|
|
EXPECT_TRUE(exe_path.find("/") == 0 || exe_path.find(":\\") == 1);
|
|
|
|
// FIlename is the name of the test binary.
|
|
|
|
std::string exe_filename = deno::Basename(exe_path);
|
2019-05-01 09:48:56 -04:00
|
|
|
EXPECT_EQ(exe_filename.find("libdeno_test"), 0u);
|
2018-08-25 19:37:15 -04:00
|
|
|
// Path exists (also tests ReadFileToString).
|
|
|
|
std::string contents;
|
|
|
|
EXPECT_TRUE(deno::ReadFileToString(exe_path.c_str(), &contents));
|
|
|
|
EXPECT_NE(contents.find("Inception :)"), std::string::npos);
|
|
|
|
}
|