|
| 1 | +local fixtures = require("tests.utils.fixtures") |
| 2 | +local utils = require("hunk.utils") |
| 3 | +local fs = require("hunk.api.fs") |
| 4 | +local api = require("hunk.api") |
| 5 | + |
| 6 | +local function create_symlink(dst, source) |
| 7 | + vim.fn.system({ "ln", "-s", source, dst }) |
| 8 | +end |
| 9 | + |
| 10 | +local function prepare_symlinks(workspace) |
| 11 | + fs.write_file(workspace.left .. "/had-content", { "1", "2", "3" }) |
| 12 | + create_symlink(workspace.left .. "/was-symlink1", "some-target") |
| 13 | + create_symlink(workspace.left .. "/was-symlink2", "some-target") |
| 14 | + |
| 15 | + create_symlink(workspace.right .. "/had-content", "some-target") |
| 16 | + fs.write_file(workspace.right .. "/was-symlink1", { "1", "2", "3" }) |
| 17 | + create_symlink(workspace.right .. "/new-symlink", "some-target2") |
| 18 | + |
| 19 | + create_symlink(workspace.output .. "/had-content", "some-target") |
| 20 | + fs.write_file(workspace.output .. "/was-symlink1", { "1", "2", "3" }) |
| 21 | + create_symlink(workspace.output .. "/new-symlink", "some-target2") |
| 22 | +end |
| 23 | + |
| 24 | +describe("symlinks", function() |
| 25 | + it("should correctly load a changeset with symlinks", function() |
| 26 | + fixtures.with_workspace(function(workspace) |
| 27 | + prepare_symlinks(workspace) |
| 28 | + |
| 29 | + local changeset, files = api.changeset.load_changeset(workspace.left, workspace.right) |
| 30 | + |
| 31 | + it("contains all files from both sides of diff", function() |
| 32 | + assert.is_true(utils.included_in_table(files, "had-content"), "missing had-content") |
| 33 | + assert.is_true(utils.included_in_table(files, "was-symlink1"), "missing was-symlink1") |
| 34 | + assert.is_true(utils.included_in_table(files, "was-symlink2"), "missing was-symlink2") |
| 35 | + assert.is_true(utils.included_in_table(files, "new-symlink"), "missing new-symlink") |
| 36 | + assert.are.equal(#files, 4) |
| 37 | + end) |
| 38 | + |
| 39 | + it("creates a correct had-content change", function() |
| 40 | + local change = changeset["had-content"] |
| 41 | + assert.are.equal(nil, change.left_file.symlink) |
| 42 | + assert.are.equal("some-target", change.right_file.symlink) |
| 43 | + assert.are.equal("modified", change.type) |
| 44 | + assert.are.same({}, change.hunks) |
| 45 | + end) |
| 46 | + |
| 47 | + it("creates a correct was-symlink change", function() |
| 48 | + local change = changeset["was-symlink1"] |
| 49 | + assert.are.equal("some-target", change.left_file.symlink) |
| 50 | + assert.are.equal(nil, change.right_file.symlink) |
| 51 | + assert.are.equal("modified", change.type) |
| 52 | + assert.are.same({}, change.hunks) |
| 53 | + end) |
| 54 | + |
| 55 | + it("creates a correct was-symlink change", function() |
| 56 | + local change = changeset["was-symlink2"] |
| 57 | + assert.are.equal("some-target", change.left_file.symlink) |
| 58 | + assert.are.equal(nil, change.right_file.symlink) |
| 59 | + assert.are.equal("deleted", change.type) |
| 60 | + assert.are.same({}, change.hunks) |
| 61 | + end) |
| 62 | + |
| 63 | + it("creates a correct was-symlink change", function() |
| 64 | + local change = changeset["new-symlink"] |
| 65 | + assert.are.equal(nil, change.left_file.symlink) |
| 66 | + assert.are.equal("some-target2", change.right_file.symlink) |
| 67 | + assert.are.equal("added", change.type) |
| 68 | + assert.are.same({}, change.hunks) |
| 69 | + end) |
| 70 | + end) |
| 71 | + end) |
| 72 | +end) |
0 commit comments