Add ICU message format support
[chromium-blink-merge.git] / tools / gn / function_get_path_info_unittest.cc
blob306c57e88c134082dc4edca32fe7887b9f6f426b
1 // Copyright 2014 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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/functions.h"
7 #include "tools/gn/test_with_scope.h"
9 namespace {
11 class GetPathInfoTest : public testing::Test {
12 public:
13 GetPathInfoTest() : testing::Test() {
14 setup_.scope()->set_source_dir(SourceDir("//src/foo/"));
17 // Convenience wrapper to call GetLabelInfo.
18 std::string Call(const std::string& input, const std::string& what) {
19 FunctionCallNode function;
21 std::vector<Value> args;
22 args.push_back(Value(nullptr, input));
23 args.push_back(Value(nullptr, what));
25 Err err;
26 Value result = functions::RunGetPathInfo(setup_.scope(), &function,
27 args, &err);
28 if (err.has_error()) {
29 EXPECT_TRUE(result.type() == Value::NONE);
30 return std::string();
32 return result.string_value();
35 protected:
36 TestWithScope setup_;
39 } // namespace
41 TEST_F(GetPathInfoTest, File) {
42 EXPECT_EQ("bar.txt", Call("foo/bar.txt", "file"));
43 EXPECT_EQ("bar.txt", Call("bar.txt", "file"));
44 EXPECT_EQ("bar.txt", Call("/bar.txt", "file"));
45 EXPECT_EQ("", Call("foo/", "file"));
46 EXPECT_EQ("", Call("//", "file"));
47 EXPECT_EQ("", Call("/", "file"));
50 TEST_F(GetPathInfoTest, Name) {
51 EXPECT_EQ("bar", Call("foo/bar.txt", "name"));
52 EXPECT_EQ("bar", Call("bar.", "name"));
53 EXPECT_EQ("", Call("/.txt", "name"));
54 EXPECT_EQ("", Call("foo/", "name"));
55 EXPECT_EQ("", Call("//", "name"));
56 EXPECT_EQ("", Call("/", "name"));
59 TEST_F(GetPathInfoTest, Extension) {
60 EXPECT_EQ("txt", Call("foo/bar.txt", "extension"));
61 EXPECT_EQ("", Call("bar.", "extension"));
62 EXPECT_EQ("txt", Call("/.txt", "extension"));
63 EXPECT_EQ("", Call("f.oo/", "extension"));
64 EXPECT_EQ("", Call("//", "extension"));
65 EXPECT_EQ("", Call("/", "extension"));
68 TEST_F(GetPathInfoTest, Dir) {
69 EXPECT_EQ("foo", Call("foo/bar.txt", "dir"));
70 EXPECT_EQ(".", Call("bar.txt", "dir"));
71 EXPECT_EQ("foo/bar", Call("foo/bar/baz", "dir"));
72 EXPECT_EQ("//foo", Call("//foo/", "dir"));
73 EXPECT_EQ("//.", Call("//", "dir"));
74 EXPECT_EQ("/foo", Call("/foo/", "dir"));
75 EXPECT_EQ("/.", Call("/", "dir"));
78 // Note "current dir" is "//src/foo"
79 TEST_F(GetPathInfoTest, AbsPath) {
80 EXPECT_EQ("//src/foo/foo/bar.txt", Call("foo/bar.txt", "abspath"));
81 EXPECT_EQ("//src/foo/bar.txt", Call("bar.txt", "abspath"));
82 EXPECT_EQ("//src/foo/bar/", Call("bar/", "abspath"));
83 EXPECT_EQ("//foo", Call("//foo", "abspath"));
84 EXPECT_EQ("//foo/", Call("//foo/", "abspath"));
85 EXPECT_EQ("//", Call("//", "abspath"));
86 EXPECT_EQ("/foo", Call("/foo", "abspath"));
87 EXPECT_EQ("/foo/", Call("/foo/", "abspath"));
88 EXPECT_EQ("/", Call("/", "abspath"));
91 // Note build dir is "//out/Debug/".
92 TEST_F(GetPathInfoTest, OutDir) {
93 EXPECT_EQ("//out/Debug/obj/src/foo/foo", Call("foo/bar.txt", "out_dir"));
94 EXPECT_EQ("//out/Debug/obj/src/foo/bar", Call("bar/", "out_dir"));
95 EXPECT_EQ("//out/Debug/obj/src/foo", Call(".", "out_dir"));
96 EXPECT_EQ("//out/Debug/obj/src/foo", Call("bar", "out_dir"));
97 EXPECT_EQ("//out/Debug/obj/foo", Call("//foo/bar.txt", "out_dir"));
98 // System paths go into the ABS_PATH obj directory.
99 EXPECT_EQ("//out/Debug/obj/ABS_PATH/foo", Call("/foo/bar.txt", "out_dir"));
100 #if defined(OS_WIN)
101 EXPECT_EQ("//out/Debug/obj/ABS_PATH/C/foo",
102 Call("/C:/foo/bar.txt", "out_dir"));
103 #endif
106 // Note build dir is "//out/Debug/".
107 TEST_F(GetPathInfoTest, GenDir) {
108 EXPECT_EQ("//out/Debug/gen/src/foo/foo", Call("foo/bar.txt", "gen_dir"));
109 EXPECT_EQ("//out/Debug/gen/src/foo/bar", Call("bar/", "gen_dir"));
110 EXPECT_EQ("//out/Debug/gen/src/foo", Call(".", "gen_dir"));
111 EXPECT_EQ("//out/Debug/gen/src/foo", Call("bar", "gen_dir"));
112 EXPECT_EQ("//out/Debug/gen/foo", Call("//foo/bar.txt", "gen_dir"));
113 // System paths go into the root obj directory.
114 EXPECT_EQ("//out/Debug/gen", Call("/foo/bar.txt", "gen_dir"));