Repository: neovim/neovim
File: test/functional/lua/fs_spec.lua (Lua)

Code before:
    it('works with a relative path', function()
      eq(
        test_source_path,
        exec_lua([[return vim.fs.root(..., 'CMakePresets.json')]], vim.fs.basename(nvim_prog))
      )
    end)

    it('uses cwd for unnamed buffers', function()
      command('new')
      eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
    end)

    it("uses cwd for buffers with non-empty 'buftype'", function()
      command('new')
      command('set buftype=nofile')
      command('file lua://')
      eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
    end)

    it('returns an absolute path for an invalid filename', function()
      command('new')
      command('set buftype=nofile')
      command('file lua://')
      eq(test_source_path, exec_lua([[return vim.fs.root('file://asd', 'CMakePresets.json')]]))
    end)
  end)

  describe('joinpath()', function()
    it('works', function()
      eq('foo/bar/baz', vim.fs.joinpath('foo', 'bar', 'baz'))
      eq('foo/bar/baz', vim.fs.joinpath('foo', '/bar/', '/baz'))
    end)
    it('rewrites backslashes on Windows', function()
      if is_os('win') then
        eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo]], [[\\bar\\\\baz]], [[zub\]]))
      else
        eq([[foo/\\bar\\\\baz/zub\]], vim.fs.joinpath([[foo]], [[\\bar\\\\baz]], [[zub\]]))
      end
    end)
    it('strips redundant slashes', function()
      if is_os('win') then
        eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo//]], [[\\bar\\\\baz]], [[zub\]]))
      else
        eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo]], [[//bar////baz]], [[zub/]]))
      end
    end)
  end)

  describe('normalize()', function()
    it('removes trailing /', function()
      eq('/home/user', vim.fs.normalize('/home/user/'))

Review comment (bug):
windows ci fail, need `t.fix_slashes`

i will push a fix + rebase

```
FAILED   test/functional/lua/fs_spec.lua @ 436: vim.fs root() returns an absolute path for an invalid filename
test/functional\lua\fs_spec.lua:440: Expected objects to be the same.
Passed in:
(string) 'D:\a\neovim\neovim'
Expected:
(string) 'D:/a/neovim/neovim'
```

Code after:
    it('works with a relative path', function()
      eq(
        test_source_path,
        exec_lua([[return vim.fs.root(..., 'CMakePresets.json')]], vim.fs.basename(nvim_prog))
      )
    end)

    it('uses cwd for unnamed buffers', function()
      command('new')
      eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
    end)

    it("uses cwd for buffers with non-empty 'buftype'", function()
      command('new')
      command('set buftype=nofile')
      command('file lua://')
      eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
    end)

    it('returns an absolute path for an invalid filename', function()
      assert(n.fn.isabsolutepath(test_source_path) == 1)
      eq(
        t.fix_slashes(test_source_path),
        t.fix_slashes(exec_lua([[return vim.fs.root('file://asd', 'CMakePresets.json')]]))
      )
    end)
  end)

  describe('joinpath()', function()
    it('works', function()
      eq('foo/bar/baz', vim.fs.joinpath('foo', 'bar', 'baz'))
      eq('foo/bar/baz', vim.fs.joinpath('foo', '/bar/', '/baz'))
    end)
    it('rewrites backslashes on Windows', function()
      if is_os('win') then
        eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo]], [[\\bar\\\\baz]], [[zub\]]))
      else
        eq([[foo/\\bar\\\\baz/zub\]], vim.fs.joinpath([[foo]], [[\\bar\\\\baz]], [[zub\]]))
      end
    end)
    it('strips redundant slashes', function()
      if is_os('win') then
        eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo//]], [[\\bar\\\\baz]], [[zub\]]))
      else
        eq('foo/bar/baz/zub/', vim.fs.joinpath([[foo]], [[//bar////baz]], [[zub/]]))
      end
    end)
  end)

  describe('normalize()', function()
    it('removes trailing /', function()