summaryrefslogtreecommitdiff
path: root/core/libdeno/file_util_test.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-03-30 14:45:36 -0400
committerGitHub <noreply@github.com>2019-03-30 14:45:36 -0400
commitc9614d86c190b98bd8f0df9e17272387c3bad1d5 (patch)
tree68d9054cabb8a829beac72024d48c37f0fce7321 /core/libdeno/file_util_test.cc
parentad3cbc50fb255f287a890a28f158f6842d335538 (diff)
Move //libdeno to //core/libdeno (#2015)
Fixes some sed errors introduced in c43cfe. Unfortunately moving libdeno required splitting build.rs into two parts, one for cli and one for core. I've also removed the arm64 build - it's complicating things at this re-org and we're not even testing it. I need to swing back to it and get tools/test.py running for it.
Diffstat (limited to 'core/libdeno/file_util_test.cc')
-rw-r--r--core/libdeno/file_util_test.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/libdeno/file_util_test.cc b/core/libdeno/file_util_test.cc
new file mode 100644
index 000000000..80c878044
--- /dev/null
+++ b/core/libdeno/file_util_test.cc
@@ -0,0 +1,46 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+#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));
+}
+
+TEST(FileUtilTest, Basename) {
+ EXPECT_EQ("foo.txt", deno::Basename("foo.txt"));
+ EXPECT_EQ("foo.txt", deno::Basename("/foo.txt"));
+ EXPECT_EQ("", deno::Basename("/foo/"));
+ EXPECT_EQ("", deno::Basename("foo/"));
+ 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"));
+}
+
+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);
+ EXPECT_EQ(exe_filename.find("test_cc"), 0u);
+ // 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);
+}