<commit_before>package mockatoo.macro;

#if macro

import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;

using tink.macro.tools.Printer;
using tink.macro.tools.ExprTools;

/**
Macro for remapping a mock's method invocation when using Mockatoo.when()
*/
class WhenMacro
{
	public static function create(expr:Expr):Expr
	{
		var str = expr.print();
		trace(str);
		trace(expr);

		//converts instance.one(1)
		//into instance.mockProxy.when("one", [1])

		switch(expr.expr)
		{
			case ECall(e, params):

				var ident = e.toString();

				var parts = ident.split(".");
				var methodName = EConst(CString(parts.pop())).at();

				var args = params.toArray();

				ident = parts.join(".") + ".mockProxy.stub";

				var actualExpr = ident.resolve().call([methodName, args]);
				trace(actualExpr.toString());
				return actualExpr;

			default: throw "Invalid arg [" + expr.print() + "]";
		}
		return expr;
	}
}

#end<commit_msg>Fixed issue with when() not casting object to Mock<commit_after>package mockatoo.macro;

#if macro

import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;

using tink.macro.tools.Printer;
using tink.macro.tools.ExprTools;
using tink.macro.tools.TypeTools;

/**
Macro for remapping a mock's method invocation when using Mockatoo.when()
*/
class WhenMacro
{
	public static function create(expr:Expr):Expr
	{
		var str = expr.print();
		trace(str);
		trace(expr);

		//converts instance.one(1)
		//into instance.mockProxy.when("one", [1])

		switch(expr.expr)
		{
			case ECall(e, params):

				var ident = e.toString();

				var parts = ident.split(".");
				var methodName = EConst(CString(parts.pop())).at();

				var args = params.toArray();

				ident = parts.join(".");

				var eCast = ECast(ident.resolve(), "mockatoo.Mock".asComplexType()).at();

				var eMethod = eCast.field("mockProxy").field("stub");

				var actualExpr = eMethod.call([methodName, args]);
				trace(actualExpr.toString());
				return actualExpr;

			default: throw "Invalid arg [" + expr.print() + "]";
		}
		return expr;
	}
}

#end
{'fraction_non_alphanumeric': 0.1578454332552693, 'fraction_numerical': 0.001873536299765808, 'mean_word_length': 3.7466666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7636584', 'n_tokens_mistral': 839, 'n_tokens_neox': 715, 'n_words': 167}