File tree 2 files changed +30
-0
lines changed 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ SRC += analyses/ai/ai.cpp \
74
74
util/irep_sharing.cpp \
75
75
util/json_array.cpp \
76
76
util/json_object.cpp \
77
+ util/lazy.cpp \
77
78
util/memory_info.cpp \
78
79
util/message.cpp \
79
80
util/optional.cpp \
Original file line number Diff line number Diff line change
1
+ /* ******************************************************************\
2
+
3
+ Module: Unit tests for lazy
4
+
5
+ Author: Romain Brenguier, [email protected]
6
+
7
+ \*******************************************************************/
8
+
9
+ #include < testing-utils/use_catch.h>
10
+ #include < util/lazy.h>
11
+
12
+ SCENARIO (" lazy test" , " [core][util][lazy]" )
13
+ {
14
+ std::size_t call_counter = 0 ;
15
+ auto length_with_counter = [&call_counter](const std::string &s) {
16
+ ++call_counter;
17
+ return s.length ();
18
+ };
19
+ auto lazy_length =
20
+ lazyt<int >::from_fun ([&]() { return length_with_counter (" foo" ); });
21
+
22
+ REQUIRE (call_counter == 0 );
23
+ auto result = lazy_length.force ();
24
+ REQUIRE (call_counter == 1 );
25
+ REQUIRE (result == 3 );
26
+ result = lazy_length.force ();
27
+ REQUIRE (call_counter == 1 );
28
+ REQUIRE (result == 3 );
29
+ }
You can’t perform that action at this time.
0 commit comments