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

Code before:
      eq(true, api.nvim_get_option_value('readonly', {}))
    end)

    it('directory', function()
      screen:set_default_attr_ids({
        [1] = { bold = true, foreground = Screen.colors.Blue1 },
        [2] = { bold = true, reverse = true },
        [3] = { bold = true, foreground = Screen.colors.SeaGreen },
        [4] = { reverse = true },
      })

      local cwd = fn.getcwd()
      local msg = cwd .. pathsep .. 'Xdir is not trusted. Note that directory trust is by name, if the contents change, the directory remains trusted.'
      if #msg >= screen._width then
        pending('path too long')
        return
      end

      -- Need to use feed_command instead of exec_lua because of the confirmation prompt
      feed_command([[lua vim.secure.read('Xdir')]])
      screen:expect([[
        {MATCH: +}|
        {1:~{MATCH: +}}|*3
        {2:{MATCH: +}}|
        :lua vim.secure.read('Xdir'){MATCH: +}|
        {3:]] .. cwd .. pathsep .. [[Xdir is not trusted. Note that directory trust is by name, if the contents change, the directory remains trusted.}{MATCH: +}|
        {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
      ]])
      feed('d')
      screen:expect([[
        ^{MATCH: +}|
        {1:~{MATCH: +}}|*6
        {MATCH: +}|
      ]])

      local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust'))
      eq(string.format('! %s', cwd .. pathsep .. 'Xdir'), vim.trim(trust))
      eq(vim.NIL, exec_lua([[return vim.secure.read('Xdir')]]))

      os.remove(stdpath('state') .. pathsep .. 'trust')

      feed_command([[lua vim.secure.read('Xdir')]])
      screen:expect([[
        {MATCH: +}|
        {1:~{MATCH: +}}|*3
        {2:{MATCH: +}}|
        :lua vim.secure.read('Xdir'){MATCH: +}|
        {3:]] .. cwd .. pathsep .. [[Xdir is not trusted. Note that directory trust is by name, if the contents change, the directory remains trusted.}{MATCH: +}|
        {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
      ]])
      feed('a')

Review comment (suggestion):
```suggestion
        {3:]] .. msg .. [[}{MATCH: +}|
```

Code after:
      eq(true, api.nvim_get_option_value('readonly', {}))
    end)

    it('directory', function()
      screen:set_default_attr_ids({
        [1] = { bold = true, foreground = Screen.colors.Blue1 },
        [2] = { bold = true, reverse = true },
        [3] = { bold = true, foreground = Screen.colors.SeaGreen },
        [4] = { reverse = true },
      })

      local cwd = fn.getcwd()
      local msg = cwd
        .. pathsep
        .. 'Xdir is not trusted. DIRECTORY trust is decided only by its name, not its contents.'
      if #msg >= screen._width then
        pending('path too long')
        return
      end

      -- Need to use feed_command instead of exec_lua because of the confirmation prompt
      feed_command([[lua vim.secure.read('Xdir')]])
      screen:expect([[
        {MATCH: +}|
        {1:~{MATCH: +}}|*3
        {2:{MATCH: +}}|
        :lua vim.secure.read('Xdir'){MATCH: +}|
        {3:]] .. msg .. [[}{MATCH: +}|
        {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
      ]])
      feed('d')
      screen:expect([[
        ^{MATCH: +}|
        {1:~{MATCH: +}}|*6
        {MATCH: +}|
      ]])

      local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust'))
      eq(string.format('! %s', cwd .. pathsep .. 'Xdir'), vim.trim(trust))
      eq(vim.NIL, exec_lua([[return vim.secure.read('Xdir')]]))

      os.remove(stdpath('state') .. pathsep .. 'trust')

      feed_command([[lua vim.secure.read('Xdir')]])
      screen:expect([[
        {MATCH: +}|
        {1:~{MATCH: +}}|*3
        {2:{MATCH: +}}|
        :lua vim.secure.read('Xdir'){MATCH: +}|
        {3:]] .. msg .. [[}{MATCH: +}|
        {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|