Browse Source

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

default_compile_flags
vector-of-bool 4 years ago
parent
commit
8311ad7c28
3 changed files with 23 additions and 2 deletions
  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 View File

@@ -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 View File

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

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

+ 16
- 0
src/dds/source/file.test.cpp View File

@@ -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…
Cancel
Save