Last active
March 17, 2023 11:30
-
-
Save mcepl/962ee646a7c66645c275ccc33113082c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- TODO: show current hunk in status line | |
-- TODO: incorporate more patchutils functionality | |
-- FIXME https://www.reddit.com/r/neovim/comments/unwvkw/github_hkuptyrunesnvim_lua_test_framework_for/ | |
-- FIXME https://github.com/hkupty/runes.nvim | |
pretty = require("pl.pretty") | |
local M = {} | |
-- Header object | |
M.Header = {} | |
function M.Header:parse(inline) | |
local result = {} | |
local pat = "@@%s+%-(%d+),(%d+)%s+%+(%d+),(%d+)%s+@@%s*(.*)" | |
res = inline:match(pat) | |
print("res:\n" .. pretty.dump(res)) | |
return { | |
res = res, | |
line = inline, | |
oldFirst = res[1], | |
oldCount = res[2], | |
newFirst = res[3], | |
newCount = res[4], | |
remainderLine = res[5] | |
} | |
end | |
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pretty = require("pl.pretty") | |
describe("Parsing of a hunk header", function() | |
local hk, header | |
setup(function() | |
hk = require("hunk") | |
test_header = "@@ -20,8 +20,17 @@ Hunk #1, a/tests/test_ec_curves.py" | |
end) | |
before_each(function() | |
header = hk.Header:parse(test_header) | |
end) | |
it("it is not nil", function() | |
assert.is_not_nil(header) | |
end) | |
it("original line is preserved in the attribute line", function() | |
assert.are.equal(header.line, test_header) | |
end) | |
it("attributes are set correctly", function() | |
assert.are.equal(20, header.oldFirst) | |
assert.are.equal(8, header.oldCount) | |
assert.are.equal(20, header.newFirst) | |
assert.are.equal(17, header.newCount) | |
end) | |
it("remainder of the line is preserved as well", function() | |
assert.are.equal("Hunk #1, a/tests/test_ec_curves.py", header.remainderLine) | |
end) | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stitny~/.l/s/n/s/p/p/s/v/ftplugin (lua *)$ busted -o plainTerminal --verbose hunk_spec.lua | |
"20" | |
"20" | |
"20" | |
"20" | |
0 successes / 0 failures / 4 errors / 0 pending : 0.008232 seconds | |
Error -> hunk_spec.lua @ 11 | |
Parsing of a hunk header before_each | |
./hunk.lua:19: attempt to concatenate a boolean value | |
stack traceback: | |
./hunk.lua:19: in method 'parse' | |
hunk_spec.lua:12: in function <hunk_spec.lua:11> | |
Error -> hunk_spec.lua @ 11 | |
Parsing of a hunk header before_each | |
./hunk.lua:19: attempt to concatenate a boolean value | |
stack traceback: | |
./hunk.lua:19: in method 'parse' | |
hunk_spec.lua:12: in function <hunk_spec.lua:11> | |
Error -> hunk_spec.lua @ 11 | |
Parsing of a hunk header before_each | |
./hunk.lua:19: attempt to concatenate a boolean value | |
stack traceback: | |
./hunk.lua:19: in method 'parse' | |
hunk_spec.lua:12: in function <hunk_spec.lua:11> | |
Error -> hunk_spec.lua @ 11 | |
Parsing of a hunk header before_each | |
./hunk.lua:19: attempt to concatenate a boolean value | |
stack traceback: | |
./hunk.lua:19: in method 'parse' | |
hunk_spec.lua:12: in function <hunk_spec.lua:11> | |
stitny~/.l/s/n/s/p/p/s/v/ftplugin (lua *)$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment