@micro-os-plus/micro-test-plus 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +303 -1
- package/CMakeLists.txt +9 -11
- package/README.md +12 -1226
- package/include/micro-os-plus/detail.h +54 -36
- package/include/micro-os-plus/inlines.h +46 -7
- package/include/micro-os-plus/literals.h +154 -25
- package/include/micro-os-plus/micro-test-plus.h +253 -67
- package/include/micro-os-plus/reflection.h +9 -5
- package/include/micro-os-plus/test-reporter-inlines.h +2 -2
- package/include/micro-os-plus/test-reporter.h +11 -4
- package/include/micro-os-plus/test-runner.h +2 -2
- package/include/micro-os-plus/test-suite.h +70 -6
- package/include/micro-os-plus/type-traits.h +22 -10
- package/meson.build +23 -17
- package/package.json +25 -535
- package/src/micro-test-plus.cpp +43 -0
- package/src/test-reporter.cpp +11 -1
- package/src/test-runner.cpp +11 -4
|
@@ -41,7 +41,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
41
41
|
// --------------------------------------------------------------------------
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* @brief
|
|
44
|
+
* @brief Namespace with implementation details, not part of the public API.
|
|
45
45
|
*/
|
|
46
46
|
namespace detail
|
|
47
47
|
{
|
|
@@ -87,7 +87,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
87
87
|
[[nodiscard]] constexpr auto
|
|
88
88
|
get (const T& t)
|
|
89
89
|
{
|
|
90
|
-
// Call the variadic function,
|
|
90
|
+
// Call the variadic function, basically to force it return `t`.
|
|
91
91
|
return get_impl (t, 0);
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -117,16 +117,15 @@ namespace micro_os_plus::micro_test_plus
|
|
|
117
117
|
#pragma clang diagnostic ignored "-Wpedantic"
|
|
118
118
|
#endif
|
|
119
119
|
#endif
|
|
120
|
-
if constexpr (type_traits::has_value_v<
|
|
121
|
-
|
|
120
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
121
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
122
122
|
{
|
|
123
123
|
// If both types have values (like numeric constants),
|
|
124
124
|
// compare them directly.
|
|
125
125
|
return Lhs_T::value == Rhs_T::value;
|
|
126
126
|
}
|
|
127
|
-
else if constexpr (
|
|
128
|
-
|
|
129
|
-
Lhs_T> and type_traits::has_epsilon_v<Rhs_T>)
|
|
127
|
+
else if constexpr (type_traits::has_epsilon_v<Lhs_T>
|
|
128
|
+
and type_traits::has_epsilon_v<Rhs_T>)
|
|
130
129
|
{
|
|
131
130
|
// If both values have precision, compare them using
|
|
132
131
|
// the smalles precision.
|
|
@@ -156,7 +155,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
156
155
|
{
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
[[nodiscard]] constexpr
|
|
158
|
+
[[nodiscard]] constexpr
|
|
159
|
+
operator bool () const
|
|
160
160
|
{
|
|
161
161
|
return value_;
|
|
162
162
|
}
|
|
@@ -201,14 +201,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
201
201
|
#pragma clang diagnostic ignored "-Wpedantic"
|
|
202
202
|
#endif
|
|
203
203
|
#endif
|
|
204
|
-
if constexpr (type_traits::has_value_v<
|
|
205
|
-
|
|
204
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
205
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
206
206
|
{
|
|
207
207
|
return Lhs_T::value != Rhs_T::value;
|
|
208
208
|
}
|
|
209
|
-
else if constexpr (
|
|
210
|
-
|
|
211
|
-
Lhs_T> and type_traits::has_epsilon_v<Rhs_T>)
|
|
209
|
+
else if constexpr (type_traits::has_epsilon_v<Lhs_T>
|
|
210
|
+
and type_traits::has_epsilon_v<Rhs_T>)
|
|
212
211
|
{
|
|
213
212
|
return math::abs (get (lhs_) - get (rhs_))
|
|
214
213
|
> math::min_value (Lhs_T::epsilon, Rhs_T::epsilon);
|
|
@@ -232,7 +231,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
232
231
|
{
|
|
233
232
|
}
|
|
234
233
|
|
|
235
|
-
[[nodiscard]] constexpr
|
|
234
|
+
[[nodiscard]] constexpr
|
|
235
|
+
operator bool () const
|
|
236
236
|
{
|
|
237
237
|
return value_;
|
|
238
238
|
}
|
|
@@ -272,8 +272,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
272
272
|
#pragma clang diagnostic ignored "-Wpedantic"
|
|
273
273
|
#endif
|
|
274
274
|
#endif
|
|
275
|
-
if constexpr (type_traits::has_value_v<
|
|
276
|
-
|
|
275
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
276
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
277
277
|
{
|
|
278
278
|
return Lhs_T::value > Rhs_T::value;
|
|
279
279
|
}
|
|
@@ -288,7 +288,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
288
288
|
{
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
[[nodiscard]] constexpr
|
|
291
|
+
[[nodiscard]] constexpr
|
|
292
|
+
operator bool () const
|
|
292
293
|
{
|
|
293
294
|
return value_;
|
|
294
295
|
}
|
|
@@ -328,8 +329,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
328
329
|
#pragma clang diagnostic ignored "-Wpedantic"
|
|
329
330
|
#endif
|
|
330
331
|
#endif
|
|
331
|
-
if constexpr (type_traits::has_value_v<
|
|
332
|
-
|
|
332
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
333
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
333
334
|
{
|
|
334
335
|
return Lhs_T::value >= Rhs_T::value;
|
|
335
336
|
}
|
|
@@ -344,7 +345,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
344
345
|
{
|
|
345
346
|
}
|
|
346
347
|
|
|
347
|
-
[[nodiscard]] constexpr
|
|
348
|
+
[[nodiscard]] constexpr
|
|
349
|
+
operator bool () const
|
|
348
350
|
{
|
|
349
351
|
return value_;
|
|
350
352
|
}
|
|
@@ -384,8 +386,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
384
386
|
#pragma clang diagnostic ignored "-Wpedantic"
|
|
385
387
|
#endif
|
|
386
388
|
#endif
|
|
387
|
-
if constexpr (type_traits::has_value_v<
|
|
388
|
-
|
|
389
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
390
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
389
391
|
{
|
|
390
392
|
return Lhs_T::value < Rhs_T::value;
|
|
391
393
|
}
|
|
@@ -400,7 +402,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
400
402
|
{
|
|
401
403
|
}
|
|
402
404
|
|
|
403
|
-
[[nodiscard]] constexpr
|
|
405
|
+
[[nodiscard]] constexpr
|
|
406
|
+
operator bool () const
|
|
404
407
|
{
|
|
405
408
|
return value_;
|
|
406
409
|
}
|
|
@@ -441,8 +444,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
441
444
|
#pragma clang diagnostic ignored "-Wpedantic"
|
|
442
445
|
#endif
|
|
443
446
|
#endif
|
|
444
|
-
if constexpr (type_traits::has_value_v<
|
|
445
|
-
|
|
447
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
448
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
446
449
|
{
|
|
447
450
|
return Lhs_T::value <= Rhs_T::value;
|
|
448
451
|
}
|
|
@@ -457,7 +460,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
457
460
|
{
|
|
458
461
|
}
|
|
459
462
|
|
|
460
|
-
[[nodiscard]] constexpr
|
|
463
|
+
[[nodiscard]] constexpr
|
|
464
|
+
operator bool () const
|
|
461
465
|
{
|
|
462
466
|
return value_;
|
|
463
467
|
}
|
|
@@ -486,12 +490,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
486
490
|
struct and_ : type_traits::op
|
|
487
491
|
{
|
|
488
492
|
constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
489
|
-
: lhs_{ lhs }, rhs_{ rhs },
|
|
490
|
-
|
|
493
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
494
|
+
value_{ static_cast<bool> (lhs) and static_cast<bool> (rhs) }
|
|
491
495
|
{
|
|
492
496
|
}
|
|
493
497
|
|
|
494
|
-
[[nodiscard]] constexpr
|
|
498
|
+
[[nodiscard]] constexpr
|
|
499
|
+
operator bool () const
|
|
495
500
|
{
|
|
496
501
|
return value_;
|
|
497
502
|
}
|
|
@@ -520,12 +525,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
520
525
|
struct or_ : type_traits::op
|
|
521
526
|
{
|
|
522
527
|
constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
523
|
-
: lhs_{ lhs }, rhs_{ rhs },
|
|
524
|
-
|
|
528
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
529
|
+
value_{ static_cast<bool> (lhs) or static_cast<bool> (rhs) }
|
|
525
530
|
{
|
|
526
531
|
}
|
|
527
532
|
|
|
528
|
-
[[nodiscard]] constexpr
|
|
533
|
+
[[nodiscard]] constexpr
|
|
534
|
+
operator bool () const
|
|
529
535
|
{
|
|
530
536
|
return value_;
|
|
531
537
|
}
|
|
@@ -558,7 +564,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
558
564
|
{
|
|
559
565
|
}
|
|
560
566
|
|
|
561
|
-
[[nodiscard]] constexpr
|
|
567
|
+
[[nodiscard]] constexpr
|
|
568
|
+
operator bool () const
|
|
562
569
|
{
|
|
563
570
|
return value_;
|
|
564
571
|
}
|
|
@@ -599,7 +606,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
599
606
|
{
|
|
600
607
|
}
|
|
601
608
|
|
|
602
|
-
[[nodiscard]] constexpr
|
|
609
|
+
[[nodiscard]] constexpr
|
|
610
|
+
operator bool () const
|
|
603
611
|
{
|
|
604
612
|
return value_;
|
|
605
613
|
}
|
|
@@ -628,7 +636,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
628
636
|
{
|
|
629
637
|
}
|
|
630
638
|
|
|
631
|
-
[[nodiscard]] constexpr
|
|
639
|
+
[[nodiscard]] constexpr
|
|
640
|
+
operator bool () const
|
|
632
641
|
{
|
|
633
642
|
return value_;
|
|
634
643
|
}
|
|
@@ -657,7 +666,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
657
666
|
{
|
|
658
667
|
}
|
|
659
668
|
|
|
660
|
-
[[nodiscard]] constexpr
|
|
669
|
+
[[nodiscard]] constexpr
|
|
670
|
+
operator bool () const
|
|
661
671
|
{
|
|
662
672
|
return value_;
|
|
663
673
|
}
|
|
@@ -668,6 +678,10 @@ namespace micro_os_plus::micro_test_plus
|
|
|
668
678
|
|
|
669
679
|
// ------------------------------------------------------------------------
|
|
670
680
|
|
|
681
|
+
/**
|
|
682
|
+
* @brief Base class for a deferred reporter, that collects the
|
|
683
|
+
* messages into a string.
|
|
684
|
+
*/
|
|
671
685
|
class deferred_reporter_base
|
|
672
686
|
{
|
|
673
687
|
public:
|
|
@@ -698,6 +712,10 @@ namespace micro_os_plus::micro_test_plus
|
|
|
698
712
|
std::string message_{};
|
|
699
713
|
};
|
|
700
714
|
|
|
715
|
+
/**
|
|
716
|
+
* @brief Class template for a deferred reporter specific
|
|
717
|
+
* to an expression.
|
|
718
|
+
*/
|
|
701
719
|
template <class Expr_T>
|
|
702
720
|
class deferred_reporter : public deferred_reporter_base
|
|
703
721
|
{
|
|
@@ -40,8 +40,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
40
40
|
template <typename Callable_T, typename... Args_T>
|
|
41
41
|
test_suite::test_suite (const char* name, Callable_T&& callable,
|
|
42
42
|
Args_T&&... arguments)
|
|
43
|
-
: test_suite_base{ name },
|
|
44
|
-
|
|
43
|
+
: test_suite_base{ name },
|
|
44
|
+
callable_{ std::bind (callable, arguments...) }
|
|
45
45
|
{
|
|
46
46
|
#if defined(MICRO_TEST_PLUS_TRACE)
|
|
47
47
|
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
@@ -52,16 +52,44 @@ namespace micro_os_plus::micro_test_plus
|
|
|
52
52
|
|
|
53
53
|
// --------------------------------------------------------------------------
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @details
|
|
57
|
+
* A test case is a sequence of test conditions (or simply tests,
|
|
58
|
+
* or checks), which are expectations/assumptions, i.e. conditions
|
|
59
|
+
* expected to be true.
|
|
60
|
+
*
|
|
61
|
+
* Tests are based on logical expressions, which usually compute
|
|
62
|
+
* a result and compare it to an expected value.
|
|
63
|
+
* For C++ projects, it is also possible to check if, while
|
|
64
|
+
* evaluating an expression, exceptions are thrown or not.
|
|
65
|
+
* Each test either succeeds or fails.
|
|
66
|
+
* For expectations, the runner keeps counts of successful
|
|
67
|
+
* and failed tests.
|
|
68
|
+
*
|
|
69
|
+
* A test case has a name, a function which performs the checks, and
|
|
70
|
+
* possibly arguments.
|
|
71
|
+
*
|
|
72
|
+
* The `test_case` implementation invokes the function with
|
|
73
|
+
* the provided arguments, and reports the results.
|
|
74
|
+
*
|
|
75
|
+
* @par Example
|
|
76
|
+
*
|
|
77
|
+
* ```cpp
|
|
78
|
+
* test_case ("Check answer with comparator", [] {
|
|
79
|
+
* expect (eq (compute_answer (), 42)) << "answer is 42";
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
55
83
|
template <typename Callable_T, typename... Args_T>
|
|
56
84
|
void
|
|
57
|
-
test_case (const char* name, Callable_T&&
|
|
85
|
+
test_case (const char* name, Callable_T&& callable, Args_T&&... arguments)
|
|
58
86
|
{
|
|
59
87
|
#if 0 // defined(MICRO_TEST_PLUS_TRACE)
|
|
60
88
|
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
61
89
|
#endif // MICRO_TEST_PLUS_TRACE
|
|
62
90
|
|
|
63
91
|
current_test_suite->begin_test_case (name);
|
|
64
|
-
std::invoke (std::forward<Callable_T> (
|
|
92
|
+
std::invoke (std::forward<Callable_T> (callable),
|
|
65
93
|
std::forward<Args_T> (arguments)...);
|
|
66
94
|
current_test_suite->end_test_case ();
|
|
67
95
|
}
|
|
@@ -92,9 +120,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
92
120
|
constexpr deferred_reporter<Expr_T>::deferred_reporter (
|
|
93
121
|
const Expr_T& expr, bool abort,
|
|
94
122
|
const reflection::source_location& location)
|
|
95
|
-
: deferred_reporter_base{ static_cast<bool> (expr), location },
|
|
96
|
-
|
|
97
|
-
}
|
|
123
|
+
: deferred_reporter_base{ static_cast<bool> (expr), location },
|
|
124
|
+
expr_{ expr }
|
|
98
125
|
{
|
|
99
126
|
#if 0 // defined(MICRO_TEST_PLUS_TRACE)
|
|
100
127
|
printf ("%s\n", __PRETTY_FUNCTION__);
|
|
@@ -121,6 +148,18 @@ namespace micro_os_plus::micro_test_plus
|
|
|
121
148
|
// --------------------------------------------------------------------------
|
|
122
149
|
namespace utility
|
|
123
150
|
{
|
|
151
|
+
/**
|
|
152
|
+
* @details
|
|
153
|
+
* For tests handling strings, this function template allows
|
|
154
|
+
* to split a string into a vector of substrings, using a delimiter.
|
|
155
|
+
*
|
|
156
|
+
* @par Example
|
|
157
|
+
* ```cpp
|
|
158
|
+
* expect (std::vector<std::string_view>{ "a", "b" }
|
|
159
|
+
* == utility::split<std::string_view> ("a.b", "."))
|
|
160
|
+
* << "a.b splits into [a,b]";
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
124
163
|
template <class T = std::string_view, class Delim_T>
|
|
125
164
|
[[nodiscard]] auto
|
|
126
165
|
split (T input, Delim_T delim) -> std::vector<T>
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
#include "type-traits.h"
|
|
27
27
|
#include "math.h"
|
|
28
|
+
#include <cstdint>
|
|
28
29
|
|
|
29
30
|
// ----------------------------------------------------------------------------
|
|
30
31
|
|
|
@@ -47,135 +48,235 @@ namespace micro_os_plus::micro_test_plus
|
|
|
47
48
|
*/
|
|
48
49
|
namespace literals
|
|
49
50
|
{
|
|
51
|
+
/**
|
|
52
|
+
* @ingroup micro-test-plus-literals
|
|
53
|
+
* @brief Operator to convert to `int`.
|
|
54
|
+
*/
|
|
50
55
|
template <char... Cs>
|
|
51
|
-
[[nodiscard]] constexpr auto
|
|
56
|
+
[[nodiscard]] constexpr auto
|
|
57
|
+
operator""_i ()
|
|
52
58
|
{
|
|
53
59
|
return type_traits::integral_constant<math::num<int, Cs...> ()>{};
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @ingroup micro-test-plus-literals
|
|
64
|
+
* @brief Operator to convert to `short`.
|
|
65
|
+
*/
|
|
56
66
|
template <char... Cs>
|
|
57
|
-
[[nodiscard]] constexpr auto
|
|
67
|
+
[[nodiscard]] constexpr auto
|
|
68
|
+
operator""_s ()
|
|
58
69
|
{
|
|
59
70
|
return type_traits::integral_constant<math::num<short, Cs...> ()>{};
|
|
60
71
|
}
|
|
61
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @ingroup micro-test-plus-literals
|
|
75
|
+
* @brief Operator to convert to `char`.
|
|
76
|
+
*/
|
|
62
77
|
template <char... Cs>
|
|
63
|
-
[[nodiscard]] constexpr auto
|
|
78
|
+
[[nodiscard]] constexpr auto
|
|
79
|
+
operator""_c ()
|
|
64
80
|
{
|
|
65
81
|
return type_traits::integral_constant<math::num<char, Cs...> ()>{};
|
|
66
82
|
}
|
|
67
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @ingroup micro-test-plus-literals
|
|
86
|
+
* @brief Operator to convert to `signed char`.
|
|
87
|
+
*/
|
|
68
88
|
template <char... Cs>
|
|
69
|
-
[[nodiscard]] constexpr auto
|
|
89
|
+
[[nodiscard]] constexpr auto
|
|
90
|
+
operator""_sc ()
|
|
70
91
|
{
|
|
71
92
|
return type_traits::integral_constant<
|
|
72
93
|
math::num<signed char, Cs...> ()>{};
|
|
73
94
|
}
|
|
74
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @ingroup micro-test-plus-literals
|
|
98
|
+
* @brief Operator to convert to `long`.
|
|
99
|
+
*/
|
|
75
100
|
template <char... Cs>
|
|
76
|
-
[[nodiscard]] constexpr auto
|
|
101
|
+
[[nodiscard]] constexpr auto
|
|
102
|
+
operator""_l ()
|
|
77
103
|
{
|
|
78
104
|
return type_traits::integral_constant<math::num<long, Cs...> ()>{};
|
|
79
105
|
}
|
|
80
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @ingroup micro-test-plus-literals
|
|
109
|
+
* @brief Operator to convert to `long long`.
|
|
110
|
+
*/
|
|
81
111
|
template <char... Cs>
|
|
82
|
-
[[nodiscard]] constexpr auto
|
|
112
|
+
[[nodiscard]] constexpr auto
|
|
113
|
+
operator""_ll ()
|
|
83
114
|
{
|
|
84
115
|
return type_traits::integral_constant<math::num<long long, Cs...> ()>{};
|
|
85
116
|
}
|
|
86
117
|
|
|
118
|
+
/**
|
|
119
|
+
* @ingroup micro-test-plus-literals
|
|
120
|
+
* @brief Operator to convert to `unsigned`.
|
|
121
|
+
*/
|
|
87
122
|
template <char... Cs>
|
|
88
|
-
[[nodiscard]] constexpr auto
|
|
123
|
+
[[nodiscard]] constexpr auto
|
|
124
|
+
operator""_u ()
|
|
89
125
|
{
|
|
90
126
|
return type_traits::integral_constant<math::num<unsigned, Cs...> ()>{};
|
|
91
127
|
}
|
|
92
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @ingroup micro-test-plus-literals
|
|
131
|
+
* @brief Operator to convert to `unsigned char`.
|
|
132
|
+
*/
|
|
93
133
|
template <char... Cs>
|
|
94
|
-
[[nodiscard]] constexpr auto
|
|
134
|
+
[[nodiscard]] constexpr auto
|
|
135
|
+
operator""_uc ()
|
|
95
136
|
{
|
|
96
137
|
return type_traits::integral_constant<
|
|
97
138
|
math::num<unsigned char, Cs...> ()>{};
|
|
98
139
|
}
|
|
99
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @ingroup micro-test-plus-literals
|
|
143
|
+
* @brief Operator to convert to `unsigned short`.
|
|
144
|
+
*/
|
|
100
145
|
template <char... Cs>
|
|
101
|
-
[[nodiscard]] constexpr auto
|
|
146
|
+
[[nodiscard]] constexpr auto
|
|
147
|
+
operator""_us ()
|
|
102
148
|
{
|
|
103
149
|
return type_traits::integral_constant<
|
|
104
150
|
math::num<unsigned short, Cs...> ()>{};
|
|
105
151
|
}
|
|
106
152
|
|
|
153
|
+
/**
|
|
154
|
+
* @ingroup micro-test-plus-literals
|
|
155
|
+
* @brief Operator to convert to `unsigned long`.
|
|
156
|
+
*/
|
|
107
157
|
template <char... Cs>
|
|
108
|
-
[[nodiscard]] constexpr auto
|
|
158
|
+
[[nodiscard]] constexpr auto
|
|
159
|
+
operator""_ul ()
|
|
109
160
|
{
|
|
110
161
|
return type_traits::integral_constant<
|
|
111
162
|
math::num<unsigned long, Cs...> ()>{};
|
|
112
163
|
}
|
|
113
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @ingroup micro-test-plus-literals
|
|
167
|
+
* @brief Operator to convert to `unsigned long long`.
|
|
168
|
+
*/
|
|
114
169
|
template <char... Cs>
|
|
115
|
-
[[nodiscard]] constexpr auto
|
|
170
|
+
[[nodiscard]] constexpr auto
|
|
171
|
+
operator""_ull ()
|
|
116
172
|
{
|
|
117
173
|
return type_traits::integral_constant<
|
|
118
174
|
math::num<unsigned long long, Cs...> ()>{};
|
|
119
175
|
}
|
|
120
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @ingroup micro-test-plus-literals
|
|
179
|
+
* @brief Operator to convert to `int8_t`.
|
|
180
|
+
*/
|
|
121
181
|
template <char... Cs>
|
|
122
|
-
[[nodiscard]] constexpr auto
|
|
182
|
+
[[nodiscard]] constexpr auto
|
|
183
|
+
operator""_i8 ()
|
|
123
184
|
{
|
|
124
185
|
return type_traits::integral_constant<
|
|
125
186
|
math::num<std::int8_t, Cs...> ()>{};
|
|
126
187
|
}
|
|
127
188
|
|
|
189
|
+
/**
|
|
190
|
+
* @ingroup micro-test-plus-literals
|
|
191
|
+
* @brief Operator to convert to `int16_t`.
|
|
192
|
+
*/
|
|
128
193
|
template <char... Cs>
|
|
129
|
-
[[nodiscard]] constexpr auto
|
|
194
|
+
[[nodiscard]] constexpr auto
|
|
195
|
+
operator""_i16 ()
|
|
130
196
|
{
|
|
131
197
|
return type_traits::integral_constant<
|
|
132
198
|
math::num<std::int16_t, Cs...> ()>{};
|
|
133
199
|
}
|
|
134
200
|
|
|
201
|
+
/**
|
|
202
|
+
* @ingroup micro-test-plus-literals
|
|
203
|
+
* @brief Operator to convert to `int32_t`.
|
|
204
|
+
*/
|
|
135
205
|
template <char... Cs>
|
|
136
|
-
[[nodiscard]] constexpr auto
|
|
206
|
+
[[nodiscard]] constexpr auto
|
|
207
|
+
operator""_i32 ()
|
|
137
208
|
{
|
|
138
209
|
return type_traits::integral_constant<
|
|
139
210
|
math::num<std::int32_t, Cs...> ()>{};
|
|
140
211
|
}
|
|
141
212
|
|
|
213
|
+
/**
|
|
214
|
+
* @ingroup micro-test-plus-literals
|
|
215
|
+
* @brief Operator to convert to `int64_t`.
|
|
216
|
+
*/
|
|
142
217
|
template <char... Cs>
|
|
143
|
-
[[nodiscard]] constexpr auto
|
|
218
|
+
[[nodiscard]] constexpr auto
|
|
219
|
+
operator""_i64 ()
|
|
144
220
|
{
|
|
145
221
|
return type_traits::integral_constant<
|
|
146
222
|
math::num<std::int64_t, Cs...> ()>{};
|
|
147
223
|
}
|
|
148
224
|
|
|
225
|
+
/**
|
|
226
|
+
* @ingroup micro-test-plus-literals
|
|
227
|
+
* @brief Operator to convert to `uint8_t`.
|
|
228
|
+
*/
|
|
149
229
|
template <char... Cs>
|
|
150
|
-
[[nodiscard]] constexpr auto
|
|
230
|
+
[[nodiscard]] constexpr auto
|
|
231
|
+
operator""_u8 ()
|
|
151
232
|
{
|
|
152
233
|
return type_traits::integral_constant<
|
|
153
234
|
math::num<std::uint8_t, Cs...> ()>{};
|
|
154
235
|
}
|
|
155
236
|
|
|
237
|
+
/**
|
|
238
|
+
* @ingroup micro-test-plus-literals
|
|
239
|
+
* @brief Operator to convert to `uint16_t`.
|
|
240
|
+
*/
|
|
156
241
|
template <char... Cs>
|
|
157
|
-
[[nodiscard]] constexpr auto
|
|
242
|
+
[[nodiscard]] constexpr auto
|
|
243
|
+
operator""_u16 ()
|
|
158
244
|
{
|
|
159
245
|
return type_traits::integral_constant<
|
|
160
246
|
math::num<std::uint16_t, Cs...> ()>{};
|
|
161
247
|
}
|
|
162
248
|
|
|
249
|
+
/**
|
|
250
|
+
* @ingroup micro-test-plus-literals
|
|
251
|
+
* @brief Operator to convert to `uint32_t`.
|
|
252
|
+
*/
|
|
163
253
|
template <char... Cs>
|
|
164
|
-
[[nodiscard]] constexpr auto
|
|
254
|
+
[[nodiscard]] constexpr auto
|
|
255
|
+
operator""_u32 ()
|
|
165
256
|
{
|
|
166
257
|
return type_traits::integral_constant<
|
|
167
258
|
math::num<std::uint32_t, Cs...> ()>{};
|
|
168
259
|
}
|
|
169
260
|
|
|
261
|
+
/**
|
|
262
|
+
* @ingroup micro-test-plus-literals
|
|
263
|
+
* @brief Operator to convert to `uint64_t`.
|
|
264
|
+
*/
|
|
170
265
|
template <char... Cs>
|
|
171
|
-
[[nodiscard]] constexpr auto
|
|
266
|
+
[[nodiscard]] constexpr auto
|
|
267
|
+
operator""_u64 ()
|
|
172
268
|
{
|
|
173
269
|
return type_traits::integral_constant<
|
|
174
270
|
math::num<std::uint64_t, Cs...> ()>{};
|
|
175
271
|
}
|
|
176
272
|
|
|
273
|
+
/**
|
|
274
|
+
* @ingroup micro-test-plus-literals
|
|
275
|
+
* @brief Operator to convert to `float`.
|
|
276
|
+
*/
|
|
177
277
|
template <char... Cs>
|
|
178
|
-
[[nodiscard]] constexpr auto
|
|
278
|
+
[[nodiscard]] constexpr auto
|
|
279
|
+
operator""_f ()
|
|
179
280
|
{
|
|
180
281
|
return type_traits::floating_point_constant<
|
|
181
282
|
float, math::num<unsigned long, Cs...> (),
|
|
@@ -183,8 +284,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
183
284
|
math::den_size<unsigned long, Cs...> ()>{};
|
|
184
285
|
}
|
|
185
286
|
|
|
287
|
+
/**
|
|
288
|
+
* @ingroup micro-test-plus-literals
|
|
289
|
+
* @brief Operator to convert to `double`.
|
|
290
|
+
*/
|
|
186
291
|
template <char... Cs>
|
|
187
|
-
[[nodiscard]] constexpr auto
|
|
292
|
+
[[nodiscard]] constexpr auto
|
|
293
|
+
operator""_d ()
|
|
188
294
|
{
|
|
189
295
|
return type_traits::floating_point_constant<
|
|
190
296
|
double, math::num<unsigned long, Cs...> (),
|
|
@@ -192,8 +298,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
192
298
|
math::den_size<unsigned long, Cs...> ()>{};
|
|
193
299
|
}
|
|
194
300
|
|
|
301
|
+
/**
|
|
302
|
+
* @ingroup micro-test-plus-literals
|
|
303
|
+
* @brief Operator to convert to `long double`.
|
|
304
|
+
*/
|
|
195
305
|
template <char... Cs>
|
|
196
|
-
[[nodiscard]] constexpr auto
|
|
306
|
+
[[nodiscard]] constexpr auto
|
|
307
|
+
operator""_ld ()
|
|
197
308
|
{
|
|
198
309
|
return type_traits::floating_point_constant<
|
|
199
310
|
long double, math::num<unsigned long long, Cs...> (),
|
|
@@ -201,12 +312,18 @@ namespace micro_os_plus::micro_test_plus
|
|
|
201
312
|
math::den_size<unsigned long long, Cs...> ()>{};
|
|
202
313
|
}
|
|
203
314
|
|
|
204
|
-
|
|
315
|
+
/**
|
|
316
|
+
* @ingroup micro-test-plus-literals
|
|
317
|
+
* @brief Operator to convert to `bool`.
|
|
318
|
+
*/
|
|
319
|
+
constexpr auto
|
|
320
|
+
operator""_b (const char* name, decltype (sizeof ("")) size)
|
|
205
321
|
{
|
|
206
322
|
struct named : std::string_view, type_traits::op
|
|
207
323
|
{
|
|
208
324
|
using value_type = bool;
|
|
209
|
-
[[nodiscard]] constexpr
|
|
325
|
+
[[nodiscard]] constexpr
|
|
326
|
+
operator value_type () const
|
|
210
327
|
{
|
|
211
328
|
return true;
|
|
212
329
|
}
|
|
@@ -230,6 +347,11 @@ namespace micro_os_plus::micro_test_plus
|
|
|
230
347
|
|
|
231
348
|
// --------------------------------------------------------------------------
|
|
232
349
|
|
|
350
|
+
/**
|
|
351
|
+
* @addtogroup micro-test-plus-literals
|
|
352
|
+
* @{
|
|
353
|
+
*/
|
|
354
|
+
|
|
233
355
|
// Wrappers that can be used to convert dynamic values to specific types
|
|
234
356
|
// that are recognised by the comparators.
|
|
235
357
|
// The syntax is similar to function calls, like `_i(expression)`, but the
|
|
@@ -258,7 +380,14 @@ namespace micro_os_plus::micro_test_plus
|
|
|
258
380
|
using _d = type_traits::value<double>;
|
|
259
381
|
using _ld = type_traits::value<long double>;
|
|
260
382
|
|
|
261
|
-
|
|
383
|
+
/**
|
|
384
|
+
* @}
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @ingroup micro-test-plus-literals
|
|
389
|
+
* @brief Template for wrapping any other type.
|
|
390
|
+
*/
|
|
262
391
|
template <class T>
|
|
263
392
|
struct _t : type_traits::value<T>
|
|
264
393
|
{
|