瀏覽代碼

`header_template` source kind is a header file with a `.config` on its stem

default_compile_flags
vector-of-bool 4 年之前
父節點
當前提交
8311ad7c28
共有 3 個文件被更改,包括 23 次插入2 次删除
  1. +6
    -2
      src/dds/source/file.cpp
  2. +1
    -0
      src/dds/source/file.hpp
  3. +16
    -0
      src/dds/source/file.test.cpp

+ 6
- 2
src/dds/source/file.cpp 查看文件

@@ -35,6 +35,10 @@ std::optional<source_kind> dds::infer_source_kind(path_ref p) noexcept {
auto ext_found
= std::lower_bound(header_exts.begin(), header_exts.end(), p.extension(), std::less<>());
if (ext_found != header_exts.end() && *ext_found == p.extension()) {
auto stem = p.stem();
if (stem.extension() == ".config") {
return source_kind::header_template;
}
return source_kind::header;
}

@@ -44,11 +48,11 @@ std::optional<source_kind> dds::infer_source_kind(path_ref p) noexcept {
return std::nullopt;
}

if (ends_with(p.stem().string(), ".test")) {
if (p.stem().extension() == ".test") {
return source_kind::test;
}

if (ends_with(p.stem().string(), ".main")) {
if (p.stem().extension() == ".main") {
return source_kind::app;
}


+ 1
- 0
src/dds/source/file.hpp 查看文件

@@ -9,6 +9,7 @@ namespace dds {

enum class source_kind {
header,
header_template,
source,
test,
app,

+ 16
- 0
src/dds/source/file.test.cpp 查看文件

@@ -0,0 +1,16 @@
#include <dds/source/file.hpp>

#include <catch2/catch.hpp>

using dds::source_kind;

TEST_CASE("Infer source kind") {
using dds::infer_source_kind;
auto k = infer_source_kind("foo.h");
CHECK(k == source_kind::header);
CHECK(infer_source_kind("foo.hpp") == source_kind::header);
CHECK_FALSE(infer_source_kind("foo.txt")); // Not a source file extension

CHECK(infer_source_kind("foo.hh") == source_kind::header);
CHECK(infer_source_kind("foo.config.hpp") == source_kind::header_template);
}

Loading…
取消
儲存