mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	test: make text-only snapshots work
This commit is contained in:
		| @@ -259,12 +259,13 @@ local ext_keys = { | ||||
| --              row. Last character of each row (typically "|") is stripped. | ||||
| --              Common indentation is stripped. | ||||
| --              "{MATCH:x}" in a line is matched against Lua pattern `x`. | ||||
| --              "*count" at the end of a line means it repeats `count` times. | ||||
| --              "*n" at the end of a line means it repeats `n` times. | ||||
| -- attr_ids:    Expected text attributes. Screen rows are transformed according | ||||
| --              to this table, as follows: each substring S composed of | ||||
| --              characters having the same attributes will be substituted by | ||||
| --              "{K:S}", where K is a key in `attr_ids`. Any unexpected | ||||
| --              attributes in the final state are an error. | ||||
| --              Use an empty table for a text-only (no attributes) expectation. | ||||
| --              Use screen:set_default_attr_ids() to define attributes for many | ||||
| --              expect() calls. | ||||
| -- extmarks:    Expected win_extmarks accumulated for the grids. For each grid, | ||||
| @@ -346,6 +347,9 @@ function Screen:expect(expected, attr_ids, ...) | ||||
|   local attr_state = { | ||||
|     ids = attr_ids or self._default_attr_ids, | ||||
|   } | ||||
|   if isempty(attr_ids) then | ||||
|     attr_state.ids = nil | ||||
|   end | ||||
|   if self._options.ext_linegrid then | ||||
|     attr_state.id_to_index = self:linegrid_check_attrs(attr_state.ids or {}) | ||||
|   end | ||||
| @@ -1252,7 +1256,7 @@ end | ||||
|  | ||||
| -- Generates tests. Call it where Screen:expect() would be. Waits briefly, then | ||||
| -- dumps the current screen state in the form of Screen:expect(). | ||||
| -- Use snapshot_util({},true) to generate a text-only (no attributes) test. | ||||
| -- Use snapshot_util({}) to generate a text-only (no attributes) test. | ||||
| -- | ||||
| -- @see Screen:redraw_debug() | ||||
| function Screen:snapshot_util(attrs, ignore, request_cb) | ||||
| @@ -1318,6 +1322,9 @@ function Screen:get_snapshot(attrs, ignore) | ||||
|   } | ||||
|   if attrs == nil then | ||||
|     attrs = self._default_attr_ids | ||||
|   elseif isempty(attrs) then | ||||
|     attrs = nil | ||||
|     attr_state.ids = nil | ||||
|   else | ||||
|     attr_state.modified = true | ||||
|   end | ||||
| @@ -1328,7 +1335,7 @@ function Screen:get_snapshot(attrs, ignore) | ||||
|     end | ||||
|   end | ||||
|   if self._options.ext_linegrid then | ||||
|     attr_state.id_to_index = self:linegrid_check_attrs(attr_state.ids) | ||||
|     attr_state.id_to_index = self:linegrid_check_attrs(attr_state.ids or {}) | ||||
|   end | ||||
|  | ||||
|   local lines = self:render(true, attr_state, true) | ||||
| @@ -1415,6 +1422,8 @@ function Screen:_print_snapshot(attrs, ignore) | ||||
|       table.insert(attrstrs, "  "..keyval.." = "..dict..";") | ||||
|     end | ||||
|     attrstr = (", attr_ids={\n"..table.concat(attrstrs, "\n").."\n}") | ||||
|   elseif isempty(attrs) then | ||||
|     attrstr = ', attr_ids={}' | ||||
|   end | ||||
|  | ||||
|   local result = 'screen:expect{grid=[[\n' .. kwargs.grid .. '\n]]' .. attrstr | ||||
| @@ -1430,6 +1439,7 @@ end | ||||
|  | ||||
| function Screen:print_snapshot(attrs, ignore) | ||||
|   print('\n' .. self:_print_snapshot(attrs, ignore) .. '\n') | ||||
|   io.stdout:flush() | ||||
| end | ||||
|  | ||||
| function Screen:_insert_hl_id(attr_state, hl_id) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq