<commit_before>package hunit.call;

import haxe.Constraints.Function;
import haxe.PosInfos;
import hunit.call.CallCount;
import hunit.call.Expect;
import hunit.call.IExpect;
import hunit.match.Match;
import hunit.mock.MockData;
import hunit.utils.Value;


using hunit.utils.Value;


/**
 * Expected method invocation
 *
 */
class Stub
{
    /** owner of this expectation */
    public var mockData (default,null) : MockData;
    /** method name */
    public var method (default,null) : String;
    /** expected arguments */
    public var arguments (default,null) : Array<Match<Dynamic>>;
    /** expected return value */
    public var returns (default,null) : Value<Dynamic>;
    /** expected exception */
    public var throws (default,null) : Value<Dynamic>;
    /** Custom implementation for stubbed mehtod. Value should be a callback */
    public var implementation : Value<Dynamic>;
    /** Where this stub was created */
    public var pos (default,null) : PosInfos;


    /**
     * Constructor
     *
     */
    public function new (mockData:MockData, method:String, arguments:Array<Match<Dynamic>>, returns:Value<Dynamic>, throws:Value<Dynamic>, ?pos:PosInfos) : Void
    {
        this.mockData  = mockData;
        this.method    = method;
        this.arguments = arguments;
        this.returns   = returns;
        this.throws    = throws;
        this.pos       = pos;
    }


    /**
     * Expect this stub to be invoked `count` times
     *
     */
    public function expect (count:CallCount, ?pos:PosInfos) : Expect
    {
        var expect = new Expect(
            mockData,
            method,
            arguments,
            Nothing,
            Nothing,
            count,
            pos
        );
        mockData.expect(expect);

        return expect;
    }


    /**
     * Check if `method` invoked with `arguments` this stub.
     *
     */
    public function match (method:String, arguments:Array<Dynamic>) : Bool
    {
        if (this.method != method) return false;

        if (arguments.length != this.arguments.length) {
            throw 'Arguments count does not match';
        }<commit_msg>better position reporting for failed expectations created from stubs<commit_after>package hunit.call;

import haxe.Constraints.Function;
import haxe.PosInfos;
import hunit.call.CallCount;
import hunit.call.Expect;
import hunit.call.IExpect;
import hunit.match.Match;
import hunit.mock.MockData;
import hunit.utils.Value;


using hunit.utils.Value;


/**
 * Expected method invocation
 *
 */
class Stub
{
    /** owner of this expectation */
    public var mockData (default,null) : MockData;
    /** method name */
    public var method (default,null) : String;
    /** expected arguments */
    public var arguments (default,null) : Array<Match<Dynamic>>;
    /** expected return value */
    public var returns (default,null) : Value<Dynamic>;
    /** expected exception */
    public var throws (default,null) : Value<Dynamic>;
    /** Custom implementation for stubbed mehtod. Value should be a callback */
    public var implementation : Value<Dynamic>;
    /** Where this stub was created */
    public var pos (default,null) : PosInfos;


    /**
     * Constructor
     *
     */
    public function new (mockData:MockData, method:String, arguments:Array<Match<Dynamic>>, returns:Value<Dynamic>, throws:Value<Dynamic>, ?pos:PosInfos) : Void
    {
        this.mockData  = mockData;
        this.method    = method;
        this.arguments = arguments;
        this.returns   = returns;
        this.throws    = throws;
        this.pos       = pos;
    }


    /**
     * Expect this stub to be invoked `count` times
     *
     */
    public function expect (count:CallCount) : Expect
    {
        var expect = new Expect(
            mockData,
            method,
            arguments,
            Nothing,
            Nothing,
            count,
            pos
        );
        mockData.expect(expect);

        return expect;
    }


    /**
     * Check if `method` invoked with `arguments` this stub.
     *
     */
    public function match (method:String, arguments:Array<Dynamic>) : Bool
    {
        if (this.method != method) return false;

        if (arguments.length != this.arguments.length) {
            throw 'Arguments count does not match';
        }
{'fraction_non_alphanumeric': 0.10980120203421175, 'fraction_numerical': 0.0, 'mean_word_length': 2.2980182926829267, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '4516818', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1179, 'n_words': 339}