blob: 85cc7a491ebbea6825124b9697938383ff4699f1 [file] [log] [blame]
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/file_platform.h"
#include "gtest/gtest.h"
#if !defined(COMPILER_MSVC) && !defined(__CYGWIN__)
#error("This test should only be run on Windows")
#endif // !defined(COMPILER_MSVC) && !defined(__CYGWIN__)
namespace blaze_util {
TEST(FileTest, TestDirname) {
ASSERT_EQ("", Dirname(""));
ASSERT_EQ("/", Dirname("/"));
ASSERT_EQ("", Dirname("foo"));
ASSERT_EQ("/", Dirname("/foo"));
ASSERT_EQ("/foo", Dirname("/foo/"));
ASSERT_EQ("foo", Dirname("foo/bar"));
ASSERT_EQ("foo/bar", Dirname("foo/bar/baz"));
ASSERT_EQ("\\", Dirname("\\foo"));
ASSERT_EQ("\\foo", Dirname("\\foo\\"));
ASSERT_EQ("foo", Dirname("foo\\bar"));
ASSERT_EQ("foo\\bar", Dirname("foo\\bar\\baz"));
ASSERT_EQ("foo\\bar/baz", Dirname("foo\\bar/baz\\qux"));
ASSERT_EQ("c:/", Dirname("c:/"));
ASSERT_EQ("c:\\", Dirname("c:\\"));
ASSERT_EQ("c:/", Dirname("c:/foo"));
ASSERT_EQ("c:\\", Dirname("c:\\foo"));
ASSERT_EQ("\\\\?\\c:\\", Dirname("\\\\?\\c:\\"));
ASSERT_EQ("\\\\?\\c:\\", Dirname("\\\\?\\c:\\foo"));
}
TEST(FileTest, TestBasename) {
ASSERT_EQ("", Basename(""));
ASSERT_EQ("", Basename("/"));
ASSERT_EQ("foo", Basename("foo"));
ASSERT_EQ("foo", Basename("/foo"));
ASSERT_EQ("", Basename("/foo/"));
ASSERT_EQ("bar", Basename("foo/bar"));
ASSERT_EQ("baz", Basename("foo/bar/baz"));
ASSERT_EQ("foo", Basename("\\foo"));
ASSERT_EQ("", Basename("\\foo\\"));
ASSERT_EQ("bar", Basename("foo\\bar"));
ASSERT_EQ("baz", Basename("foo\\bar\\baz"));
ASSERT_EQ("qux", Basename("foo\\bar/baz\\qux"));
ASSERT_EQ("", Basename("c:/"));
ASSERT_EQ("", Basename("c:\\"));
ASSERT_EQ("foo", Basename("c:/foo"));
ASSERT_EQ("foo", Basename("c:\\foo"));
ASSERT_EQ("", Basename("\\\\?\\c:\\"));
ASSERT_EQ("foo", Basename("\\\\?\\c:\\foo"));
}
} // namespace blaze_util