Skip to content

Commit 43d0602

Browse files
author
Lukasz A.J. Wrona
committed
Add unit tests for nonstd::optional
1 parent 8584bb0 commit 43d0602

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

unit/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ SRC = src/expr/require_expr.cpp \
55
src/ansi-c/c_to_expr.cpp \
66
unit_tests.cpp \
77
catch_example.cpp \
8+
util/expr_iterator.cpp \
9+
optional.cpp \
10+
analyses/call_graph.cpp \
11+
java_bytecode/java_bytecode_convert_class/convert_abstract_class.cpp \
812
# Empty last line
913

1014
# Test source files

unit/optional.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************\
2+
3+
Module: nonstd::optional unit tests
4+
5+
Author: Diffblue Limited. All rights reserved.
6+
7+
\*******************************************************************/
8+
9+
#include "catch.hpp"
10+
#include <util/optional.h>
11+
12+
TEST_CASE("Optional without a value", "[core][util][optional]")
13+
{
14+
optionalt<bool> maybe_value;
15+
REQUIRE(maybe_value.has_value()==false);
16+
REQUIRE_THROWS_AS(maybe_value.value(), bad_optional_accesst);
17+
}
18+
19+
TEST_CASE("Optional with a value", "[core][util][optional]")
20+
{
21+
optionalt<bool> maybe_value=false;
22+
REQUIRE(maybe_value.has_value());
23+
REQUIRE(maybe_value.value()==false);
24+
}
25+
26+
27+
TEST_CASE("Optional with a value (operator access)", "[core][util][optional]")
28+
{
29+
optionalt<bool> maybe_value=true;
30+
REQUIRE(maybe_value.has_value());
31+
REQUIRE(*maybe_value==true);
32+
}

0 commit comments

Comments
 (0)