forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go To Definition int tests (dotnet#14855)
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
vsintegration/tests/FSharp.Editor.IntegrationTests/Extensions/IBufferGraphExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Projection; | ||
|
||
namespace FSharp.Editor.IntegrationTests.Extensions; | ||
|
||
internal static class IBufferGraphExtensions | ||
{ | ||
public static SnapshotSpan? MapUpOrDownToFirstMatch(this IBufferGraph bufferGraph, SnapshotSpan span, Predicate<ITextSnapshot> match) | ||
{ | ||
var spans = bufferGraph.MapDownToFirstMatch(span, SpanTrackingMode.EdgeExclusive, match); | ||
if (!spans.Any()) | ||
{ | ||
spans = bufferGraph.MapUpToFirstMatch(span, SpanTrackingMode.EdgeExclusive, match); | ||
} | ||
|
||
return spans.Select(s => (SnapshotSpan?)s).FirstOrDefault(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
vsintegration/tests/FSharp.Editor.IntegrationTests/Extensions/ITextViewExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Utilities; | ||
|
||
namespace FSharp.Editor.IntegrationTests.Extensions; | ||
|
||
internal static class ITextViewExtensions | ||
{ | ||
public static SnapshotPoint? GetCaretPoint(this ITextView textView, Predicate<ITextSnapshot> match) | ||
{ | ||
var caret = textView.Caret.Position; | ||
var span = textView.BufferGraph.MapUpOrDownToFirstMatch(new SnapshotSpan(caret.BufferPosition, 0), match); | ||
if (span.HasValue) | ||
{ | ||
return span.Value.Start; | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public static ITextBuffer? GetBufferContainingCaret(this ITextView textView, string contentType = StandardContentTypeNames.Text) | ||
{ | ||
var point = textView.GetCaretPoint(s => s.ContentType.IsOfType(contentType)); | ||
return point.HasValue ? point.Value.Snapshot.TextBuffer : null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
vsintegration/tests/FSharp.Editor.IntegrationTests/GoToDefinitionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.CodeAnalysis.Testing; | ||
using Microsoft.VisualStudio.Extensibility.Testing; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using static Microsoft.VisualStudio.VSConstants; | ||
|
||
namespace FSharp.Editor.IntegrationTests; | ||
|
||
public class GoToDefinitionTests : AbstractIntegrationTest | ||
{ | ||
[IdeFact] | ||
public async Task GoesToDefinition_Async() | ||
{ | ||
var token = HangMitigatingCancellationToken; | ||
var template = WellKnownProjectTemplates.FSharpNetCoreClassLibrary; | ||
|
||
var solutionExplorer = TestServices.SolutionExplorer; | ||
var editor = TestServices.Editor; | ||
var shell = TestServices.Shell; | ||
var workspace = TestServices.Workspace; | ||
|
||
var code = """ | ||
module Test | ||
let add x y = x + y | ||
let increment = add 1 | ||
"""; | ||
var expectedText = "let add x y = x + y"; | ||
|
||
await solutionExplorer.CreateSolutionAsync(nameof(GoToDefinitionTests), token); | ||
await solutionExplorer.AddProjectAsync("Library", template, token); | ||
await solutionExplorer.RestoreNuGetPackagesAsync(token); | ||
await editor.SetTextAsync(code, token); | ||
|
||
await editor.PlaceCaretAsync("add 1", token); | ||
await shell.ExecuteCommandAsync(VSStd97CmdID.GotoDefn, token); | ||
var actualText = await editor.GetCurrentLineTextAsync(token); | ||
|
||
Assert.Contains(expectedText, actualText); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters