Skip to content

Commit

Permalink
Option: Test Coverage
Browse files Browse the repository at this point in the history
Add unit tests for `auxiliary::Option`
  • Loading branch information
ax3l committed Oct 28, 2020
1 parent a5ee790 commit c6d486f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/AuxiliaryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "openPMD/backend/Container.hpp"
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/auxiliary/Option.hpp"
#include "openPMD/auxiliary/StringManip.hpp"
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/IO/AbstractIOHandler.hpp"
Expand Down Expand Up @@ -43,6 +44,33 @@ struct TestHelper : public Attributable
} // openPMD


TEST_CASE( "optional", "[auxiliary]" ) {
using namespace auxiliary;

Option<int> opt;

REQUIRE_THROWS(opt.get());
REQUIRE_THROWS(opt.get() = 42);
REQUIRE(!opt);
REQUIRE(!opt.has_value());

opt = 43;
REQUIRE(opt);
REQUIRE(opt.has_value());
REQUIRE(opt.get() == 43);

Option<int> opt2{ opt };
REQUIRE(opt2);
REQUIRE(opt2.has_value());
REQUIRE(opt2.get() == 43);

Option<int> opt3 = makeOption( 3 );
REQUIRE(opt3);
REQUIRE(opt3.has_value());
REQUIRE(opt3.get() == 3);
}


TEST_CASE( "deref_cast_test", "[auxiliary]" ) {
using namespace auxiliary;

Expand Down

0 comments on commit c6d486f

Please sign in to comment.