forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_static_test.cpp
65 lines (51 loc) · 1.84 KB
/
make_static_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iosfwd>
#include <string>
#include <type_traits>
#include "cata_catch.h"
#include "make_static.h"
#include "string_id.h"
TEST_CASE( "make_static_macro_test", "[make_static_macro]" )
{
using test_id_type = string_id<int>;
CHECK( 1 == STATIC( 1 ) );
CHECK_FALSE( 2 == STATIC( 1 ) );
CHECK( test_id_type( "test1" ) == STATIC( test_id_type( "test1" ) ) );
CHECK_FALSE( test_id_type( "test1" ) == STATIC( test_id_type( "test2" ) ) );
// check the static scope
auto get_static = []() -> const auto & {
return STATIC( std::string( "test" ) );
};
// entity with the same address should be returned
CHECK( &get_static() == &get_static() );
const auto test11 = STATIC( "test11" );
static_assert( std::is_same<std::decay_t<decltype( test11 )>, std::string>::value,
"type must be std::string" );
CHECK( test11 == "test11" );
CHECK( STATIC( "test11" ) == "test11" );
CHECK( STATIC( "test11" ) == STATIC( "test11" ) );
CHECK_FALSE( STATIC( "test11" ) == STATIC( "test12" ) );
}
TEST_CASE( "make_static_macro_benchmark_string_id", "[.][make_static_macro][benchmark]" )
{
using test_id_type = string_id<int>;
static const test_id_type test_id( "test" );
BENCHMARK( "static variable outside" ) {
return test_id.is_empty();
};
BENCHMARK( "static variable inside" ) {
static const test_id_type test_id( "test" );
return test_id.is_empty();
};
BENCHMARK( "inline const" ) {
return test_id_type( "test" ).is_empty();
};
BENCHMARK( "static in a lambda" ) {
return ( []() -> const auto & {
static const test_id_type test_id( "test" );
return test_id;
} )().is_empty();
};
BENCHMARK( "make_static macro" ) {
return STATIC( test_id_type( "test" ) ).is_empty();
};
}