1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "testing/gtest/include/gtest/gtest.h" 6 #include "tools/gn/source_dir.h" 7 #include "tools/gn/source_file.h" 8 9 TEST(SourceDir, ResolveRelativeFile) { 10 SourceDir base("//base/"); 11 12 // Empty input is an error. 13 EXPECT_TRUE(base.ResolveRelativeFile("") == SourceFile()); 14 15 // These things are directories, so should be an error. 16 EXPECT_TRUE(base.ResolveRelativeFile("//foo/bar/") == SourceFile()); 17 EXPECT_TRUE(base.ResolveRelativeFile("bar/") == SourceFile()); 18 19 // Absolute paths should be passed unchanged. 20 EXPECT_TRUE(base.ResolveRelativeFile("//foo") == SourceFile("//foo")); 21 EXPECT_TRUE(base.ResolveRelativeFile("/foo") == SourceFile("/foo")); 22 23 // Basic relative stuff. 24 EXPECT_TRUE(base.ResolveRelativeFile("foo") == SourceFile("//base/foo")); 25 EXPECT_TRUE(base.ResolveRelativeFile("./foo") == SourceFile("//base/foo")); 26 EXPECT_TRUE(base.ResolveRelativeFile("../foo") == SourceFile("//foo")); 27 EXPECT_TRUE(base.ResolveRelativeFile("../../foo") == SourceFile("//foo")); 28 } 29 30 TEST(SourceDir, ResolveRelativeDir) { 31 SourceDir base("//base/"); 32 33 // Empty input is an error. 34 EXPECT_TRUE(base.ResolveRelativeDir("") == SourceDir()); 35 36 // Absolute paths should be passed unchanged. 37 EXPECT_TRUE(base.ResolveRelativeDir("//foo") == SourceDir("//foo/")); 38 EXPECT_TRUE(base.ResolveRelativeDir("/foo") == SourceDir("/foo/")); 39 40 // Basic relative stuff. 41 EXPECT_TRUE(base.ResolveRelativeDir("foo") == SourceDir("//base/foo/")); 42 EXPECT_TRUE(base.ResolveRelativeDir("./foo") == SourceDir("//base/foo/")); 43 EXPECT_TRUE(base.ResolveRelativeDir("../foo") == SourceDir("//foo/")); 44 EXPECT_TRUE(base.ResolveRelativeDir("../../foo/") == SourceDir("//foo/")); 45 } 46