local Context = require("care.context")

describe("Context", function()
    before_each(function()
        vim.api.nvim_buf_set_lines(0, 0, -1, false, {})
        vim.api.nvim_win_set_cursor(0, { 1, 0 })
    end)
    describe("create new", function()
        it("in middle of line", function()
            vim.fn.setline(1, "local function test(param) end")
            vim.cmd.normal({ "0f)l", bang = true })
            vim.cmd.startinsert()

            local context = Context:new()
            assert.is_true(context:changed())
            assert.is.equal(26, context.cursor.col)
            assert.is.equal(1, context.cursor.row)
            assert.is.equal("local function test(param) end", context.line)
            assert.is.equal("local function test(param)", context.line_before_cursor)
        end)

        it("at end of line", function()
            vim.fn.setline(1, "local function test(param) end")
            vim.cmd.startinsert({ bang = true })

            local context = Context:new()
            assert.is_true(context:changed())
            assert.is.equal(30, context.cursor.col)
            assert.is.equal(1, context.cursor.row)
            assert.is.equal("local function test(param) end", context.line)
            assert.is.equal("local function test(param) end", context.line_before_cursor)
        end)
    end)
end)
