diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/bitfield.cc | 4 | ||||
-rw-r--r-- | test/option.cc | 77 |
2 files changed, 40 insertions, 41 deletions
diff --git a/test/bitfield.cc b/test/bitfield.cc index 77bb286..0d4dcac 100644 --- a/test/bitfield.cc +++ b/test/bitfield.cc @@ -4,8 +4,8 @@ #include <cstdio> BITFIELD_START(MOOSE, std::uint32_t) - FIELD(IO, 4, 7) - FIELD(EL, 16, 31) +FIELD(IO, 4, 7) +FIELD(EL, 16, 31) BITFIELD_END() int main() { diff --git a/test/option.cc b/test/option.cc index 8697089..0417266 100644 --- a/test/option.cc +++ b/test/option.cc @@ -1,6 +1,6 @@ #include <option.h> -#include <cstdlib> #include <cstdio> +#include <cstdlib> struct Checker { static unsigned cnt; @@ -25,61 +25,60 @@ int main() { using option::option; auto check_cnt = [](unsigned expect) { - if (expect != Checker::cnt) { - std::printf("Checker: expect=%u cnt=%u\n", expect, Checker::cnt); - std::abort(); - } - + if (expect != Checker::cnt) { + std::printf("Checker: expect=%u cnt=%u\n", expect, Checker::cnt); + std::abort(); + } }; { - option<int> o1; - option<int> o2{::option::none{}}; + option<int> o1; + option<int> o2{::option::none{}}; - assert(!o1.has_value()); - assert(!o2.has_value()); + assert(!o1.has_value()); + assert(!o2.has_value()); } // Assume we start test with cnt=0. check_cnt(0); { - option<Checker> o1(Checker{}); - // copy construct - option<Checker> o2 = o1; - // move construct - option<Checker> o3 = o1.take(); - - assert(!o1.has_value()); - assert(o2.has_value()); - assert(o3.has_value()); - - // move option - option<Checker> o4 = std::move(o2); - - assert(!o2.has_value()); - assert(o4.has_value()); - - // take reference to inner - auto x = o3.value(); - // take ownership of inner - auto y = o4.take(); - - assert(!o1.has_value()); - assert(!o2.has_value()); - assert(o3.has_value()); - assert(!o4.has_value()); + option<Checker> o1(Checker{}); + // copy construct + option<Checker> o2 = o1; + // move construct + option<Checker> o3 = o1.take(); + + assert(!o1.has_value()); + assert(o2.has_value()); + assert(o3.has_value()); + + // move option + option<Checker> o4 = std::move(o2); + + assert(!o2.has_value()); + assert(o4.has_value()); + + // take reference to inner + auto x = o3.value(); + // take ownership of inner + auto y = o4.take(); + + assert(!o1.has_value()); + assert(!o2.has_value()); + assert(o3.has_value()); + assert(!o4.has_value()); } // Expect to finish test with cnt=0. check_cnt(0); { - option<Checker> o1; - assert(!o1.has_value()); + option<Checker> o1; + assert(!o1.has_value()); - o1.emplace(); - assert(o1.has_value()); + o1.emplace(); + assert(o1.has_value()); } // Expect to finish test with cnt=0. |