local g=script.Parent.Parent.TestEZ local R=require(g.Expectation)return{["\105\116 \115\104\111\117\108\100 \115\117\099\099\101\101\100 \105\102 \097\110 \101\109\112\116\121 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \110\101\118\101\114 \116\104\114\111\119"]=function()local function g() end local c=R.new(g)local P=pcall(function()c.never:throw()end)assert(P,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end;["\105\116 \115\104\111\117\108\100 \115\117\099\099\101\101\100 \105\102 \097 \116\104\114\111\119\105\110\103 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \116\104\114\111\119"]=function()local function g()error("\111\111\102")end local c=R.new(g)local P=pcall(function()c:throw()end)assert(P,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end,["\105\116 \115\104\111\117\108\100 \102\097\105\108 \105\102 \097 \116\104\114\111\119\105\110\103 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \110\101\118\101\114 \116\104\114\111\119"]=function()local function g()error("\111\111\102")end local c=R.new(g)local P,D=pcall(function()c.never:throw()end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \102\117\110\099\116\105\111\110 \116\111 \115\117\099\099\101\101\100\044 \098\117\116 \105\116 \116\104\114\101\119 \097\110 \101\114\114\111\114\058"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end,["\105\116 \115\104\111\117\108\100 \102\097\105\108 \105\102 \097\110 \101\109\112\116\121 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \116\104\114\111\119"]=function()local function g() end local c=R.new(g)local P,D=pcall(function()c:throw()end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \102\117\110\099\116\105\111\110 \116\111 \116\104\114\111\119 \097\110 \101\114\114\111\114\044 \098\117\116 \105\116 \100\105\100 \110\111\116\046"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end;["\105\116 \115\104\111\117\108\100 \102\097\105\108 \105\102 \097\110 \101\109\112\116\121 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \116\104\114\111\119 \119\105\116\104 \097 \109\101\115\115\097\103\101"]=function()local function g() end local c=R.new(g)local P,D=pcall(function()c:throw("\102\111\111")end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \102\117\110\099\116\105\111\110 \116\111 \116\104\114\111\119 \097\110 \101\114\114\111\114 \099\111\110\116\097\105\110\105\110\103 \"\102\111\111\"\044 \098\117\116 \105\116 \100\105\100 \110\111\116\046"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end;["\105\116 \115\104\111\117\108\100 \102\097\105\108 \105\102 \097 \116\104\114\111\119\105\110\103 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \116\104\114\111\119 \119\105\116\104 \097 \100\105\102\102\101\114\101\110\116 \101\114\114\111\114 \109\101\115\115\097\103\101"]=function()local function g()error("\111\111\102")end local c=R.new(g)local P,D=pcall(function()c:throw("\102\111\111")end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \102\117\110\099\116\105\111\110 \116\111 \116\104\114\111\119 \097\110 \101\114\114\111\114 \099\111\110\116\097\105\110\105\110\103 \"\102\111\111\""),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))assert(D:match("\058 \111\111\102"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end;["\115\104\111\117\108\100 \115\117\099\099\101\101\100 \105\102 \105\116 \100\111\101\115\110\'\116 \102\097\105\108 \119\104\101\110 \105\116 \119\097\115 \101\120\112\101\099\116\105\110\103 \116\111 \110\101\118\101\114 \116\104\114\111\119 \119\105\116\104 \097 \109\101\115\115\097\103\101"]=function()local function g() end local c=R.new(g)local P=pcall(function()c.never:throw("\102\111\111")end)assert(P,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end;["\105\116 \115\104\111\117\108\100 \115\117\099\099\101\101\100 \105\102 \097 \116\104\114\111\119\105\110\103 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \116\104\114\111\119 \097 \115\117\098\115\116\114\105\110\103 \111\102 \116\104\101 \109\101\115\115\097\103\101"]=function()local function g()error("\102\111\111-\111\111\102")end local c=R.new(g)local P=pcall(function()c:throw("\111\111\102")end)assert(P,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end,["\105\116 \115\104\111\117\108\100 \102\097\105\108 \105\102 \097 \116\104\114\111\119\105\110\103 \102\117\110\099\116\105\111\110 \105\115 \101\120\112\101\099\116\101\100 \116\111 \110\101\118\101\114 \116\104\114\111\119 \097 \115\117\098\115\116\114\105\110\103 \111\102 \116\104\101 \109\101\115\115\097\103\101"]=function()local function g()error("\102\111\111-\111\111\102")end local c=R.new(g)local P,D=pcall(function()c.never:throw("\111\111\102")end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \102\117\110\099\116\105\111\110 \116\111 \110\101\118\101\114 \116\104\114\111\119 \097\110 \101\114\114\111\114 \099\111\110\116\097\105\110\105\110\103 \"\111\111\102\""),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))assert(D:match("\058 \102\111\111\037-\111\111\102"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end;["\105\116 \115\104\111\117\108\100 \115\117\099\099\101\101\100 \105\102 \116\121\112\101\115 \109\097\116\099\104"]=function()local g=R.new(5)local c=R.new("\070\111\111")local P=R.new(function()return true end)local D=pcall(function()g:a("\110\117\109\098\101\114")c:a("\115\116\114\105\110\103")P:a("\102\117\110\099\116\105\111\110")end)assert(D,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end,["\105\116 \115\104\111\117\108\100 \102\097\105\108 \105\102 \116\121\112\101\115 \100\111\110\'\116 \109\097\116\099\104"]=function()local g=R.new(5)local c,P=pcall(function()g:a("\115\116\114\105\110\103")end)assert(not c,"\115\104\111\117\108\100 \102\097\105\108")assert(P:match("\069\120\112\101\099\116\101\100 \118\097\108\117\101 \111\102 \116\121\112\101 \"\115\116\114\105\110\103\"\044 \103\111\116 \118\097\108\117\101 \"\053\" \111\102 \116\121\112\101 \110\117\109\098\101\114"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(P))end,["\110\105\108 \115\104\111\117\108\100 \098\101 \110\111\116 \111\107"]=function()local g=R.new(nil)local c=pcall(function()g.never:ok()end)assert(c,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")local P,D=pcall(function()g:ok()end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \118\097\108\117\101 \"\110\105\108\" \116\111 \098\101 \110\111\110\037-\110\105\108"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end,["\102\097\108\115\101 \115\104\111\117\108\100 \098\101 \111\107"]=function()local g=R.new(false)local c=pcall(function()g:ok()end)assert(c,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")local P,D=pcall(function()g.never:ok()end)assert(not P,"\115\104\111\117\108\100 \102\097\105\108")assert(D:match("\069\120\112\101\099\116\101\100 \118\097\108\117\101 \"\102\097\108\115\101\" \116\111 \098\101 \110\105\108"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(D))end,["\101\113\117\097\108 \118\097\108\117\101\115 \115\104\111\117\108\100 \098\101 \101\113\117\097\108"]=function()local g=R.new("\102\111\111")local c=pcall(function()g:equal("\102\111\111")end)assert(c,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end;["\100\105\102\102\101\114\101\110\116 \118\097\108\117\101\115 \115\104\111\117\108\100 \110\111\116 \098\101 \101\113\117\097\108"]=function()local g=R.new("\053")local c,P=pcall(function()g:equal(5)end)assert(not c,"\115\104\111\117\108\100 \102\097\105\108")assert(P:match("\069\120\112\101\099\116\101\100 \118\097\108\117\101 \"\053\" \037\040\110\117\109\098\101\114\037\041\044 \103\111\116 \"\053\" \037\040\115\116\114\105\110\103\037\041 \105\110\115\116\101\097\100"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(P))end,["\115\105\109\105\108\097\114 \110\117\109\098\101\114\115 \115\104\111\117\108\100 \098\101 \110\101\097\114"]=function()local g=R.new(.1111111)local c=pcall(function()g:near(.11111111111111)end)assert(c,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end,["\110\117\109\098\101\114\115 \111\117\116\115\105\100\101 \116\104\101 \100\101\102\097\117\108\116 \108\105\109\105\116 \115\104\111\117\108\100 \110\111\116 \098\101 \110\101\097\114"]=function()local g=R.new(.11111)local c,P=pcall(function()g:near(.11111111111111)end)assert(not c,"\115\104\111\117\108\100 \102\097\105\108")assert(P:match("\069\120\112\101\099\116\101\100 \118\097\108\117\101 \116\111 \098\101 \110\101\097\114 \037\100\043\046\037\100\043 \037\040\119\105\116\104\105\110 \037\100\043\046\037\100\043\037\041 \098\117\116 \103\111\116 \037\100\043\046\037\100\043 \105\110\115\116\101\097\100"),("\069\114\114\111\114 \109\101\115\115\097\103\101 \100\111\101\115 \110\111\116 \109\097\116\099\104\058\n\037\115\n"):format(P))end;["\110\101\097\114 \115\104\111\117\108\100 \114\101\115\112\101\099\116 \108\105\109\105\116 \097\114\103\117\109\101\110\116"]=function()local g=R.new(.1)local c=pcall(function()g:near(.11111111111111,.1)end)assert(c,"\115\104\111\117\108\100 \115\117\099\099\101\101\100")end}
local TestEZ = script.Parent.Parent.TestEZ
local Expectation = require(TestEZ.Expectation)

return {
    ["it should succeed if an empty function is expected to never throw"] = function()
        local function shouldNotThrow()
        end

        local expect = Expectation.new(shouldNotThrow)

        local success = pcall(function()
            expect.never:throw()
        end)

        assert(success, "should succeed")
    end,
    ["it should succeed if a throwing function is expected to throw"] = function()
        local function shouldThrow()
            error("oof")
        end

        local expect = Expectation.new(shouldThrow)

        local success = pcall(function()
            expect:throw()
        end)

        assert(success, "should succeed")
    end,
    ["it should fail if a throwing function is expected to never throw"] = function()
        local function shouldThrow()
            error("oof")
        end

        local expect = Expectation.new(shouldThrow)

        local success, message = pcall(function()
            expect.never:throw()
        end)

        assert(not success, "should fail")
        assert(
            message:match("Expected function to succeed, but it threw an error:"),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["it should fail if an empty function is expected to throw"] = function()
        local function shouldNotThrow()
        end

        local expect = Expectation.new(shouldNotThrow)

        local success, message = pcall(function()
            expect:throw()
        end)

        assert(not success, "should fail")
        assert(
            message:match("Expected function to throw an error, but it did not."),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["it should fail if an empty function is expected to throw with a message"] = function()
        local function shouldNotThrow()
        end

        local expect = Expectation.new(shouldNotThrow)

        local success, message = pcall(function()
            expect:throw("foo")
        end)

        assert(not success, "should fail")
        assert(
            message:match("Expected function to throw an error containing \"foo\", but it did not."),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["it should fail if a throwing function is expected to throw with a different error message"] = function()
        local function shouldThrow()
            error("oof")
        end

        local expect = Expectation.new(shouldThrow)

        local success, message = pcall(function()
            expect:throw("foo")
        end)

        assert(not success, "should fail")
        -- Make sure we state the expected error
        assert(
            message:match("Expected function to throw an error containing \"foo\""),
            ("Error message does not match:\n%s\n"):format(message)
        )
        -- Make sure we state the actual error
        assert(
            message:match(": oof"),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["should succeed if it doesn't fail when it was expecting to never throw with a message"] = function()
        local function shouldNotThrow()
        end

        local expect = Expectation.new(shouldNotThrow)

        local success = pcall(function()
            expect.never:throw("foo")
        end)

        assert(success, "should succeed")
    end,
    ["it should succeed if a throwing function is expected to throw a substring of the message"] = function()
        local function shouldThrow()
            error("foo-oof")
        end

        local expect = Expectation.new(shouldThrow)

        local success = pcall(function()
            expect:throw("oof")
        end)

        assert(success, "should succeed")
    end,
    ["it should fail if a throwing function is expected to never throw a substring of the message"] = function()
        local function shouldThrow()
            error("foo-oof")
        end

        local expect = Expectation.new(shouldThrow)

        local success, message = pcall(function()
            expect.never:throw("oof")
        end)

        assert(not success, "should fail")
        -- Make sure we state the expected error
        assert(
            message:match("Expected function to never throw an error containing \"oof\""),
            ("Error message does not match:\n%s\n"):format(message)
        )
        -- Make sure we state the actual error
        assert(
            message:match(": foo%-oof"),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["it should succeed if types match"] = function()
        local expectNumber = Expectation.new(5)
        local expectString = Expectation.new("Foo")
        local expectFunction = Expectation.new(function()
            return true
        end)

        local success = pcall(function()
            expectNumber:a("number")
            expectString:a("string")
            expectFunction:a("function")
        end)

        assert(success, "should succeed")
    end,
    ["it should fail if types don't match"] = function()
        local expectNumber = Expectation.new(5)

        local success, message = pcall(function()
            expectNumber:a("string")
        end)

        assert(not success, "should fail")
        assert(
            message:match('Expected value of type "string", got value "5" of type number'),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["nil should be not ok"] = function()
        local expect = Expectation.new(nil)

        local successNever = pcall(function()
            expect.never:ok()
        end)

        assert(successNever, "should succeed")

        local successOk, message = pcall(function()
            expect:ok()
        end)

        assert(not successOk, "should fail")
        assert(
            message:match('Expected value "nil" to be non%-nil'),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["false should be ok"] = function()
        local expect = Expectation.new(false)

        local successOk = pcall(function()
            expect:ok()
        end)

        assert(successOk, "should succeed")

        local successNever, message = pcall(function()
            expect.never:ok()
        end)

        assert(not successNever, "should fail")
        assert(
            message:match('Expected value "false" to be nil'),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["equal values should be equal"] = function()
        local expect = Expectation.new("foo")

        local success = pcall(function()
            expect:equal("foo")
        end)

        assert(success, "should succeed")
    end,
    ["different values should not be equal"] = function()
        local expect = Expectation.new("5")

        local success, message = pcall(function()
            expect:equal(5)
        end)

        assert(not success, "should fail")
        assert(
            message:match('Expected value "5" %(number%), got "5" %(string%) instead'),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["similar numbers should be near"] = function()
        local expect = Expectation.new(0.1111111)

        local success = pcall(function()
            expect:near(1.0 / 9.0)
        end)

        assert(success, "should succeed")
    end,
    ["numbers outside the default limit should not be near"] = function()
        local expect = Expectation.new(0.11111)

        local success, message = pcall(function()
            expect:near(1.0 / 9.0)
        end)

        assert(not success, "should fail")
        assert(
            message:match("Expected value to be near %d+.%d+ %(within %d+.%d+%) but got %d+.%d+ instead"),
            ("Error message does not match:\n%s\n"):format(message)
        )
    end,
    ["near should respect limit argument"] = function()
        local expect = Expectation.new(0.1)

        local success = pcall(function()
            expect:near(1.0 / 9.0, 0.1)
        end)

        assert(success, "should succeed")
    end,
}
