Example #1
0
FATAL_TEST(enums, try_parse) {
# define CREATE_TEST(e, x) \
  do { \
    std::string const s(FATAL_TO_STR(x)); \
    e out = static_cast<e>(-1); \
    FATAL_EXPECT_TRUE(enum_traits<e>::try_parse(out, s)); \
    FATAL_EXPECT_EQ(e::x, out); \
    \
    out = static_cast<e>(-1); \
    FATAL_EXPECT_TRUE(enum_traits<e>::try_parse(out, s.begin(), s.end())); \
    FATAL_EXPECT_EQ(e::x, out); \
    \
    out = static_cast<e>(-1); \
    FATAL_EXPECT_FALSE(enum_traits<e>::try_parse(out, s.begin(), s.begin())); \
    FATAL_EXPECT_EQ(static_cast<e>(-1), out); \
    \
    FATAL_EXPECT_FALSE( \
      enum_traits<e>::try_parse( \
        out, s.begin(), std::next(s.begin(), s.size() - 1) \
      ) \
    ); \
    FATAL_EXPECT_EQ(static_cast<e>(-1), out); \
    \
    auto const i = s + "invalid"; \
    FATAL_EXPECT_FALSE((enum_traits<e>::try_parse(out, i))); \
    FATAL_EXPECT_FALSE((enum_traits<e>::try_parse(out, i.begin(), i.end()))); \
  } while (false)

  CREATE_TEST(test_enum, state0);
  CREATE_TEST(test_enum, state1);
  CREATE_TEST(test_enum, state2);
  CREATE_TEST(test_enum, state3);

  CREATE_TEST(custom_enum, field0);
  CREATE_TEST(custom_enum, field1);
  CREATE_TEST(custom_enum, field2);

# undef CREATE_TEST

  {
    using traits = enum_traits<test_enum>;
    traits::type out;

    FATAL_EXPECT_FALSE(traits::try_parse(out, std::string()));
    FATAL_EXPECT_FALSE(traits::try_parse(out, std::string("invalid")));
  }

  {
    using traits = enum_traits<custom_enum>;
    traits::type out;

    FATAL_EXPECT_FALSE(traits::try_parse(out, std::string()));
    FATAL_EXPECT_FALSE(traits::try_parse(out, std::string("invalid")));
  }
}
Example #2
0
FATAL_TEST(traits, is_safe_overload) {
  FATAL_EXPECT_FALSE((is_safe_overload<Base, Base>::value));
  FATAL_EXPECT_FALSE((is_safe_overload<Base, Derived>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, int>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, void>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, Foo>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, int, int>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, void, void>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, Foo, Foo>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, int, int, int>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, void, void, void>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, Foo, Foo, Foo>::value));
  FATAL_EXPECT_TRUE((is_safe_overload<Base, int, void, Foo, bool>::value));
}
Example #3
0
FATAL_TEST(index_search, list) {
  using h = list<void, bool, double, int, unsigned>;
  FATAL_EXPECT_TRUE(index_search<h>(0, search_visitor<void, 0>()));
  FATAL_EXPECT_TRUE(index_search<h>(1, search_visitor<bool, 1>()));
  FATAL_EXPECT_TRUE(index_search<h>(2, search_visitor<double, 2>()));
  FATAL_EXPECT_TRUE(index_search<h>(3, search_visitor<int, 3>()));
  FATAL_EXPECT_TRUE(index_search<h>(4, search_visitor<unsigned, 4>()));
  FATAL_EXPECT_FALSE(index_search<h>(5, search_visitor<void *, 5>()));
}
Example #4
0
FATAL_TEST(scalar_search, list) {
  using h = index_list<50, 20, 10, 40, 30>;
  FATAL_EXPECT_TRUE(scalar_search<h>(10, value_search_visitor<10, 0>()));
  FATAL_EXPECT_TRUE(scalar_search<h>(20, value_search_visitor<20, 1>()));
  FATAL_EXPECT_TRUE(scalar_search<h>(30, value_search_visitor<30, 2>()));
  FATAL_EXPECT_TRUE(scalar_search<h>(40, value_search_visitor<40, 3>()));
  FATAL_EXPECT_TRUE(scalar_search<h>(50, value_search_visitor<50, 4>()));
  FATAL_EXPECT_FALSE(scalar_search<h>(60, value_search_visitor<60, 5>()));
}
FATAL_TEST(pointer_selector, managed) {
  FATAL_EXPECT_FALSE((pointer_selector<pointer_class::raw, int>::managed::value));
  FATAL_EXPECT_FALSE((
    pointer_selector<pointer_class::raw, int const>::managed::value
  ));
  FATAL_EXPECT_TRUE((pointer_selector<pointer_class::unique, int>::managed::value));
  FATAL_EXPECT_TRUE((
    pointer_selector<pointer_class::unique, int const>::managed::value
  ));
  FATAL_EXPECT_TRUE((
    pointer_selector<pointer_class::unique, int, test_deleter>::managed::value
  ));
  FATAL_EXPECT_TRUE((
    pointer_selector<
      pointer_class::unique, int const, test_deleter
    >::managed::value
  ));
  FATAL_EXPECT_TRUE((pointer_selector<pointer_class::shared, int>::managed::value));
  FATAL_EXPECT_TRUE((
    pointer_selector<pointer_class::shared, int const>::managed::value
  ));
}
Example #6
0
FATAL_TEST(sorted_search, empty) {
  using h = index_list<>;
  FATAL_EXPECT_FALSE(sorted_search<h>(10, value_search_visitor<10, 0>()));
  FATAL_EXPECT_FALSE(sorted_search<h>(20, value_search_visitor<20, 1>()));
  FATAL_EXPECT_FALSE(sorted_search<h>(30, value_search_visitor<30, 2>()));
  FATAL_EXPECT_FALSE(sorted_search<h>(40, value_search_visitor<40, 3>()));
  FATAL_EXPECT_FALSE(sorted_search<h>(50, value_search_visitor<50, 4>()));
  FATAL_EXPECT_FALSE(sorted_search<h>(60, value_search_visitor<60, 5>()));
}
Example #7
0
FATAL_TEST(traits, is_fast_pass) {
  FATAL_EXPECT_TRUE(is_fast_pass<bool>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool &&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const &&>::value);

  FATAL_EXPECT_TRUE(is_fast_pass<bool *>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool *&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool *&&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool *const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool *const &&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const *>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const *&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const *&&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const *const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<bool const *const &&>::value);

  FATAL_EXPECT_TRUE(is_fast_pass<int>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int &&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const &&>::value);

  FATAL_EXPECT_TRUE(is_fast_pass<int *>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int *&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int *&&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int *const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int *const &&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const *>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const *&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const *&&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const *const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<int const *const &&>::value);

  FATAL_EXPECT_FALSE(is_fast_pass<std::string>::value);
  FATAL_EXPECT_FALSE(is_fast_pass<std::string &>::value);
  FATAL_EXPECT_FALSE(is_fast_pass<std::string &&>::value);
  FATAL_EXPECT_FALSE(is_fast_pass<std::string const>::value);
  FATAL_EXPECT_FALSE(is_fast_pass<std::string const &>::value);
  FATAL_EXPECT_FALSE(is_fast_pass<std::string const &&>::value);

  FATAL_EXPECT_TRUE(is_fast_pass<std::string *>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string *&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string *&&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string *const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string *const &&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string const *>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string const *&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string const *&&>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string const *const &>::value);
  FATAL_EXPECT_TRUE(is_fast_pass<std::string const *const &&>::value);
}
Example #8
0
FATAL_TEST(type_get, first_comparer) {
  FATAL_EXPECT_TRUE((
    Foo<5, 99, 8, 1>::comparison<
      type_get_first_comparer<>::template compare
    >::value
  ));

  FATAL_EXPECT_TRUE((
    Foo<5, 99, 8, 1>::comparison<
      type_get_first_comparer<comparison_transform::less_than>::template compare
    >::value
  ));

  FATAL_EXPECT_FALSE((
    Foo<5, 99, 8, 1>::comparison<
      type_get_first_comparer<
        comparison_transform::greater_than
      >::template compare
    >::value
  ));
}
Example #9
0
FATAL_TEST(type_get, second_comparer) {
  FATAL_EXPECT_TRUE((
    Foo<99, 5, 1, 8>::comparison<
      type_get_second_comparer<>::template compare
    >::value
  ));

  FATAL_EXPECT_TRUE((
    Foo<99, 5, 1, 8>::comparison<
      type_get_second_comparer<
        comparison_transform::less_than
      >::template compare
    >::value
  ));

  FATAL_EXPECT_FALSE((
    Foo<99, 5, 1, 8>::comparison<
      type_get_second_comparer<
        comparison_transform::greater_than
      >::template compare
    >::value
  ));
}
Example #10
0
FATAL_TEST(traits, is_callable) {
  auto const lambda = []() {};
  auto const lambda_is = [](int, std::string) {};

  FATAL_EXPECT_TRUE((is_callable<foonctor>::value));
  FATAL_EXPECT_FALSE((is_callable<foonctor, int>::value));
  FATAL_EXPECT_FALSE((is_callable<foonctor, int, double>::value));
  FATAL_EXPECT_TRUE((is_callable<foonctor, int, std::string>::value));

  FATAL_EXPECT_TRUE((is_callable<decltype(lambda)>::value));
  FATAL_EXPECT_FALSE((is_callable<decltype(lambda), int>::value));
  FATAL_EXPECT_FALSE((is_callable<decltype(lambda), int, double>::value));
  FATAL_EXPECT_FALSE((is_callable<decltype(lambda), int, std::string>::value));

  FATAL_EXPECT_FALSE((is_callable<decltype(lambda_is)>::value));
  FATAL_EXPECT_FALSE((is_callable<decltype(lambda_is), int>::value));
  FATAL_EXPECT_FALSE((is_callable<decltype(lambda_is), int, double>::value));
  FATAL_EXPECT_TRUE((
    is_callable<decltype(lambda_is), int, std::string>::value
  ));

  FATAL_EXPECT_TRUE((is_callable<foonction>::value));
  FATAL_EXPECT_FALSE((is_callable<foonction, int>::value));
  FATAL_EXPECT_FALSE((is_callable<foonction, int, double>::value));
  FATAL_EXPECT_FALSE((is_callable<foonction, int, std::string>::value));

  FATAL_EXPECT_FALSE((is_callable<foonction_is>::value));
  FATAL_EXPECT_FALSE((is_callable<foonction_is, int>::value));
  FATAL_EXPECT_FALSE((is_callable<foonction_is, int, double>::value));
  FATAL_EXPECT_TRUE((is_callable<foonction_is, int, std::string>::value));
}