<commit_before>#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "json.hpp"
#include "mstch/mstch.hpp"
#include "test_context.hpp"
#include "test_data.hpp"
#include "specs_data.hpp"
#include "specs_lambdas.hpp"

using namespace mstchtest;

#define MSTCH_PARTIAL_TEST(x) TEST_CASE(#x) { \
  REQUIRE(x ## _txt == mstch::render(x ## _mustache, x ## _data, {{"partial", x ## _partial}})); \
}

#define MSTCH_TEST(x) TEST_CASE(#x) { \
  REQUIRE(x ## _txt == mstch::render(x ## _mustache, x ## _data)); \
}

#define SPECS_TEST(x) TEST_CASE("specs_" #x) { \
  using boost::get; \
  auto data = json::parse<mstch::node,mstch::map,mstch::array>(x ## _json); \
  for(auto& test_item: get<mstch::array>(get<mstch::map>(data)["tests"])) {\
    auto test = get<mstch::map>(test_item); \
    std::map<std::string,std::string> partials; \
    if(test.count("partials")) \
      for(auto& partial_item: get<mstch::map>(test["partials"])) \
        partials.insert(std::make_pair(partial_item.first, get<std::string>(partial_item.second))); \
    for(std::pair<const std::string,mstch::node>& data_item: get<mstch::map>(test["data"])) \
      if(data_item.first == "lambda") \
        data_item.second = specs_lambdas[get<std::string>(test["name"])]; \
    SECTION(get<std::string>(test["name"])) \
      REQUIRE(mstch::render( \
          get<std::string>(test["template"]), \
          test["data"], partials) == \
          get<std::string>(test["expected"])); \
  } \
}

MSTCH_TEST(ampersand_escape)
MSTCH_TEST(apostrophe)
MSTCH_TEST(array_of_strings)
MSTCH_TEST(backslashes)
MSTCH_TEST(bug_11_eating_whitespace)
MSTCH_TEST(bug_length_property)
MSTCH_TEST(changing_delimiters)
MSTCH_TEST(comments)
MSTCH_TEST(complex)
MSTCH_TEST(context_lookup)
MSTCH_TEST(delimiters)
MSTCH_TEST(disappearing_whitespace)
MSTCH_TEST(dot_notation)
MSTCH_TEST(double_render)
MSTCH_TEST(empty_list)
MSTCH_TEST(empty_sections)
MSTCH_TEST(empty_string)
MSTCH_TEST(empty_template)
MSTCH_TEST(error_eof_in_section)
MSTCH_TEST(error_eof_in_tag)
MSTCH_TEST(error_not_found)<commit_msg>osx const error fix<commit_after>#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "json.hpp"
#include "mstch/mstch.hpp"
#include "test_context.hpp"
#include "test_data.hpp"
#include "specs_data.hpp"
#include "specs_lambdas.hpp"

using namespace mstchtest;

#define MSTCH_PARTIAL_TEST(x) TEST_CASE(#x) { \
  REQUIRE(x ## _txt == mstch::render(x ## _mustache, x ## _data, {{"partial", x ## _partial}})); \
}

#define MSTCH_TEST(x) TEST_CASE(#x) { \
  REQUIRE(x ## _txt == mstch::render(x ## _mustache, x ## _data)); \
}

#define SPECS_TEST(x) TEST_CASE("specs_" #x) { \
  using boost::get; \
  auto data = json::parse<mstch::node,mstch::map,mstch::array>(x ## _json); \
  for (auto& test_item: get<mstch::array>(get<mstch::map>(data)["tests"])) {\
    auto test = get<mstch::map>(test_item); \
    std::map<std::string,std::string> partials; \
    if (test.count("partials")) \
      for (auto& partial_item: get<mstch::map>(test["partials"])) \
        partials.insert(std::make_pair(partial_item.first, get<std::string>(partial_item.second))); \
    mstch::map data; \
    for (auto& data_item: get<mstch::map>(test["data"])) \
      if (data_item.first == "lambda") \
        data.insert(std::make_pair("lambda", specs_lambdas[get<std::string>(test["name"])])); \
      else \
        data.insert(data_item); \
    SECTION(get<std::string>(test["name"])) \
      REQUIRE( \
          mstch::render(get<std::string>(test["template"]), data, partials) == \
          get<std::string>(test["expected"])); \
  } \
}

MSTCH_TEST(ampersand_escape)
MSTCH_TEST(apostrophe)
MSTCH_TEST(array_of_strings)
MSTCH_TEST(backslashes)
MSTCH_TEST(bug_11_eating_whitespace)
MSTCH_TEST(bug_length_property)
MSTCH_TEST(changing_delimiters)
MSTCH_TEST(comments)
MSTCH_TEST(complex)
MSTCH_TEST(context_lookup)
MSTCH_TEST(delimiters)
MSTCH_TEST(disappearing_whitespace)
MSTCH_TEST(dot_notation)
MSTCH_TEST(double_render)
MSTCH_TEST(empty_list)
MSTCH_TEST(empty_sections)
MSTCH_TEST(empty_string)
MSTCH_TEST(empty_template)
MSTCH_TEST(error_eof_in_section)
MSTCH_TEST(error_eof_in_tag)
MSTCH_TEST(error_not_found)
{'fraction_non_alphanumeric': 0.1730537478910581, 'fraction_numerical': 0.0009640877319836105, 'mean_word_length': 6.1061643835616435, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1732851', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1672, 'n_words': 208}