|
3 | 3 | local util = require('tests.util') |
4 | 4 |
|
5 | 5 | describe('table', function() |
| 6 | + ---@param columns integer |
| 7 | + ---@param callback function |
| 8 | + local function with_columns(columns, callback) |
| 9 | + local previous = vim.o.columns |
| 10 | + vim.o.columns = columns |
| 11 | + local ok, err = pcall(callback) |
| 12 | + vim.o.columns = previous |
| 13 | + if not ok then |
| 14 | + error(err, 0) |
| 15 | + end |
| 16 | + end |
| 17 | + |
6 | 18 | local lines = { |
7 | 19 | '', |
8 | 20 | '| Heading 1 | `Heading 2` |', |
@@ -302,6 +314,37 @@ describe('table', function() |
302 | 314 | }) |
303 | 315 | end) |
304 | 316 |
|
| 317 | + it('wrapped indented table', function() |
| 318 | + with_columns(60, function() |
| 319 | + util.setup.text({ |
| 320 | + '', |
| 321 | + ' | Approach | Allocations | Performance |', |
| 322 | + ' |----------|-------------|-------------|', |
| 323 | + ' | `format!()` in loop | N | Slow |', |
| 324 | + ' | `write!()` to reused buffer | 1 | Fast |', |
| 325 | + ' | `push_str()` + `push()` | 1 | Fastest |', |
| 326 | + ' | Pre-sized `String::with_capacity()` | 1 (no realloc) | Fast |', |
| 327 | + }, { |
| 328 | + pipe_table = { max_table_width = -2 }, |
| 329 | + win_options = { wrap = { default = false, rendered = true } }, |
| 330 | + }) |
| 331 | + |
| 332 | + util.assert_screen({ |
| 333 | + ' ┌────────────────────┬────────────────┬───────────────┐', |
| 334 | + ' │ Approach │ Allocations │ Performance │', |
| 335 | + ' ├────────────────────┼────────────────┼───────────────┤', |
| 336 | + ' │ format!() in loop │ N │ Slow │', |
| 337 | + ' │ write!() to reused │ 1 │ Fast │', |
| 338 | + ' │ buffer │ │ │', |
| 339 | + ' │ push_str() + push( │ 1 │ Fastest │', |
| 340 | + ' │ ) │ │ │', |
| 341 | + ' │ Pre-sized String:: │ 1 (no realloc) │ Fast │', |
| 342 | + ' │ with_capacity() │ │ │', |
| 343 | + ' └────────────────────┴────────────────┴───────────────┘', |
| 344 | + }) |
| 345 | + end) |
| 346 | + end) |
| 347 | + |
305 | 348 | it('wrapped long delimiter', function() |
306 | 349 | util.setup.text({ |
307 | 350 | '', |
|
0 commit comments