|
| 1 | +#include <xtd/stream_insertable> |
| 2 | +#include <xtd/tunit/constraints/assert_that> |
| 3 | +#include <xtd/tunit/test_class_attribute> |
| 4 | +#include <xtd/tunit/test_method_attribute> |
| 5 | + |
| 6 | +namespace xtd::tests { |
| 7 | + class test_class_(stream_insertable_tests) { |
| 8 | + template<class value_t> |
| 9 | + requires stream_insertable<value_t> |
| 10 | + auto is_stream_insertable(value_t&& value) -> bool {return true;} |
| 11 | + template<class value_t> |
| 12 | + requires (!stream_insertable<value_t>) |
| 13 | + auto is_stream_insertable(value_t&& value) -> bool {return false;} |
| 14 | + |
| 15 | + struct my_stream_insertable { |
| 16 | + friend auto operator <<(std::ostream& os, const my_stream_insertable&) -> std::ostream& {return os << "my_stream_insertable";} |
| 17 | + }; |
| 18 | + |
| 19 | + struct my_stringable : public istringable<my_stringable> { |
| 20 | + auto to_string() const -> string override {return "my_stringable";} |
| 21 | + }; |
| 22 | + |
| 23 | + struct my_stream_not_insertable { |
| 24 | + }; |
| 25 | + |
| 26 | + auto test_method_(with_string_literal) { |
| 27 | + assert_that(is_stream_insertable("str")).is().true_(); |
| 28 | + } |
| 29 | + |
| 30 | + auto test_method_(with_object) { |
| 31 | + assert_that(is_stream_insertable(object {})).is().false_(); |
| 32 | + } |
| 33 | + |
| 34 | + auto test_method_(with_string) { |
| 35 | + assert_that(is_stream_insertable("str"_s)).is().true_(); |
| 36 | + } |
| 37 | + |
| 38 | + auto test_method_(with_version) { |
| 39 | + assert_that(is_stream_insertable("1.2.3"_vers)).is().false_(); |
| 40 | + } |
| 41 | + |
| 42 | + auto test_method_(with_my_stream_insertable) { |
| 43 | + assert_that(is_stream_insertable(my_stream_insertable {})).is().true_(); |
| 44 | + } |
| 45 | + |
| 46 | + auto test_method_(with_my_stream_not_insertable) { |
| 47 | + assert_that(is_stream_insertable(my_stream_not_insertable {})).is().false_(); |
| 48 | + } |
| 49 | + |
| 50 | + auto test_method_(with_my_stringable) { |
| 51 | + assert_that(is_stream_insertable(my_stringable {})).is().true_(); |
| 52 | + } |
| 53 | + |
| 54 | + auto test_method_(with_bool) { |
| 55 | + assert_that(is_stream_insertable(true)).is().true_(); |
| 56 | + assert_that(is_stream_insertable(false)).is().true_(); |
| 57 | + } |
| 58 | + |
| 59 | + auto test_method_(with_integrals) { |
| 60 | + assert_that(is_stream_insertable(42_s8)).is().true_(); |
| 61 | + assert_that(is_stream_insertable(42_s16)).is().true_(); |
| 62 | + assert_that(is_stream_insertable(42_s32)).is().true_(); |
| 63 | + assert_that(is_stream_insertable(42_s64)).is().true_(); |
| 64 | + |
| 65 | + assert_that(is_stream_insertable(42_u8)).is().true_(); |
| 66 | + assert_that(is_stream_insertable(42_u16)).is().true_(); |
| 67 | + assert_that(is_stream_insertable(42_u32)).is().true_(); |
| 68 | + assert_that(is_stream_insertable(42_u64)).is().true_(); |
| 69 | + } |
| 70 | + }; |
| 71 | +} |
0 commit comments