Skip to content

Commit

Permalink
Use special init file in tests
Browse files Browse the repository at this point in the history
The main purpose at the moment is to select a compatible colorscheme for
neovim v0.9 ad v0.10.
  • Loading branch information
lucc committed May 16, 2024
1 parent 5e7a7de commit dc345d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This is a nvimpager init file for the test suite.

if vim.fn.has("nvim-0.10") == 1 then
vim.cmd.colorscheme("vim")
end
34 changes: 17 additions & 17 deletions test/nvimpager_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ describe("cat mode", function()
end)
end)

it("displays a small file with syntax highlighting to stdout", function()
local output = run("./nvimpager -c test/fixtures/makefile")
it("displays a small file with syntax highlighting to stdout #colorscheme", function()
local output = run("./nvimpager -c test/fixtures/makefile -u test/fixtures/init.lua")
local expected = read("test/fixtures/makefile.ansi")
assert.equal(expected, output)
end)

it("reads stdin with syntax highlighting", function()
it("reads stdin with syntax highlighting #colorscheme", function()
local output = run("./nvimpager -c -- " ..
"-c 'set filetype=make' " ..
"< test/fixtures/makefile")
"-c 'set filetype=make' -u test/fixtures/init.lua " ..
" < test/fixtures/makefile")
local expected = read("test/fixtures/makefile.ansi")
assert.equal(expected, output)
end)
Expand All @@ -94,24 +94,24 @@ describe("cat mode", function()
assert.equal(expected, output)
end)

it("handles color schemes with a non trivial Normal group", function()
it("handles color schemes with a non trivial Normal group #colorscheme", function()
local output = run("./nvimpager -c test/fixtures/conceal.tex " ..
"--cmd 'hi Normal ctermfg=Red'")
" -u test/fixtures/init.lua --cmd 'hi Normal ctermfg=Red'")
local expected = read("test/fixtures/conceal.tex.red")
assert.equal(expected, output)
end)

it("highlights all files", function()
it("highlights all files #colorscheme", function()
local output = run("./nvimpager -c test/fixtures/makefile " ..
"test/fixtures/help.txt ")
"test/fixtures/help.txt -u test/fixtures/init.lua")
local expected = read("test/fixtures/makefile.ansi") ..
read("test/fixtures/help.txt.ansi")
assert.equal(expected, output)
end)

it("concatenates the same file twice", function()
it("concatenates the same file twice #colorscheme", function()
local output = run("./nvimpager -c test/fixtures/makefile " ..
"test/fixtures/makefile ")
"test/fixtures/makefile -u test/fixtures/init.lua")
local expected = read("test/fixtures/makefile.ansi")
expected = expected .. expected
assert.equal(expected, output)
Expand All @@ -130,22 +130,22 @@ describe("cat mode", function()
assert.equal('', output)
end)

it("explicit - as file argument means stdin", function()
local shell_command = "echo foo | ./nvimpager -c - test/fixtures/makefile"
it("explicit - as file argument means stdin #colorscheme", function()
local shell_command = "echo foo | ./nvimpager -c - test/fixtures/makefile -u test/fixtures/init.lua"
local output = run("sh -c '" .. shell_command .. "'")
local expected = "\27[0mfoo\27[0m\n" ..
read("test/fixtures/makefile.ansi")
assert.equal(expected, output)
end)

it("prefers file arguments over stdin", function()
local shell_command = "echo foo | ./nvimpager -c test/fixtures/makefile"
it("prefers file arguments over stdin #colorscheme", function()
local shell_command = "echo foo | ./nvimpager -c test/fixtures/makefile -u test/fixtures/init.lua"
local output = run("sh -c '" .. shell_command .. "'")
assert.equal(read("test/fixtures/makefile.ansi"), output)
end)

it("can show stdin as the second file", function()
local output = run("echo foo | ./nvimpager -c test/fixtures/makefile -")
it("can show stdin as the second file #colorscheme", function()
local output = run("echo foo | ./nvimpager -c test/fixtures/makefile - -u test/fixtures/init.lua")
local expected = read("test/fixtures/makefile.ansi") .. "\27[0mfoo\27[0m\n"
assert.equal(expected, output)
end)
Expand Down

0 comments on commit dc345d7

Please sign in to comment.