From 148a67f44c5e964a631f7e21717fb73186f7fbbc Mon Sep 17 00:00:00 2001 From: majocha Date: Tue, 28 Feb 2023 09:39:39 +0100 Subject: [PATCH] initial tests for NavigateToSearchService --- .../FSharp.Editor.Tests.fsproj | 1 + .../NavigateToSearchServiceTests.fs | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 vsintegration/tests/FSharp.Editor.Tests/NavigateToSearchServiceTests.fs diff --git a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj index 7c45d65bbce..7a1700a3711 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj +++ b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj @@ -28,6 +28,7 @@ + diff --git a/vsintegration/tests/FSharp.Editor.Tests/NavigateToSearchServiceTests.fs b/vsintegration/tests/FSharp.Editor.Tests/NavigateToSearchServiceTests.fs new file mode 100644 index 00000000000..a1c16499dbc --- /dev/null +++ b/vsintegration/tests/FSharp.Editor.Tests/NavigateToSearchServiceTests.fs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Editor.Tests + +open Xunit +open System.Threading +open Microsoft.CodeAnalysis.Text +open Microsoft.VisualStudio.FSharp.Editor +open FSharp.Compiler.Text +open FSharp.Editor.Tests.Helpers +open Microsoft.CodeAnalysis.ExternalAccess.FSharp.NavigateTo + +module NavigateToSearchServiceTests = + + let fileContents = + """ +module HeyHo = + let inline (+>) f c = f c + + let Żółwik żwawy = () + + let ``a few words`` = 0 + + let one' = 1 + let two'' = 2 + + type CamelCaseLongName = class end +""" + + let sourceText = SourceText.From(fileContents) + + let solution = RoslynTestHelpers.CreateSolution(fileContents) + let project = solution.Projects |> Seq.exactlyOne + let provider = MefHelpers.createExportProvider () + + let navigateToSearch pattern = + let service: IFSharpNavigateToSearchService = provider.GetExportedValue() + + service + .SearchProjectAsync( + project, + [] |> Seq.toImmutableArray, + pattern, + service.KindsProvided, + CancellationToken.None + ) + .Result + + let assertResultsContain pattern expected = + navigateToSearch pattern + |> Seq.exists (fun i -> i.Name = expected) + |> Assert.True + + [] + let ``unicode symbols`` () = assertResultsContain "Żó" "Żółwik" + + [] + let ``capitalized camel case`` () = + assertResultsContain "CLN" "CamelCaseLongName" + + [] + let ``lower camel case`` () = + assertResultsContain "cln" "CamelCaseLongName" + + [] + let ``substring`` () = assertResultsContain "ne'" "one'" + + [] + let ``backticked identifier`` () = + assertResultsContain "a few words" "a few words" + + [] + let ``operator`` () = assertResultsContain "+>" "+>"