local stdio = require("neocodeium.utils.stdio")

describe("readable()", function()
   it("should return true if file is readable", function()
      assert.True(stdio.readable("tests/assets/readable.txt"))
   end)
   it("should return false if file doesn't exists", function()
      assert.False(stdio.readable("not_exists.txt"))
   end)
   it("should return false if file exists, but not readable", function()
      assert.False(stdio.readable("tests/assets/not_readable.txt"))
   end)
end)

describe("executable()", function()
   it("should return true if executable exists", function()
      assert.True(stdio.executable("cat"))
   end)
   it("should return false if executable doesn't exists or not executable", function()
      assert.False(stdio.executable("tests/assets/readable.txt"))
      assert.False(stdio.executable("tests/assets/not_exists"))
   end)
end)

describe("read()", function()
   it("should return content of the file as a string", function()
      assert.Equal(stdio.read("tests/assets/readable.txt"), "hello\nworld\n!\n")
   end)
   it("should return nil on any failure (not exists, can't be read etc)", function()
      assert.Nil(stdio.read("not_exists.txt"))
      assert.Nil(stdio.read("tests/assets/not_readable.txt"))
   end)
end)

describe("root_dir()", function()
   it("should return correct path string", function()
      local path = stdio.root_dir()
      assert.True(#vim.fs.find("lua", { path = path, type = "directory" }) > 0)
      assert.True(#vim.fs.find("neocodeium", { path = path .. "/lua", type = "directory" }) > 0)
   end)
end)
