コード例 #1
0
        public void UserFunctions02()
        {
            var completionSets = new List <CompletionSet>();
            var content        =
                @"
aaa123 <- function(a,b,c) { }
while(TRUE) {
aaa456 <- function() { }
#
aa
}";

            RCompletionTestUtilities.GetCompletions(_services, content, content.IndexOf('#') + 4, completionSets);
            completionSets.Should().ContainSingle();
            completionSets[0].Completions.Should().BeEmpty();

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(_services, content, content.IndexOf('#') + 5, completionSets);
            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            var completions = completionSets[0].Completions;

            completions.Should().NotBeEmpty();
            completions.Should().Contain(c => c.DisplayText == "aaa123");
            completions.Should().Contain(c => c.DisplayText == "aaa456");
        }
コード例 #2
0
        public void FunctionDefinition01()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(_services, "x <- function()", 14, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions.Should().BeEmpty();
        }
コード例 #3
0
        public void SuppressedCompletion(string content, int position)
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(_services, content, position, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions.Should().BeEmpty();
        }
コード例 #4
0
        public void BeforeComment()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(_services, "#No", 0, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions.Should().NotBeEmpty();
        }
コード例 #5
0
        public void Datasets()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "m", 1, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions
            .Should().Contain(c => c.DisplayText == "mtcars");
        }
コード例 #6
0
        public void BaseFunctions01()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "", 0, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions.Should().Contain(c => c.DisplayText == "abbreviate")
            .And.Contain(c => c.DisplayText == "abs");
        }
コード例 #7
0
        public void RtvsPackage()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "rtv", 3, completionSets, new TextRange(0, 3));

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();
            completionSets[0].Completions[0].DisplayText.Should().Be("rtvs");
        }
コード例 #8
0
        public void NoDuplicatesEntries()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "r", 1, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions
            .Should().ContainSingle(c => c.DisplayText == "require");
        }
コード例 #9
0
        public void CaseSensitiveEntries()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "ma", 2, completionSets);

            completionSets.Should().ContainSingle()
            .Which.Completions.Should()
            .Contain(c => c.DisplayText == "matrix").And
            .Contain(c => c.DisplayText == "Matrix");
        }
コード例 #10
0
        public void FunctionDefinition02()
        {
            for (int i = 14; i <= 18; i++)
            {
                var completionSets = new List <CompletionSet>();
                RCompletionTestUtilities.GetCompletions(_services, "x <- function(a, b)", i, completionSets);

                completionSets.Should().ContainSingle()
                .Which.Completions.Should().BeEmpty();
            }
        }
コード例 #11
0
        public void Keywords01()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(_services, "f", 1, completionSets, new TextRange(0, 1));

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().Contain(c => c.DisplayText == "for");
        }
コード例 #12
0
        public void Packages01()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "lIbrAry(", 8, completionSets);

            completionSets.Should().ContainSingle();

            completionSets[0].Completions.Should().Contain(c => c.DisplayText == "base")
            .Which.Description.Should().Be("Base R functions.");
        }
コード例 #13
0
        public void UserFunctionArgumentsNoBrace(string content, string expectedEntry)
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(_services, content, 2, content.Length - content.IndexOfOrdinal("aaa("), completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == expectedEntry);
        }
コード例 #14
0
        public void UserFunctions01()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(_services, "aaaa <- function(a,b,c)\r\na", 25, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "aaaa");
        }
コード例 #15
0
        public void BaseFunctions02()
        {
            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(EditorShell, "FAC", 3, completionSets, new TextRange(0, 3));

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions[0].DisplayText.Should().Be("factanal");
            completionSets[0].Completions[1].DisplayText.Should().Be("factor");
        }
コード例 #16
0
        public void UserVariables03()
        {
            var completionSets = new List <CompletionSet>();
            var content        =
                @"x123 <- 1
for(x456 in 1:10) x";

            RCompletionTestUtilities.GetCompletions(_services, content, 0, content.Length, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "x123")
            .And.Contain(c => c.DisplayText == "x456");
        }
コード例 #17
0
        public async Task InternalExternal(string content, int position, string expectedEntry, string notExpectedEntry)
        {
            var packageName = await FunctionIndex.GetPackageNameAsync(expectedEntry);

            packageName.Should().NotBeNull();

            var completionSets = new List <CompletionSet>();

            RCompletionTestUtilities.GetCompletions(Services, content, position, completionSets);
            completionSets.Should().ContainSingle();

            var entries = completionSets[0].Completions.Select(c => c.DisplayText).ToList();

            entries.Should().Contain(expectedEntry);
            entries.Should().NotContain(notExpectedEntry);
        }
コード例 #18
0
        public void UserFunctionArguments01()
        {
            var    completionSets = new List <CompletionSet>();
            string content        =
                @"
aaa <- function(a, b, c) { }
aaa(a
";

            RCompletionTestUtilities.GetCompletions(_services, content, 2, 5, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "a =");
        }
コード例 #19
0
        public void UserVariables02()
        {
            var completionSets = new List <CompletionSet>();
            var content        =
                @"
{

    aaa123 <- 1

    1 -> bbb123

}
";

            RCompletionTestUtilities.GetCompletions(_services, content, 2, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.NotContain(c => c.DisplayText == "aaa123")
            .And.NotContain(c => c.DisplayText == "bbb123");

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(_services, content, 4, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "aaa123")
            .And.NotContain(c => c.DisplayText == "bbb123");

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(_services, content, 6, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "aaa123")
            .And.Contain(c => c.DisplayText == "bbb123");
        }
コード例 #20
0
ファイル: PackageInstallTest.cs プロジェクト: skrutsick/RTVS
        public async Task InstallPackageTest()
        {
            await Workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo(), null, 50000);

            var completionSets = new List <CompletionSet>();

            for (int i = 0; i < 2; i++)
            {
                try {
                    await Workflow.Packages.UninstallPackageAsync("abc", null);

                    EventsPump.DoEvents(1000);
                } catch (RException) { }

                await PackageIndex.BuildIndexAsync();

                completionSets.Clear();
                RCompletionTestUtilities.GetCompletions(Services, "abc::", 5, completionSets);

                completionSets.Should().ContainSingle();
                // Try again one more time
                if (completionSets[0].Completions.Count == 0)
                {
                    break;
                }
            }
            completionSets[0].Completions.Should().BeEmpty();

            try {
                await Workflow.RSession.ExecuteAsync("install.packages('abc')", REvaluationKind.Mutating);

                EventsPump.DoEvents(1000);
            } catch (RException) { }

            await PackageIndex.BuildIndexAsync();

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(Services, "abc::", 5, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Completions.Should().NotBeEmpty();
        }
コード例 #21
0
        public void FunctionDefinition03()
        {
            for (int i = 14; i <= 19; i++)
            {
                var completionSets = new List <CompletionSet>();
                RCompletionTestUtilities.GetCompletions(_editorShell, "x <- function(a, b = x+y)", i, completionSets);

                completionSets.Should().ContainSingle()
                .Which.Completions.Should().BeEmpty();
            }

            for (int i = 20; i <= 24; i++)
            {
                var completionSets = new List <CompletionSet>();
                RCompletionTestUtilities.GetCompletions(_editorShell, "x <- function(a, b = x+y)", i, completionSets);

                completionSets.Should().NotBeEmpty();
                completionSets[0].Completions.Should().NotBeEmpty();
            }
        }
コード例 #22
0
        public void UserFunctions03()
        {
            var completionSets = new List <CompletionSet>();
            var content        =
                @"
aaa123 <- function(a,b,c) { }
while(TRUE) {

aa
aaa456 <- function() { }

aa
}
aaa789 = function(a,b,c) { }
";

            RCompletionTestUtilities.GetCompletions(_editorShell, content, 4, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            var completions = completionSets[0].Completions;

            completions.Should().NotBeEmpty();
            completions.Should().Contain(c => c.DisplayText == "aaa123");
            completions.Should().NotContain(c => c.DisplayText == "aaa456");
            completions.Should().Contain(c => c.DisplayText == "aaa789");

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(_editorShell, content, 7, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completions = completionSets[0].Completions;
            completions.Should().NotBeEmpty();
            completions.Should().Contain(c => c.DisplayText == "aaa123");
            completions.Should().Contain(c => c.DisplayText == "aaa456");
            completions.Should().Contain(c => c.DisplayText == "aaa789");
        }
コード例 #23
0
        public void UserVariables01()
        {
            var completionSets = new List <CompletionSet>();
            var content        =
                @"
aaa123 <- 1

bbb123 = 1

";

            RCompletionTestUtilities.GetCompletions(_editorShell, content, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "aaa123")
            .And.Contain(c => c.DisplayText == "bbb123");

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(_editorShell, content, 2, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "aaa123")
            .And.Contain(c => c.DisplayText == "bbb123");

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(_editorShell, content, 4, 0, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Filter();

            completionSets[0].Completions.Should().NotBeEmpty()
            .And.Contain(c => c.DisplayText == "aaa123")
            .And.Contain(c => c.DisplayText == "bbb123");
        }
コード例 #24
0
        public async Task SpecificPackage(string content, int position, string expectedEntry, string expectedDescription, bool realHost)
        {
            var hostScript = realHost ? new RHostScript(Workflow.RSessions) : null;

            try {
                var info = await FunctionIndex.GetFunctionInfoAsync(expectedEntry);

                info.Should().NotBeNull();

                var completionSets = new List <CompletionSet>();
                RCompletionTestUtilities.GetCompletions(EditorShell, content, position, completionSets);

                completionSets.Should().ContainSingle();

                var entry = completionSets[0].Completions.FirstOrDefault(c => c.DisplayText == expectedEntry);
                entry.Should().NotBeNull();

                var description = entry.Description;
                description.Should().Contain(expectedDescription);
            } finally {
                hostScript?.Dispose();
            }
        }