<commit_before>require('spec/setup/defines')
require('stdlib/utils/string')
require('stdlib/utils/table')

local Event

-- faketorio event registry placed here
local factorio_event_registry

-- fire faketorio event into registered listeners if any
local function fire(e)
    if not e then e = {} end
    if not e.name then e.name = 0 end
    if factorio_event_registry[e.name] then
        return factorio_event_registry[e.name](e)
    end
end

describe("Event",
    function()

        setup(
            function()
                _G.table.size = table.size
            end
        )

        before_each(
            function()
                factorio_event_registry = {}
                Event = require('stdlib/event/event')
                _G.script = {
                    on_event = function(i, f) factorio_event_registry[i] = f end,
                    on_init = function(f) _G.on_event(_G.script.on_event(Event.core_events.init, f)) end,<commit_msg>event_spec: add genstubs convenience function<commit_after>require('spec/setup/defines')
require('stdlib/utils/string')
require('stdlib/utils/table')

local Event

-- faketorio event registry placed here
local factorio_event_registry

-- fire faketorio event into registered listeners if any
local function fire(e)
    if not e then e = {} end
    if not e.name then e.name = 0 end
    if factorio_event_registry[e.name] then
        return factorio_event_registry[e.name](e)
    end
end

-- convenience function to generate a pile of unique stubs, i.e.:
-- a,b,c = genstubs(3)
-- a('foo')
-- assert.stub(a).was.called_with('foo')
-- assert.stub(b).was.not.called()
local function genstubs(count)
    count = not count and 1 or count
    local tmocks = {}
    while count > 0 do
        table.insert(tmocks, function() end)
        count = count - 1
    end
    return table.unpack(mock(tmocks, true))
end

describe("Event",
    function()

        setup(
            function()
                _G.table.size = table.size
            end
        )

        before_each(
            function()
                factorio_event_registry = {}
                Event = require('stdlib/event/event')
                _G.script = {
                    on_event = function(i, f) factorio_event_registry[i] = f end,
                    on_init = function(f) _G.on_event(_G.script.on_event(Event.core_events.init, f)) end,
{'fraction_non_alphanumeric': 0.10472972972972973, 'fraction_numerical': 0.002533783783783784, 'mean_word_length': 2.263085399449036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6312392', 'n_tokens_mistral': 734, 'n_tokens_neox': 707, 'n_words': 179}