public void CanCompleteGitSwitchBranch()
        {
            using var scope = FakeGit.GetScope();
            var res = "git switch ".CompleteInput();

            Assert.AreEqual("buildfix", res[0].CompletionText);
        }
        public void CanCompleteGitDiffFiles()
        {
            using var scope = FakeGit.GetScope();
            var res = "git diff -- ".CompleteInput();

            Assert.AreEqual("src/PSGitCompletions/Git.cs", res[0].CompletionText);
        }
        public void CanCompleteBisect(string command, string firstResult)
        {
            using var scope = FakeGit.GetScope();
            var res = command.CompleteInput();

            Assert.AreEqual(firstResult, res[0].CompletionText);
        }
        public void CanCompleteGitCommandPart()
        {
            using var scope = FakeGit.GetScope();
            var res = "git ad".CompleteInput();

            Assert.AreEqual("add", res[0].CompletionText);
        }
        public void CanCompleteGitDiffCommits()
        {
            using var scope = FakeGit.GetScope();
            var res = "git diff ".CompleteInput();

            Assert.AreEqual("afcff36", res[0].CompletionText);
            Assert.AreEqual("adding resharper settings to gitignore", res[0].ToolTip);
        }
        public void CanCompleteGitCommandOptions()
        {
            using var scope = FakeGit.GetScope();
            var res = "git add -".CompleteInput();

            Assert.AreEqual("--", res[0].CompletionText);
            Assert.AreEqual("--all", res[1].CompletionText);
        }
        public void CanCompleteFetchOriginRef()
        {
            using var scope = FakeGit.GetScope();

            var completions = "git fetch origin ".CompleteInput();

            Assert.AreEqual(2, completions.Count);
            Assert.AreEqual("origin", completions[0].CompletionText);
        }
        public void CanCompleteGetGitFetchRemote()
        {
            using var scope = FakeGit.GetScope();

            var completions = "git fetch ".CompleteInput();

            Assert.AreEqual(2, completions.Count);
            Assert.AreEqual("upstream", completions[1].CompletionText);
        }
        public void CanCompleteCheckoutFiles(string command, string firstResult, int resultCount)
        {
            using var scope = FakeGit.GetScope();

            var completions = command.CompleteInput();

            Assert.AreEqual(resultCount, completions.Count);
            Assert.AreEqual(firstResult, completions[0].CompletionText);
        }
        public void CanCompleteGitCommands()
        {
            using var scope = FakeGit.GetScope();
            var res = "git ".CompleteInput();

            Assert.AreEqual("add", res[0].CompletionText);
            var diff = res.FirstOrDefault(c => c.CompletionText == "diff");

            Assert.IsNotNull(diff);
        }
        public void CanGetBranchDescriptions()
        {
            using var scope = FakeGit.GetScope();

            var desc = Git.BranchDescriptions().ToDictionary(c => c.Name, b => b.Description);

            Assert.AreEqual(3, desc.Count);
            Assert.AreEqual("Main branch\r\nThis is the branch that releases are made from", desc["master"]);
            Assert.AreEqual("Some other branch\r\n", desc["other"]);
        }
        public void CanGetGitRemoteUrls()
        {
            using var scope = FakeGit.GetScope();

            var remoteRefs = Git.Remotes().ToArray();

            Assert.AreEqual("origin", remoteRefs[0].Name);
            Assert.AreEqual("https://github.com/powershell/PowerShell (fetch)", remoteRefs[1].FetchUrl);
            Assert.AreEqual("https://github.com/powershell/PowerShell (fetch)", remoteRefs[1].FetchUrl);
        }
        public void CanParseCompletionInfo(string command, string commandName, bool afterDoubleDash, bool isCompletingParameterName, string?previousParameterName, string?previousParameterValue, string wordToComplete = "", bool isCompletingCommand = false, int cursorPosition = -1)
        {
            using var scope = FakeGit.GetScope();

            var res = command.CreateCompleteCommandParameters();

            Assert.AreEqual(commandName, res.CommandName, "Expected same command name");
            Assert.AreEqual(afterDoubleDash, res.AfterDoubleDash, "Expected correct AfterDoubleDash");
            Assert.AreEqual(isCompletingParameterName, res.IsCompletingParameterName, "Expected correct IsCopmpletingParameterName");
            Assert.AreEqual(previousParameterName, res.PreviousParameterName, "Expected correct PreviousParameterName");
            Assert.AreEqual(previousParameterValue, res.PreviousParameterValue, "Expected correct PreviousParameterValue");
            Assert.AreEqual(wordToComplete, res.WordToComplete, "Expected correct WordToComplete");
            Assert.AreEqual(isCompletingCommand, res.IsCompletingCommand, "Expected correct IsCompletingCommand");
            if (cursorPosition > 0)
            {
                Assert.AreEqual(cursorPosition, res.CursorPosition, "Expected correct IsCompletingCommand");
            }
        }
        public void TestPSTabExpansion(string command, string firstMatch)
        {
            using var scope = FakeGit.GetScope();

            InitialSessionState iss = InitialSessionState.CreateDefault();
            var codeBaseUrl         = new Uri(typeof(Git).Assembly.Location);
            var codeBasePath        = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);

            iss.ImportPSModule(new [] { codeBasePath });
            //iss.Commands.Add(new SessionStateFunctionEntry("TabExpansion2", TabExpansionFunction));
            using var ps = PowerShell.Create(iss);
            Assert.IsFalse(ps.HadErrors, string.Join(Environment.NewLine, ps.Streams.Error.ReadAll().Select(e => e.Exception.Message)));

            ps.AddScript($"Import-Module {codeBasePath}", true).Invoke();
            Assert.IsFalse(ps.HadErrors, string.Join(Environment.NewLine, ps.Streams.Error.ReadAll().Select(e => e.Exception.Message)));

            ps.AddScript($"TabExpansion2 -inputScript '{command}' -cursorColumn {command.Length}");

            var res = (CommandCompletion)(ps.Invoke()[0].BaseObject);

            Assert.IsFalse(ps.HadErrors, string.Join(Environment.NewLine, ps.Streams.Error.ReadAll().Select(e => e.Exception.Message)));
            Assert.IsTrue(res.CompletionMatches.Count > 0);
            Assert.AreEqual(firstMatch, res.CompletionMatches[0].CompletionText);
        }