|
| 1 | +local git = require("neo-tree.git") |
| 2 | +local utils = require("neo-tree.utils") |
| 3 | +local test_utils = require("tests.utils") |
| 4 | +local gsplit_plain = vim.fn.has("nvim-0.9") == 1 and { plain = true } or true |
| 5 | +describe("git parser", function() |
| 6 | + describe("parses v2 output", function() |
| 7 | + local porcelain_v2_status = { |
| 8 | + "1 D. N... 100644 000000 000000 ade2881afa1dcb156a3aa576024aa0fecf789191 0000000000000000000000000000000000000000 deleted_staged.txt", |
| 9 | + "1 .D N... 100644 100644 000000 9c13483e67ceff219800303ec7af39c4f0301a5b 9c13483e67ceff219800303ec7af39c4f0301a5b deleted_unstaged.txt", |
| 10 | + "1 MM N... 100644 100644 100644 4417f3aca512ffdf247662e2c611ee03ff9255cc 29c0e9846cd6410a44c4ca3fdaf5623818bd2838 modified_mixed.txt", |
| 11 | + "1 M. N... 100644 100644 100644 f784736eecdd43cd8eb665615163cfc6506fca5f 8d6fad5bd11ac45c7c9e62d4db1c427889ed515b modified_staged.txt", |
| 12 | + "1 .M N... 100644 100644 100644 c9e1e027aa9430cb4ffccccf45844286d10285c1 c9e1e027aa9430cb4ffccccf45844286d10285c1 modified_unstaged.txt", |
| 13 | + "1 A. N... 000000 100644 100644 0000000000000000000000000000000000000000 89cae60d74c222609086441e29985f959b6ec546 new_staged_file.txt", |
| 14 | + "2 R. N... 100644 100644 100644 3454a7dc6b93d1098e3c3f3ec369589412abdf99 3454a7dc6b93d1098e3c3f3ec369589412abdf99 R100 renamed_staged_new.txt", |
| 15 | + "renamed_staged_old.txt", |
| 16 | + "1 .T N... 100644 100644 120000 192f10ed8c11efb70155e8eb4cae6ec677347623 192f10ed8c11efb70155e8eb4cae6ec677347623 type_change.txt", |
| 17 | + "? .gitignore", |
| 18 | + "? untracked.txt", |
| 19 | + } |
| 20 | + |
| 21 | + local test = function() |
| 22 | + local old = utils.is_windows |
| 23 | + local iter = coroutine.wrap(function() |
| 24 | + for i, s in ipairs(porcelain_v2_status) do |
| 25 | + coroutine.yield(s) |
| 26 | + end |
| 27 | + end) |
| 28 | + local git_root = utils.is_windows and "C:\\" or "/asdf" |
| 29 | + local status = git._parse_porcelain(2, git_root, iter, {}) |
| 30 | + assert.are.same({ |
| 31 | + [utils.path_join(git_root, ".gitignore")] = "?", |
| 32 | + [utils.path_join(git_root, "deleted_staged.txt")] = "D.", |
| 33 | + [utils.path_join(git_root, "deleted_unstaged.txt")] = ".D", |
| 34 | + [utils.path_join(git_root, "modified_mixed.txt")] = "MM", |
| 35 | + [utils.path_join(git_root, "modified_staged.txt")] = "M.", |
| 36 | + [utils.path_join(git_root, "modified_unstaged.txt")] = ".M", |
| 37 | + [utils.path_join(git_root, "new_staged_file.txt")] = "A.", |
| 38 | + [utils.path_join(git_root, "renamed_staged_new.txt")] = "R100", |
| 39 | + [utils.path_join(git_root, "type_change.txt")] = ".T", |
| 40 | + [utils.path_join(git_root, "untracked.txt")] = "?", |
| 41 | + }, status) |
| 42 | + end |
| 43 | + |
| 44 | + local old = utils.on_windows |
| 45 | + utils.on_windows = false |
| 46 | + it("on unix", test) |
| 47 | + utils.on_windows = true |
| 48 | + it("on windows", test) |
| 49 | + utils.on_windows = old |
| 50 | + end) |
| 51 | + |
| 52 | + describe("parses v1 output", function() |
| 53 | + local porcelain_v1_status = { |
| 54 | + "1 D. N... 100644 000000 000000 ade2881afa1dcb156a3aa576024aa0fecf789191 0000000000000000000000000000000000000000 deleted_staged.txt", |
| 55 | + "1 .D N... 100644 100644 000000 9c13483e67ceff219800303ec7af39c4f0301a5b 9c13483e67ceff219800303ec7af39c4f0301a5b deleted_unstaged.txt", |
| 56 | + "1 MM N... 100644 100644 100644 4417f3aca512ffdf247662e2c611ee03ff9255cc 29c0e9846cd6410a44c4ca3fdaf5623818bd2838 modified_mixed.txt", |
| 57 | + "1 M. N... 100644 100644 100644 f784736eecdd43cd8eb665615163cfc6506fca5f 8d6fad5bd11ac45c7c9e62d4db1c427889ed515b modified_staged.txt", |
| 58 | + "1 .M N... 100644 100644 100644 c9e1e027aa9430cb4ffccccf45844286d10285c1 c9e1e027aa9430cb4ffccccf45844286d10285c1 modified_unstaged.txt", |
| 59 | + "1 A. N... 000000 100644 100644 0000000000000000000000000000000000000000 89cae60d74c222609086441e29985f959b6ec546 new_staged_file.txt", |
| 60 | + "2 R. N... 100644 100644 100644 3454a7dc6b93d1098e3c3f3ec369589412abdf99 3454a7dc6b93d1098e3c3f3ec369589412abdf99 R100 renamed_staged_new.txt", |
| 61 | + "renamed_staged_old.txt", |
| 62 | + "1 .T N... 100644 100644 120000 192f10ed8c11efb70155e8eb4cae6ec677347623 192f10ed8c11efb70155e8eb4cae6ec677347623 type_change.txt", |
| 63 | + "? .gitignore", |
| 64 | + "? untracked.txt", |
| 65 | + } |
| 66 | + local test = function() |
| 67 | + local iter = coroutine.wrap(function() |
| 68 | + for i, s in ipairs(porcelain_v1_status) do |
| 69 | + coroutine.yield(s) |
| 70 | + end |
| 71 | + end) |
| 72 | + local git_root = utils.is_windows and "C:\\" or "/asdf" |
| 73 | + local status = git._parse_porcelain(2, git_root, iter, {}) |
| 74 | + assert.are.same({ |
| 75 | + [utils.path_join(git_root, ".gitignore")] = "?", |
| 76 | + [utils.path_join(git_root, "deleted_staged.txt")] = "D.", |
| 77 | + [utils.path_join(git_root, "deleted_unstaged.txt")] = ".D", |
| 78 | + [utils.path_join(git_root, "modified_mixed.txt")] = "MM", |
| 79 | + [utils.path_join(git_root, "modified_staged.txt")] = "M.", |
| 80 | + [utils.path_join(git_root, "modified_unstaged.txt")] = ".M", |
| 81 | + [utils.path_join(git_root, "new_staged_file.txt")] = "A.", |
| 82 | + [utils.path_join(git_root, "renamed_staged_new.txt")] = "R100", |
| 83 | + [utils.path_join(git_root, "type_change.txt")] = ".T", |
| 84 | + [utils.path_join(git_root, "untracked.txt")] = "?", |
| 85 | + }, status) |
| 86 | + end |
| 87 | + local restore = test_utils.os_to_windows(false) |
| 88 | + it("on unix", test) |
| 89 | + test_utils.os_to_windows(true) |
| 90 | + it("on windows", test) |
| 91 | + restore() |
| 92 | + end) |
| 93 | +end) |
0 commit comments