@@ -1194,33 +1194,45 @@ describe('build_inline_selection_text', function()
11941194 vim .bo = original_bo
11951195 end )
11961196
1197- it (' should return nil and notify when not a file buffer' , function ()
1197+ it (' should return formatted text without file path for non- file buffer' , function ()
11981198 local original_is_buf_a_file = util .is_buf_a_file
1199+ local original_get_current_selection = BaseContext .get_current_selection
1200+ local original_get_current_file_for_selection = BaseContext .get_current_file_for_selection
11991201 local original_get_current_buf = vim .api .nvim_get_current_buf
12001202
12011203 util .is_buf_a_file = function ()
12021204 return false
12031205 end
1206+ BaseContext .get_current_selection = function ()
1207+ return { text = ' function foo()\n return 42\n end' , lines = ' 10, 12' }
1208+ end
1209+ BaseContext .get_current_file_for_selection = function ()
1210+ return nil
1211+ end
12041212 vim .api .nvim_get_current_buf = function ()
12051213 return 10
12061214 end
12071215
1208- local original_notify = vim .notify
1209- local notifications = {}
1210- vim .notify = function (msg , level )
1211- table.insert (notifications , { msg = msg , level = level })
1212- end
1216+ local original_bo = vim .bo
1217+ vim .bo = setmetatable ({}, {
1218+ __index = function (_ , _ )
1219+ return { filetype = ' lua' }
1220+ end ,
1221+ })
12131222
12141223 local text = context .build_inline_selection_text ()
12151224
1216- assert .is_nil (text )
1217- assert .equal (1 , # notifications )
1218- assert .equal (' Cannot add selection: not a file buffer' , notifications [1 ].msg )
1219- assert .equal (vim .log .levels .WARN , notifications [1 ].level )
1225+ assert .is_not_nil (text )
1226+ assert .is_nil (text :match (' %*%*`' ))
1227+ assert .is_not_nil (text :match (' ```lua' ))
1228+ assert .is_not_nil (text :match (' function foo%(%)' ))
1229+ assert .is_not_nil (text :match (' ```$' ))
12201230
12211231 util .is_buf_a_file = original_is_buf_a_file
1232+ BaseContext .get_current_selection = original_get_current_selection
1233+ BaseContext .get_current_file_for_selection = original_get_current_file_for_selection
12221234 vim .api .nvim_get_current_buf = original_get_current_buf
1223- vim .notify = original_notify
1235+ vim .bo = original_bo
12241236 end )
12251237
12261238 it (' should return nil and notify when no visual selection found' , function ()
0 commit comments