local N=require("\064\068\101\118\080\097\099\107\097\103\101\115\047\074\101\115\116\071\108\111\098\097\108\115")local f=N.describe local u=N.test local p=N.expect local b=require("\046\046\047\105\110\105\116")local E=b.Future f("\109\097\112\069\114\114",function()u("\116\111 \101\114\114\111\114",function()local N=E.new(function()error("\065",0)end)N:mapErr(function(N)(p(N)).toEqual("\065")error("\066",0)end)local f=N:await();(p(f:isErr())).toBe(true)local u=f:unwrapErr();(p(u)).toEqual("\066")p.assertions(3)end)u("\116\111 \115\116\114\105\110\103",function()local N=E.new(function()error("\065",0)return"\065"end)N:mapErr(function(N)(p(N)).toEqual("\065")return"\066"end)local f=N:await();(p(f:isErr())).toBe(true)local u=f:unwrapErr();(p(u)).toEqual("\066")p.assertions(3)end)end)
local JestGlobals = require("@DevPackages/JestGlobals")

local describe = JestGlobals.describe
local test = JestGlobals.test
local expect = JestGlobals.expect

local Futures = require("../init")
local Future = Futures.Future

describe("mapErr", function()
	test("to error", function()
		local myFuture = Future.new(function()
			error("A", 0)
		end)

		myFuture:mapErr(function(err)
			expect(err).toEqual("A")
			error("B", 0)
		end)

		local result = myFuture:await()
		expect(result:isErr()).toBe(true)

		local err = result:unwrapErr()
		expect(err).toEqual("B")
		expect.assertions(3)
	end)

	test("to string", function()
		local myFuture = Future.new(function()
			error("A", 0)
			return "A"
		end)

		myFuture:mapErr(function(err)
			expect(err).toEqual("A")
			return "B"
		end)

		local result = myFuture:await()
		expect(result:isErr()).toBe(true)

		local err = result:unwrapErr()
		expect(err).toEqual("B")
		expect.assertions(3)
	end)
end)
