<commit_before>describe("rote.RoteTerm", function()
    it("creates RoteTerm", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
    end)

    it("throws if size is invalid", function()
        local rote = assert(require "rote")
        assert.has_error(function()
            local rt = rote.RoteTerm(0, 80)
        end)
        assert.has_error(function()
            local rt = rote.RoteTerm(24, 0)
        end)
    end)

    it("gets size of RoteTerm", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(24, rt:rows())
        assert.equal(80, rt:cols())
    end)

    it("sets cursor to (0, 0) initially", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(0, rt:row())
        assert.equal(0, rt:col())
    end)

    it("sets all chars to space initially", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        for row = 0, 23 do
            for col = 0, 79 do
                assert.equal(' ', rt:cellChar(row, col))
            end
        end
    end)

    it("changes cell char", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:setCellChar(0, 0, 'A')
        assert.equal('A', rt:cellChar(0, 0))
    end)

    it("throws if length(ch) != 1", function()
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, 'aa')
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, '')
        end)
    end)

    it("throws if ch is a control character", function()
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, '\0')
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, '\n')
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, string.char(31))
        end)
    end)

    it("changes cell attribute", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:setCellAttr(0, 0, 42)
        assert.equal(42, rt:cellAttr(0, 0))
    end)

    it("throws if cell attribute is invalid", function()
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellAttr(0, 0, -1)
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellAttr(0, 0, 256)
        end)
    end)

    it("changes current attribute", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:setAttr(30)
        assert.equal(30, rt:attr())
    end)

    it("has child_pid = 0 by default", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(0, rt:childPid())
    end)

    it("forks pty", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        local pid = rt:forkPty('ls')
        assert.equal(pid, rt:childPid())
        -- TODO fix zombie
    end)

    it("forsakes child", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:forkPty('ls')
        os.execute('sleep 1')
        rt:forsakeChild()
        -- TODO fix zombie
    end)

    it("gets updates from child", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:forkPty('ls -a')
        os.execute('sleep 1')
        rt:update()
        rt:forsakeChild()
        assert.not_equal(' ', rt:cellChar(0, 0))
    end)

    it("restores from snapshot", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        local snapshot = rt:takeSnapshot()
        assert.equal(' ', rt:cellChar(0, 0))
        rt:setCellChar(0, 0, 'A')
        assert.equal('A', rt:cellChar(0, 0))
        rt:restoreSnapshot(snapshot)
        assert.equal(' ', rt:cellChar(0, 0))
    end)

    -- TODO write, inject, keypress, getPtyFd
end)<commit_msg>spec for RoteTerm:getPtyFd()<commit_after>describe("rote.RoteTerm", function()
    it("creates RoteTerm", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
    end)

    it("throws if size is invalid", function()
        local rote = assert(require "rote")
        assert.has_error(function()
            local rt = rote.RoteTerm(0, 80)
        end)
        assert.has_error(function()
            local rt = rote.RoteTerm(24, 0)
        end)
    end)

    it("gets size of RoteTerm", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(24, rt:rows())
        assert.equal(80, rt:cols())
    end)

    it("sets cursor to (0, 0) initially", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(0, rt:row())
        assert.equal(0, rt:col())
    end)

    it("sets all chars to space initially", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        for row = 0, 23 do
            for col = 0, 79 do
                assert.equal(' ', rt:cellChar(row, col))
            end
        end
    end)

    it("changes cell char", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:setCellChar(0, 0, 'A')
        assert.equal('A', rt:cellChar(0, 0))
    end)

    it("throws if length(ch) != 1", function()
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, 'aa')
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, '')
        end)
    end)

    it("throws if ch is a control character", function()
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, '\0')
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, '\n')
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellChar(0, 0, string.char(31))
        end)
    end)

    it("changes cell attribute", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:setCellAttr(0, 0, 42)
        assert.equal(42, rt:cellAttr(0, 0))
    end)

    it("throws if cell attribute is invalid", function()
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellAttr(0, 0, -1)
        end)
        assert.has_error(function()
            local rote = assert(require "rote")
            local rt = rote.RoteTerm(24, 80)
            rt:setCellAttr(0, 0, 256)
        end)
    end)

    it("changes current attribute", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:setAttr(30)
        assert.equal(30, rt:attr())
    end)

    it("has child_pid = 0 by default", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(0, rt:childPid())
    end)

    it("forks pty", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        local pid = rt:forkPty('ls')
        assert.equal(pid, rt:childPid())
        -- TODO fix zombie
    end)

    it("forsakes child", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:forkPty('ls')
        os.execute('sleep 1')
        rt:forsakeChild()
        -- TODO fix zombie
    end)

    it("gets updates from child", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        rt:forkPty('ls -a')
        os.execute('sleep 1')
        rt:update()
        rt:forsakeChild()
        assert.not_equal(' ', rt:cellChar(0, 0))
    end)

    it("restores from snapshot", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        local snapshot = rt:takeSnapshot()
        assert.equal(' ', rt:cellChar(0, 0))
        rt:setCellChar(0, 0, 'A')
        assert.equal('A', rt:cellChar(0, 0))
        rt:restoreSnapshot(snapshot)
        assert.equal(' ', rt:cellChar(0, 0))
    end)

    it("returns pseudo tty descriptor", function()
        local rote = assert(require "rote")
        local rt = rote.RoteTerm(24, 80)
        assert.equal(-1, rt:getPtyFd())
        local pid = rt:forkPty('vi')
        assert.not_equal(-1, rt:getPtyFd())
        rt:update()
        os.execute('kill -9 ' .. pid)
        rt:forsakeChild()
        assert.equal(-1, rt:getPtyFd())
    end)

    -- TODO write, inject, keypress
end)
{'fraction_non_alphanumeric': 0.13452868852459016, 'fraction_numerical': 0.03114754098360656, 'mean_word_length': 2.0154464009885698, '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': '7449974', 'n_tokens_mistral': 3384, 'n_tokens_neox': 3124, 'n_words': 802}