<commit_before>#include "stdafx.h"
#include "CppUnitTest.h"
#include "Mock.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace mock4cpp_tests
{
	TEST_CLASS(invocation_matching_tests)
	{
	public:
		
		struct SomeInterface
		{
			virtual int func1(int) = 0;
			virtual void proc1(int) = 0;

			virtual int func2(int&) = 0;
			virtual void proc2(int&) = 0;

			virtual int func3(const int) = 0;
			virtual void proc3(const int) = 0;

		};


		TEST_METHOD(MatchInvocation_primitive_parameter)
		{
			Mock<SomeInterface> mock;
			mock.When(&SomeInterface::func1).Matching([](int a){return a == 1; }).Return(2);
			mock.When(&SomeInterface::proc1).Matching([](int a){return a == 1; }).Throw(std::string("impl"));

			SomeInterface &i = mock.get();

			Assert::AreEqual(2, i.func1(1));
			Assert::ExpectException<std::string>([&i]{ i.proc1(1); });
		}

		TEST_METHOD(MatchInvocation_primitive_parameter_by_ref)
		{
			Mock<SomeInterface> mock;
			mock.When(&SomeInterface::func2).Matching([](int a){return a == 1; }).Return(2);
			mock.When(&SomeInterface::proc2).Matching([](int a){return a == 1; }).Throw(std::string("impl"));

			SomeInterface &i = mock.get();
			int one = 1;
			Assert::AreEqual(2, i.func2(one));
			Assert::ExpectException<std::string>([&one,&i]{ i.proc2(one); });
		}

		TEST_METHOD(MatchInvocation_const_primitive_parameter)
		{
			Mock<SomeInterface> mock;
			mock.When(&SomeInterface::func3).Matching([](int a){return a == 1; }).Return(2);
			mock.When(&SomeInterface::proc3).Matching([](int a){return a == 1; }).Throw(std::string("impl"));

			SomeInterface &i = mock.get();

			Assert::AreEqual(2, i.func3(1));
			Assert::ExpectException<std::string>([&i]{ i.proc3(1); });
		}

	};
}<commit_msg>add arg matching tests<commit_after>#include "stdafx.h"
#include "CppUnitTest.h"
#include <string>
#include "Mock.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace mock4cpp_tests
{
	TEST_CLASS(invocation_matching_tests)
	{
	public:
		
		struct SomeInterface
		{
			virtual int func1(int, std::string) = 0;
			virtual void proc1(int, std::string) = 0;

			virtual int func2(int&, std::string&) = 0;
			virtual void proc2(int&, std::string&) = 0;

			virtual int func3(const int, const std::string&) = 0;
			virtual void proc3(const int, const std::string&) = 0;

		};


		TEST_METHOD(MatchInvocation_ByValue)
		{
			Mock<SomeInterface> mock;
			mock.When(&SomeInterface::func1).Matching([](int a, std::string s){return a == 1; }).Return(2);
			mock.When(&SomeInterface::proc1).Matching([](int a, std::string s){return a == 1; }).Throw(std::string("impl"));

			SomeInterface &i = mock.get();

			Assert::AreEqual(2, i.func1(1,std::string("A")));
			Assert::ExpectException<std::string>([&]{ i.proc1(1, std::string("A")); });
		}

		TEST_METHOD(MatchInvocation_ByRef)
		{
			Mock<SomeInterface> mock;
			mock.When(&SomeInterface::func2).Matching([](int a, std::string s){return a == 1; }).Return(2);
			mock.When(&SomeInterface::proc2).Matching([](int a, std::string s){return a == 1; }).Throw(std::string("impl"));

			SomeInterface &i = mock.get();
			int one = 1;
			std::string s{""};
			Assert::AreEqual(2, i.func2(one,s));
			Assert::ExpectException<std::string>([&]{ i.proc2(one,s); });
		}

		TEST_METHOD(MatchInvocation_const_primitive_parameter)
		{
			Mock<SomeInterface> mock;
			mock.When(&SomeInterface::func3).Matching([](int a, const std::string &s){return a == 1; }).Return(2);
			mock.When(&SomeInterface::proc3).Matching([](int a, const std::string &s){return a == 1; }).Throw(std::string("impl"));

			// should also work
			mock.When(&SomeInterface::func3).Matching([](int a, std::string s){return a == 2; }).Return(2);
			mock.When(&SomeInterface::proc3).Matching([](int a, std::string s){return a == 2; }).Throw(std::string("impl"));

			SomeInterface &i = mock.get();
			std::string s{ "" };

			Assert::AreEqual(2, i.func3(1,s));
			Assert::ExpectException<std::string>([&]{ i.proc3(1,s); });

			Assert::AreEqual(2, i.func3(2, s));
			Assert::ExpectException<std::string>([&]{ i.proc3(2, s); });
		}

	};
}
{'fraction_non_alphanumeric': 0.20097560975609757, 'fraction_numerical': 0.022926829268292682, 'mean_word_length': 5.166917293233083, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4935179', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1447, 'n_words': 263}