|
| 1 | +local putils = require "telescope.previewers.utils" |
| 2 | +local utils = require "telescope.utils" |
| 3 | + |
| 4 | +describe("timed_split_lines", function() |
| 5 | + local expect = { |
| 6 | + "", |
| 7 | + "", |
| 8 | + "line3 of the file", |
| 9 | + "", |
| 10 | + "line5 of the file", |
| 11 | + "", |
| 12 | + "", |
| 13 | + "line8 of the file, last line of file", |
| 14 | + } |
| 15 | + |
| 16 | + local split_lines = function(s) |
| 17 | + return putils.timed_split_lines(s, { |
| 18 | + start_time = vim.uv.hrtime(), |
| 19 | + preview = { |
| 20 | + timeout = 250, -- should be more than enough time |
| 21 | + }, |
| 22 | + }) |
| 23 | + end |
| 24 | + |
| 25 | + if utils.iswin then |
| 26 | + describe("handles files on Windows", function() |
| 27 | + it("reads file ending with \\r\\n (standard Windows line terminator)", function() |
| 28 | + local file = table.concat(expect, "\r\n") .. "\r\n" |
| 29 | + assert.are.same(expect, split_lines(file)) |
| 30 | + end) |
| 31 | + |
| 32 | + it("reads file ending with \\n only", function() |
| 33 | + local file = table.concat(expect, "\n") .. "\n" |
| 34 | + assert.are.same(expect, split_lines(file)) |
| 35 | + end) |
| 36 | + |
| 37 | + it("reads file with no trailing newline", function() |
| 38 | + local file = table.concat(expect, "\r\n") |
| 39 | + assert.are.same(expect, split_lines(file)) |
| 40 | + end) |
| 41 | + end) |
| 42 | + else |
| 43 | + describe("handles files on non Windows environment", function() |
| 44 | + it("reads file ending with \\n (standard Unix line terminator)", function() |
| 45 | + local file = table.concat(expect, "\n") .. "\n" |
| 46 | + assert.are.same(expect, split_lines(file)) |
| 47 | + end) |
| 48 | + |
| 49 | + it("reads file with no trailing newline", function() |
| 50 | + local file = table.concat(expect, "\n") |
| 51 | + assert.are.same(expect, split_lines(file)) |
| 52 | + end) |
| 53 | + end) |
| 54 | + end |
| 55 | +end) |
0 commit comments