Skip to content

Commit e377608

Browse files
committed
debug ci tests
1 parent b17c61f commit e377608

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

lua/plenary/path2.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function _WindowsPath:expand(parts, sep)
222222
local new_parts = {}
223223
for _, part in ipairs(parts) do
224224
part = part:gsub(pattern, function(m)
225-
local var_name = m:sub(2):sub(1, -2)
225+
local var_name = m:sub(2, -2)
226226

227227
---@diagnostic disable-next-line: missing-parameter
228228
local var = uv.os_getenv(var_name)
@@ -1376,8 +1376,8 @@ function Path:tail(lines)
13761376
return (table.concat(data):gsub("[\r\n]$", ""))
13771377
end
13781378

1379-
---@param offset integer
1380-
---@param length integer
1379+
---@param offset integer byte offset from which the file is read, supports negative index
1380+
---@param length integer number of bytes to read from the offset
13811381
---@return string
13821382
function Path:readbyterange(offset, length)
13831383
vim.validate {
@@ -1403,7 +1403,6 @@ function Path:readbyterange(offset, length)
14031403
local data = ""
14041404
local read_chunk
14051405
while #data < length do
1406-
-- local read_chunk = assert(uv.fs_read(fd, length - #data, offset))
14071406
read_chunk, err = uv.fs_read(fd, length - #data, offset)
14081407
if read_chunk == nil then
14091408
error(err)

tests/plenary/path2_spec.lua

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -932,14 +932,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
932932
copies of the Software, and to permit persons to whom the Software is
933933
furnished to do so, subject to the following conditions:]]
934934

935-
assert.are.same(should, data)
935+
assert.are.same(should, data, diff_str(should, data))
936936
end)
937937

938938
it_cross_plat("should read the first line of file", function()
939939
local p = Path:new "LICENSE"
940940
local data = p:head(1)
941941
local should = [[MIT License]]
942-
assert.are.same(should, data)
942+
assert.are.same(should, data, diff_str(should, data))
943943
end)
944944

945945
it_cross_plat("should max read whole file", function()
@@ -966,7 +966,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
966966
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
967967
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
968968
SOFTWARE.]]
969-
assert.are.same(should, data)
969+
assert.are.same(should, data, diff_str(should, data))
970970
end)
971971

972972
it_cross_plat("handles unix lf line endings", function()
@@ -1018,14 +1018,14 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
10181018
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10191019
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10201020
SOFTWARE.]]
1021-
assert.are.same(should, data)
1021+
assert.are.same(should, data, diff_str(should, data))
10221022
end)
10231023

10241024
it_cross_plat("should read the last line of file", function()
10251025
local p = Path:new "LICENSE"
10261026
local data = p:tail(1)
10271027
local should = [[SOFTWARE.]]
1028-
assert.are.same(should, data)
1028+
assert.are.same(should, data, diff_str(should, data))
10291029
end)
10301030

10311031
it_cross_plat("should max read whole file", function()
@@ -1052,7 +1052,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
10521052
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10531053
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10541054
SOFTWARE.]]
1055-
assert.are.same(should, data)
1055+
assert.are.same(should, data, diff_str(should, data))
10561056
end)
10571057

10581058
it_cross_plat("handles unix lf line endings", function()
@@ -1098,18 +1098,72 @@ SOFTWARE.]]
10981098
end)
10991099

11001100
describe("readbyterange", function()
1101+
after_each(function()
1102+
uv.fs_unlink "foobar.txt"
1103+
end)
1104+
11011105
it_cross_plat("should read bytes at given offset", function()
11021106
local p = Path:new "LICENSE"
11031107
local data = p:readbyterange(13, 10)
11041108
local should = "Copyright "
1105-
assert.are.same(should, data)
1109+
assert.are.same(should, data, diff_str(should, data))
11061110
end)
11071111

11081112
it_cross_plat("supports negative offset", function()
11091113
local p = Path:new "LICENSE"
11101114
local data = p:readbyterange(-10, 10)
11111115
local should = "SOFTWARE.\n"
1112-
assert.are.same(should, data)
1116+
assert.are.same(should, data, diff_str(should, data))
1117+
end)
1118+
1119+
it_cross_plat("handles unix lf line endings", function()
1120+
local p = Path:new "foobar.txt"
1121+
p:touch()
1122+
1123+
local txt = "foo\nbar\nbaz"
1124+
p:write(txt, "w")
1125+
local data = p:readbyterange(3, 5)
1126+
local expect = "\nbar\n"
1127+
assert.are.same(expect, data, diff_str(expect, data))
1128+
end)
1129+
1130+
it_cross_plat("handles windows crlf line endings", function()
1131+
local p = Path:new "foobar.txt"
1132+
p:touch()
1133+
1134+
local txt = "foo\r\nbar\r\nbaz"
1135+
p:write(txt, "w")
1136+
local data = p:readbyterange(3, 5)
1137+
local expect = "\r\nbar"
1138+
assert.are.same(expect, data, diff_str(expect, data))
1139+
end)
1140+
1141+
it_cross_plat("handles mac cr line endings", function()
1142+
local p = Path:new "foobar.txt"
1143+
p:touch()
1144+
1145+
local txt = "foo\rbar\rbaz"
1146+
p:write(txt, "w")
1147+
local data = p:readbyterange(3, 5)
1148+
local expect = "\rbar\r"
1149+
assert.are.same(expect, data, diff_str(expect, data))
1150+
end)
1151+
1152+
it_cross_plat("offset larger than size", function()
1153+
local p = Path:new "foobar.txt"
1154+
p:touch()
1155+
1156+
local txt = "hello"
1157+
p:write(txt, "w")
1158+
local data = p:readbyterange(10, 3)
1159+
assert.are.same("", data)
1160+
end)
1161+
1162+
it_cross_plat("no offset", function()
1163+
local p = Path:new "LICENSE"
1164+
local data = p:readbyterange(0, 11)
1165+
local should = "MIT License"
1166+
assert.are.same(should, data, diff_str(should, data))
11131167
end)
11141168
end)
11151169

@@ -1129,13 +1183,14 @@ SOFTWARE.]]
11291183
end)
11301184

11311185
it_cross_plat("doesn't find file", function()
1132-
local p = Path:new "."
1186+
local p = Path:new(path.root())
11331187
local res = p:find_upwards "aisohtenaishoetnaishoetnasihoetnashitoen"
11341188
assert.is_nil(res)
11351189
end)
11361190
end)
11371191

11381192
describe("expand", function()
1193+
uv.os_setenv("FOOVAR", "foo")
11391194
uv.os_setenv("BARVAR", "bar")
11401195

11411196
describe("unix", function()
@@ -1144,7 +1199,7 @@ SOFTWARE.]]
11441199
end
11451200

11461201
it("match valid env var", function()
1147-
local p = Path:new "foo/$BARVAR/baz"
1202+
local p = Path:new "$FOOVAR/$BARVAR/baz"
11481203
assert.are.same("foo/bar/baz", p:expand())
11491204
end)
11501205

@@ -1160,7 +1215,7 @@ SOFTWARE.]]
11601215
end
11611216

11621217
it_win("match valid env var", function()
1163-
local p = Path:new "foo/%BARVAR%/baz"
1218+
local p = Path:new "%foovar%/%BARVAR%/baz"
11641219
local expect = Path:new "foo/bar/baz"
11651220
assert.are.same(expect.filename, p:expand())
11661221
end)

0 commit comments

Comments
 (0)