65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
#include <Void/TestingMock/MockFunction.hpp>
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
Void::Testing::Test lt_le_gt_ge_match_appropriately()
|
|
{
|
|
using namespace Void::TestingMock;
|
|
MockFunction<int(int)> fn{"f"};
|
|
fn.expect(Lt(10)).returns(1).times(1);
|
|
fn.expect(Le(20)).returns(2).times(1);
|
|
fn.expect(Gt(30)).returns(3).times(1);
|
|
fn.expect(Ge(40)).returns(4).times(1);
|
|
|
|
Void::Testing::expect_eq(fn(5), 1);
|
|
Void::Testing::expect_eq(fn(15), 2);
|
|
Void::Testing::expect_eq(fn(35), 3);
|
|
Void::Testing::expect_eq(fn(40), 4);
|
|
}
|
|
|
|
Void::Testing::Test range_matches_inclusive_bounds()
|
|
{
|
|
using namespace Void::TestingMock;
|
|
MockFunction<int(int)> fn{"in_range"};
|
|
fn.expect(Range(10, 20)).returns(99).times(3);
|
|
|
|
Void::Testing::expect_eq(fn(10), 99); // lower bound
|
|
Void::Testing::expect_eq(fn(15), 99); // middle
|
|
Void::Testing::expect_eq(fn(20), 99); // upper bound
|
|
}
|
|
|
|
Void::Testing::Test pred_matcher_invokes_user_callable()
|
|
{
|
|
using namespace Void::TestingMock;
|
|
MockFunction<int(int)> fn{"is_even"};
|
|
fn.expect(Pred<int>([](const int& v) { return v % 2 == 0; }))
|
|
.returns(1)
|
|
.times(2);
|
|
|
|
Void::Testing::expect_eq(fn(4), 1);
|
|
Void::Testing::expect_eq(fn(8), 1);
|
|
}
|
|
|
|
Void::Testing::Test starts_with_matches_string_prefix()
|
|
{
|
|
using namespace Void::TestingMock;
|
|
MockFunction<int(std::string_view)> fn{"prefix"};
|
|
fn.expect(StartsWith<std::string_view>("hello")).returns(1).times(2);
|
|
|
|
Void::Testing::expect_eq(fn("hello world"), 1);
|
|
Void::Testing::expect_eq(fn("hello"), 1);
|
|
}
|
|
|
|
Void::Testing::Test contains_matches_substring()
|
|
{
|
|
using namespace Void::TestingMock;
|
|
MockFunction<int(std::string_view)> fn{"contains"};
|
|
fn.expect(Contains<std::string_view>("foo")).returns(1).times(2);
|
|
|
|
Void::Testing::expect_eq(fn("a foo b"), 1);
|
|
Void::Testing::expect_eq(fn("foobar"), 1);
|
|
}
|