describe("The rednet library", function()
    describe("rednet.open", function()
        it("validates arguments", function()
            expect.error(rednet.open, nil):eq("bad argument #1 (expected string, got nil)")
        end)

        it("requires a modem to be present", function()
            expect.error(rednet.open, "not_there"):eq("No such modem: not_there")
        end)
    end)

    describe("rednet.close", function()
        it("validates arguments", function()
            rednet.close()
            expect.error(rednet.close, 1):eq("bad argument #1 (expected string, got number)")
            expect.error(rednet.close, false):eq("bad argument #1 (expected string, got boolean)")
        end)

        it("requires a modem to be present", function()
            expect.error(rednet.close, "not_there"):eq("No such modem: not_there")
        end)
    end)

    describe("rednet.isOpen", function()
        it("validates arguments", function()
            rednet.isOpen()
            rednet.isOpen("")
            expect.error(rednet.isOpen, 1):eq("bad argument #1 (expected string, got number)")
            expect.error(rednet.isOpen, false):eq("bad argument #1 (expected string, got boolean)")
        end)
    end)

    describe("rednet.send", function()
        it("validates arguments", function()
            rednet.send(1)
            rednet.send(1, nil, "")
            expect.error(rednet.send, nil):eq("bad argument #1 (expected number, got nil)")
            expect.error(rednet.send, 1, nil, false):eq("bad argument #3 (expected string, got boolean)")
        end)
    end)

    describe("rednet.broadcast", function()
        it("validates arguments", function()
            rednet.broadcast(nil)
            rednet.broadcast(nil, "")
            expect.error(rednet.broadcast, nil, false):eq("bad argument #2 (expected string, got boolean)")
        end)
    end)

    describe("rednet.receive", function()
        it("validates arguments", function()
            expect.error(rednet.receive, false):eq("bad argument #1 (expected string, got boolean)")
            expect.error(rednet.receive, "", false):eq("bad argument #2 (expected number, got boolean)")
        end)
    end)

    describe("rednet.host", function()
        it("validates arguments", function()
            expect.error(rednet.host, "", "localhost"):eq("Reserved hostname")
            expect.error(rednet.host, nil):eq("bad argument #1 (expected string, got nil)")
            expect.error(rednet.host, "", nil):eq("bad argument #2 (expected string, got nil)")
        end)
    end)

    describe("rednet.unhost", function()
        it("validates arguments", function()
            rednet.unhost("")
            expect.error(rednet.unhost, nil):eq("bad argument #1 (expected string, got nil)")
        end)
    end)

    describe("rednet.lookup", function()
        it("validates arguments", function()
            expect.error(rednet.lookup, nil):eq("bad argument #1 (expected string, got nil)")
            expect.error(rednet.lookup, "", false):eq("bad argument #2 (expected string, got boolean)")
        end)

        it("gets a locally hosted protocol", function()
            rednet.host("a_protocol", "a_hostname")

            expect(rednet.lookup("a_protocol")):eq(os.getComputerID())
            expect(rednet.lookup("a_protocol", "localhost")):eq(os.getComputerID())
            expect(rednet.lookup("a_protocol", "a_hostname")):eq(os.getComputerID())
        end)
    end)
end)
