1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00
denoland-deno/src/file_util_test.cc
2018-07-24 10:38:11 -04:00

28 lines
1 KiB
C++

// Copyright 2018 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("/"));
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, BinaryContentAsC) {
auto c_code = deno::BinaryContentAsC("aaa", std::string("bbb"));
EXPECT_TRUE(c_code.find("static const char aaa_data[]") != std::string::npos);
EXPECT_TRUE(c_code.find("static const int aaa_size = 3;") !=
std::string::npos);
}
// TODO(ry) success unit test. Needs a tempfile or fixture.
// TEST(FileUtilTest, ReadFileToStringSuccess) { }