• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 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 "gn/source_file.h"
6 
7 #include "util/test/test.h"
8 
9 // The SourceFile object should normalize the input passed to the constructor.
10 // The normalizer unit test checks for all the weird edge cases for normalizing
11 // so here just check that it gets called.
TEST(SourceFile,Normalize)12 TEST(SourceFile, Normalize) {
13   SourceFile a("//foo/../bar.cc");
14   EXPECT_EQ("//bar.cc", a.value());
15 
16   std::string b_str("//foo/././../bar.cc");
17   SourceFile b(std::move(b_str));
18   EXPECT_TRUE(b_str.empty());  // Should have been swapped in.
19   EXPECT_EQ("//bar.cc", b.value());
20 }
21 
TEST(SourceFile,GetType)22 TEST(SourceFile, GetType) {
23   static const struct {
24     std::string_view path;
25     SourceFile::Type type;
26   } kData[] = {
27       {"", SourceFile::SOURCE_UNKNOWN},
28       {"a.c", SourceFile::SOURCE_C},
29       {"a.cc", SourceFile::SOURCE_CPP},
30       {"a.cpp", SourceFile::SOURCE_CPP},
31       {"a.cxx", SourceFile::SOURCE_CPP},
32       {"a.c++", SourceFile::SOURCE_CPP},
33       {"foo.h", SourceFile::SOURCE_H},
34       {"foo.hh", SourceFile::SOURCE_H},
35       {"foo.hpp", SourceFile::SOURCE_H},
36       {"foo.inc", SourceFile::SOURCE_H},
37       {"foo.inl", SourceFile::SOURCE_H},
38       {"foo.ipp", SourceFile::SOURCE_H},
39       {"foo.m", SourceFile::SOURCE_M},
40       {"foo.mm", SourceFile::SOURCE_MM},
41       {"foo.o", SourceFile::SOURCE_O},
42       {"foo.obj", SourceFile::SOURCE_O},
43       {"foo.S", SourceFile::SOURCE_S},
44       {"foo.s", SourceFile::SOURCE_S},
45       {"foo.asm", SourceFile::SOURCE_S},
46       {"foo.go", SourceFile::SOURCE_GO},
47       {"foo.rc", SourceFile::SOURCE_RC},
48       {"foo.rs", SourceFile::SOURCE_RS},
49       {"foo.def", SourceFile::SOURCE_DEF},
50       {"foo.swift", SourceFile::SOURCE_SWIFT},
51       {"foo.swiftmodule", SourceFile::SOURCE_SWIFTMODULE},
52       {"foo.modulemap", SourceFile::SOURCE_MODULEMAP},
53 
54       // A few degenerate cases
55       {"foo.obj/a", SourceFile::SOURCE_UNKNOWN},
56       {"foo.cppp", SourceFile::SOURCE_UNKNOWN},
57       {"cpp", SourceFile::SOURCE_UNKNOWN},
58   };
59   for (const auto& data : kData) {
60     EXPECT_EQ(data.type, SourceFile(data.path).GetType());
61   }
62 }
63