Browse Source

Try to resolve some compilation issues around the constexpr string stuff

master
Jessica James 3 years ago
parent
commit
39a2467826
  1. 8
      src/test/http_query.cpp
  2. 6
      src/test/test.hpp
  3. 6
      src/test/unicode_sequence.cpp

8
src/test/http_query.cpp

@ -23,15 +23,15 @@
using namespace std::literals;
// Compile-time tests for constexpr on compilers which support C++20 constexpr std::string
#ifdef __cpp_lib_constexpr_string
#if defined(__cpp_lib_constexpr_string) && (__GNUC__ >= 12 || _MSC_VER >= 1929)
constexpr std::string query_constexpr(std::string_view in_expression) {
std::string result{ static_cast<std::string>(in_expression) };
jessilib::deserialize_http_query(result);
return result;
}
static_assert(query_constexpr("test"s) == "test"s);
static_assert(query_constexpr("first+second"s) == "first second"s);
static_assert(query_constexpr("first%20second"s) == "first second"s);
ASSERT_COMPILES_CONSTEXPR(return query_constexpr("test"s) == "test"s);
ASSERT_COMPILES_CONSTEXPR(return query_constexpr("first+second"s) == "first second"s);
ASSERT_COMPILES_CONSTEXPR(return query_constexpr("first%20second"s) == "first second"s);
#endif // __cpp_lib_constexpr_string
using char_types = ::testing::Types<char, char8_t, char16_t, char32_t>;

6
src/test/test.hpp

@ -1,5 +1,5 @@
/**
* Copyright (C) 2018 Jessica James.
* Copyright (C) 2018-2021 Jessica James.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -22,7 +22,11 @@
#include "gtest/gtest.h"
// Helper macros
#define ASSERT_COMPILES(expr) static_assert([]() { expr; } != nullptr, "Your compiler is whack yo");
#define ASSERT_COMPILES_CONSTEXPR(expr) static_assert([]() constexpr { expr; } != nullptr, "Your compiler is whack yo");
#define UNIQUE_LABEL( LABEL ) LABEL ## __LINE__ ## __
#define repeat( ITERATIONS ) for (size_t UNIQUE_LABEL(iteration_) = 0; UNIQUE_LABEL(iteration_) != (ITERATIONS); ++ UNIQUE_LABEL(iteration_) )
#define JESSITEST_CONCAT(lhs, rhs) JESSITEST_CONCAT_HELPER(lhs, rhs)
#define JESSITEST_CONCAT_HELPER(lhs, rhs) lhs ## rhs
using base_test = ::testing::Test;

6
src/test/unicode_sequence.cpp

@ -24,14 +24,14 @@
using namespace std::literals;
// Compile-time tests for constexpr on compilers which support C++20 constexpr std::string
#ifdef __cpp_lib_constexpr_string
#if defined(__cpp_lib_constexpr_string) && (__GNUC__ >= 12 || _MSC_VER >= 1929)
constexpr std::string cpp_constexpr(std::string_view in_expression) {
std::string result{ static_cast<std::string>(in_expression) };
jessilib::apply_cpp_escape_sequences(result);
return result;
}
static_assert(cpp_constexpr("test"s) == "test"s);
static_assert(cpp_constexpr("\\r\\n"s) == "\r\n"s);
ASSERT_COMPILES_CONSTEXPR(return cpp_constexpr("test"s) == "test"s);
ASSERT_COMPILES_CONSTEXPR(return cpp_constexpr("\\r\\n"s) == "\r\n"s);
#endif // __cpp_lib_constexpr_string
using char_types = ::testing::Types<char, char8_t, char16_t, char32_t>;

Loading…
Cancel
Save