<commit_before>local strung = require"strung"

--- First, the test and benchmark infrastructure.
--- `try` and `gmtry` run both the original and strung version of the functions, 
--- and compare either their ouput, or their speed if "bench" is passed as a 
--- parameter to the script.

local ttstr = require"util".val_to_string
local BASE = 10000
local iter, try, gmtry
if arg[1] == "bench" then 
    function try(f, a, s, d, g, h)
        -- jit.off() jit.on()
        tsi, tSo = 0, 0
        local params = {a, s, d, g, h}
        local ri, Ros
        print(("-_"):rep(30))
        print("Test: ", f, unpack(params))
        local tic = os.clock()
        for i = 1, II do
            ri = {string[f](a, s, d, g, h)}
        end
        tsi = os.clock() - tic
        local tic = os.clock()
        for i = 1, II do
            Ro = {strung[f](a, s, d, g, h)}
        end
        tSo = os.clock() - tic
        print("strung/string: ", tSo/tsi)
    end
    function gmtry(s, p)
        print(("-_"):rep(30))
        print("Test: ", "gmatch", s, p)
        local ri, ro = {}, {}
        local tic = os.clock()
        for i = 1, II do
            ro = {}
            for a, b, c, d, e, f in strung.gmatch(s, p) do
                ro[#ro + 1] = {a, b, c, d, e}
            end
        end
        local tsi = os.clock() - tic
        local tic = os.clock()
        for i = 1, II do
            ri = {}
            for a, b, c, d, e, f in string.gmatch(s, p) do
                ri[#ri + 1] = {a, b, c, d, e}
            end
        end
        local tSo = os.clock() - tic
        print("strung/string: ", tSo/tsi)
    end
    function iter(n) II = BASE * n end
else
    function try(f, ...)
        local params = {...}
        local ri, Ros
        print(("-_"):rep(30))
        print("Test: ", f, ...)
        ri = {string[f](...)}
        Ro = {strung[f](...)}
        for i, v in ipairs(params) do params[i] = tostring(v) end
        for i = 1, math.max(#ri, #Ro) do
            strung.assert(ri[i] == Ro[i], params[2], table.concat({ 
                table.concat(params, ", "), 
                "ri:", table.concat(ri, ",  "), 
                " \tRo:", table.concat(Ro, ", ")
            }, " | "))
        end
    end
    function gmtry(s, p)
        print(("-_"):rep(30))
        print("Test: ", "gmatch", s, p)
        local ri, ro = {}, {}
        for a, b, c, d, e, f in strung.gmatch(s, p) do
            ro[#ro + 1] = {a, b, c, d, e}
        end
        print"Now string"
        for a, b, c, d, e, f in string.gmatch(s, p) do
            ri[#ri + 1] = {a, b, c, d, e}
        end
        strung.assert(#ro == #ri, p, "string: \n"..ttstr(ri).."\n=/=/=/=/=/=/=/=/\nstrung:\n"..ttstr(ro))
        for i = 1, #ro do
        strung.assert(#ro[i] == #ri[i], p, "string: \n"..ttstr(ri).."\n=/=/=/=/=/=/=/=/\nstrung:\n"..ttstr(ro))
            for j = 1, #ri[i] do
                strung.assert(ri[i][j] == ro[i][j], p, "string: \n"..ttstr(ri).."\n=/=/=/=/=/=/=/=/\nstrung:\n"..ttstr(ro))
            end
        end
    end
    iter = function()end
end


--- The tests (in reverse order of complexity)

local _f, _m, _gm, _gs = string.find, string.match, string.gmatch, string.gsub

strung.install()
assert(<commit_msg>fix stray `print()` in the tests<commit_after>local strung = require"strung"

--- First, the test and benchmark infrastructure.
--- `try` and `gmtry` run both the original and strung version of the functions, 
--- and compare either their ouput, or their speed if "bench" is passed as a 
--- parameter to the script.

local ttstr = require"util".val_to_string
local BASE = 10000
local iter, try, gmtry
if arg[1] == "bench" then 
    function try(f, a, s, d, g, h)
        -- jit.off() jit.on()
        tsi, tSo = 0, 0
        local params = {a, s, d, g, h}
        local ri, Ros
        print(("-_"):rep(30))
        print("Test: ", f, unpack(params))
        local tic = os.clock()
        for i = 1, II do
            ri = {string[f](a, s, d, g, h)}
        end
        tsi = os.clock() - tic
        local tic = os.clock()
        for i = 1, II do
            Ro = {strung[f](a, s, d, g, h)}
        end
        tSo = os.clock() - tic
        print("strung/string: ", tSo/tsi)
    end
    function gmtry(s, p)
        print(("-_"):rep(30))
        print("Test: ", "gmatch", s, p)
        local ri, ro = {}, {}
        local tic = os.clock()
        for i = 1, II do
            ro = {}
            for a, b, c, d, e, f in strung.gmatch(s, p) do
                ro[#ro + 1] = {a, b, c, d, e}
            end
        end
        local tsi = os.clock() - tic
        local tic = os.clock()
        for i = 1, II do
            ri = {}
            for a, b, c, d, e, f in string.gmatch(s, p) do
                ri[#ri + 1] = {a, b, c, d, e}
            end
        end
        local tSo = os.clock() - tic
        print("strung/string: ", tSo/tsi)
    end
    function iter(n) II = BASE * n end
else
    function try(f, ...)
        local params = {...}
        local ri, Ros
        print(("-_"):rep(30))
        print("Test: ", f, ...)
        ri = {string[f](...)}
        Ro = {strung[f](...)}
        for i, v in ipairs(params) do params[i] = tostring(v) end
        for i = 1, math.max(#ri, #Ro) do
            strung.assert(ri[i] == Ro[i], params[2], table.concat({ 
                table.concat(params, ", "), 
                "ri:", table.concat(ri, ",  "), 
                " \tRo:", table.concat(Ro, ", ")
            }, " | "))
        end
    end
    function gmtry(s, p)
        print(("-_"):rep(30))
        print("Test: ", "gmatch", s, p)
        local ri, ro = {}, {}
        for a, b, c, d, e, f in strung.gmatch(s, p) do
            ro[#ro + 1] = {a, b, c, d, e}
        end
        for a, b, c, d, e, f in string.gmatch(s, p) do
            ri[#ri + 1] = {a, b, c, d, e}
        end
        strung.assert(#ro == #ri, p, "string: \n"..ttstr(ri).."\n=/=/=/=/=/=/=/=/\nstrung:\n"..ttstr(ro))
        for i = 1, #ro do
        strung.assert(#ro[i] == #ri[i], p, "string: \n"..ttstr(ri).."\n=/=/=/=/=/=/=/=/\nstrung:\n"..ttstr(ro))
            for j = 1, #ri[i] do
                strung.assert(ri[i][j] == ro[i][j], p, "string: \n"..ttstr(ri).."\n=/=/=/=/=/=/=/=/\nstrung:\n"..ttstr(ro))
            end
        end
    end
    iter = function()end
end


--- The tests (in reverse order of complexity)

local _f, _m, _gm, _gs = string.find, string.match, string.gmatch, string.gsub

strung.install()
assert(
{'fraction_non_alphanumeric': 0.1925282901875678, 'fraction_numerical': 0.008680824678344443, 'mean_word_length': 1.5643879173290938, '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': '6358923', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2385, 'n_words': 696}