diff --git a/src/test/http_query.cpp b/src/test/http_query.cpp index a5491c2..f885a83 100644 --- a/src/test/http_query.cpp +++ b/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(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; diff --git a/src/test/test.hpp b/src/test/test.hpp index 58aafd0..42fb522 100644 --- a/src/test/test.hpp +++ b/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; diff --git a/src/test/unicode_sequence.cpp b/src/test/unicode_sequence.cpp index c48dd21..291f8e7 100644 --- a/src/test/unicode_sequence.cpp +++ b/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(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;