Ninja
includes_normalize_test.cc
Go to the documentation of this file.
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "includes_normalize.h"
16 
17 #include <gtest/gtest.h>
18 
19 #include "test.h"
20 #include "util.h"
21 
23  EXPECT_EQ("b", IncludesNormalize::Normalize("a\\..\\b", NULL));
24  EXPECT_EQ("b", IncludesNormalize::Normalize("a\\../b", NULL));
25  EXPECT_EQ("a\\b", IncludesNormalize::Normalize("a\\.\\b", NULL));
26  EXPECT_EQ("a\\b", IncludesNormalize::Normalize("a\\./b", NULL));
27 }
28 
29 namespace {
30 
31 string GetCurDir() {
32  char buf[_MAX_PATH];
33  _getcwd(buf, sizeof(buf));
34  vector<string> parts = IncludesNormalize::Split(string(buf), '\\');
35  return parts[parts.size() - 1];
36 }
37 
38 } // namespace
39 
40 TEST(IncludesNormalize, WithRelative) {
41  string currentdir = IncludesNormalize::ToLower(GetCurDir());
42  EXPECT_EQ("c", IncludesNormalize::Normalize("a/b/c", "a/b"));
44  NULL));
45  EXPECT_EQ(string("..\\") + currentdir + string("\\a"),
46  IncludesNormalize::Normalize("a", "../b"));
47  EXPECT_EQ(string("..\\") + currentdir + string("\\a\\b"),
48  IncludesNormalize::Normalize("a/b", "../c"));
49  EXPECT_EQ("..\\..\\a", IncludesNormalize::Normalize("a", "b/c"));
50  EXPECT_EQ(".", IncludesNormalize::Normalize("a", "a"));
51 }
52 
54  EXPECT_EQ("b", IncludesNormalize::Normalize("Abc\\..\\b", NULL));
55  EXPECT_EQ("BdEf", IncludesNormalize::Normalize("Abc\\..\\BdEf", NULL));
56  EXPECT_EQ("A\\b", IncludesNormalize::Normalize("A\\.\\b", NULL));
57  EXPECT_EQ("a\\b", IncludesNormalize::Normalize("a\\./b", NULL));
58  EXPECT_EQ("A\\B", IncludesNormalize::Normalize("A\\.\\B", NULL));
59  EXPECT_EQ("A\\B", IncludesNormalize::Normalize("A\\./B", NULL));
60 }
61 
63  vector<string> x;
64  EXPECT_EQ("", IncludesNormalize::Join(x, ':'));
65  x.push_back("alpha");
66  EXPECT_EQ("alpha", IncludesNormalize::Join(x, ':'));
67  x.push_back("beta");
68  x.push_back("gamma");
69  EXPECT_EQ("alpha:beta:gamma", IncludesNormalize::Join(x, ':'));
70 }
71 
74  ':'));
75  EXPECT_EQ("a", IncludesNormalize::Join(IncludesNormalize::Split("a", '/'),
76  ':'));
77  EXPECT_EQ("a:b:c",
79  IncludesNormalize::Split("a/b/c", '/'), ':'));
80 }
81 
83  EXPECT_EQ("", IncludesNormalize::ToLower(""));
84  EXPECT_EQ("stuff", IncludesNormalize::ToLower("Stuff"));
85  EXPECT_EQ("stuff and things", IncludesNormalize::ToLower("Stuff AND thINGS"));
86  EXPECT_EQ("stuff 3and thin43gs",
87  IncludesNormalize::ToLower("Stuff 3AND thIN43GS"));
88 }
89 
90 TEST(IncludesNormalize, DifferentDrive) {
91  EXPECT_EQ("stuff.h",
92  IncludesNormalize::Normalize("p:\\vs08\\stuff.h", "p:\\vs08"));
93  EXPECT_EQ("stuff.h",
94  IncludesNormalize::Normalize("P:\\Vs08\\stuff.h", "p:\\vs08"));
95  EXPECT_EQ("p:\\vs08\\stuff.h",
96  IncludesNormalize::Normalize("p:\\vs08\\stuff.h", "c:\\vs08"));
97  EXPECT_EQ("P:\\vs08\\stufF.h",
98  IncludesNormalize::Normalize("P:\\vs08\\stufF.h", "D:\\stuff/things"));
99  EXPECT_EQ("P:\\vs08\\stuff.h",
100  IncludesNormalize::Normalize("P:/vs08\\stuff.h", "D:\\stuff/things"));
101  // TODO: this fails; fix it.
102  //EXPECT_EQ("P:\\wee\\stuff.h",
103  // IncludesNormalize::Normalize("P:/vs08\\../wee\\stuff.h", "D:\\stuff/things"));
104 }
static string Join(const vector< string > &list, char sep)
static vector< string > Split(const string &input, char sep)
static string Normalize(const string &input, const char *relative_to)
Normalize by fixing slashes style, fixing redundant .
static string AbsPath(StringPiece s)
static string ToLower(const string &s)
Utility functions for normalizing include paths on Windows.
TEST(IncludesNormalize, Simple)