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

auto ext_found auto ext_found
= std::lower_bound(header_exts.begin(), header_exts.end(), p.extension(), std::less<>()); = std::lower_bound(header_exts.begin(), header_exts.end(), p.extension(), std::less<>());
if (ext_found != header_exts.end() && *ext_found == p.extension()) { 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; return source_kind::header;
} }


return std::nullopt; return std::nullopt;
} }


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


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



+ 1
- 0
src/dds/source/file.hpp View File



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

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

#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