~quf/libcs3tio

759300e91d430bc1fd398d25516b362f6db712a0 — Lukas Himbert 8 months ago c67069e
test program: print header names for each tbl
2 files changed, 41 insertions(+), 1 deletions(-)

M compile.sh
A test/header_names.cpp
M compile.sh => compile.sh +1 -1
@@ 18,7 18,7 @@ done

ar cr build/output/libcs3tio.a build/obj/*.o build/obj-ksp/*.o

for x in compiles duplicates tio roundtrip; do
for x in compiles duplicates header_names tio roundtrip; do
  "$CXX" -std=c++20 -W -Wall -Werror -Wfatal-errors -fsanitize=address,undefined -I src test/$x.cpp build/output/libcs3tio.a -o build/test/$x
  #build/test/$x
done

A test/header_names.cpp => test/header_names.cpp +40 -0
@@ 0,0 1,40 @@
// for each .tbl file in a directory, prints all occuring header names.

#include <cs3tio.h>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <set>
#include <string>

typedef std::set<std::string, std::less<>> set_type;

int main(int argc, char *argv[]) {
  if (argc != 2) {
    throw std::runtime_error("expected directory name as single cli argument");
  }
  auto dir = std::filesystem::path(argv[1]);

  for (const auto &file : std::filesystem::recursive_directory_iterator(dir)) {
    if (file.is_regular_file() && file.path().extension() == ".tbl") {
      set_type header_names;
      auto f = std::ifstream(file.path());
      auto tbl = cs3tio::load_tbl(f);
      for (auto const &header : tbl.headers) {
        if (!header_names.contains(header)) {
          header_names.emplace(std::string(header));
        }
      }
      for (auto const &entry : tbl.entries) {
        auto header = header_name(entry);
        if (!header_names.contains(header)) {
          header_names.emplace(std::string(header));
        }
      }
      std::cout << "- " << file.path().filename() << std::endl;
      for (auto const &header : header_names) {
        std::cout << "    '" << header << "'" << std::endl;
      }
    }
  }
}