-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for textDocument/definition (#201)
* Add tests for textDocument/definition * .github/workflows: bump sdk to 8.0.404 * tests/CSharpLanguageServer.Tests/Tooling.fs: don't delete temporary project dir when under GitHub Actions C/I * tests/CSharpLanguageServer.Tests/Tooling.fs: bump timeout to 60 secs in WaitForProgressEnd
- Loading branch information
1 parent
aab7156
commit bd0f4bf
Showing
12 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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,76 @@ | ||
module CSharpLanguageServer.Tests.DefinitionTests | ||
|
||
open NUnit.Framework | ||
open Ionide.LanguageServerProtocol.Types | ||
|
||
open CSharpLanguageServer.Tests.Tooling | ||
open System | ||
|
||
[<TestCase>] | ||
let testDefinitionWorks () = | ||
use client = setupServerClient defaultClientProfile "TestData/testDefinitionWorks" | ||
client.StartAndWaitForSolutionLoad() | ||
|
||
use classFile = client.Open("Project/Class.cs") | ||
|
||
let definitionParams0: DefinitionParams = | ||
{ TextDocument = { Uri = classFile.Uri } | ||
Position = { Line = 0u; Character = 0u } | ||
WorkDoneToken = None | ||
PartialResultToken = None | ||
} | ||
|
||
let declaration0: Declaration option = classFile.Request("textDocument/definition", definitionParams0) | ||
Assert.IsTrue(declaration0.IsNone) | ||
|
||
let definitionParams1: DefinitionParams = | ||
{ TextDocument = { Uri = classFile.Uri } | ||
Position = { Line = 2u; Character = 16u } | ||
WorkDoneToken = None | ||
PartialResultToken = None | ||
} | ||
|
||
let declaration1: Declaration option = classFile.Request("textDocument/definition", definitionParams1) | ||
|
||
match declaration1.Value with | ||
| U2.C1 _ -> failwith "Location[] was expected" | ||
| U2.C2 declaration1Locations -> | ||
let expectedLocations1: Location array = | ||
[| | ||
{ Uri = classFile.Uri | ||
Range = { Start = { Line = 2u; Character = 16u } | ||
End = { Line = 2u; Character = 23u } } | ||
} | ||
|] | ||
|
||
Assert.AreEqual(expectedLocations1, declaration1Locations) | ||
|
||
[<TestCase>] | ||
let testDefinitionWorksInAspNetProject () = | ||
use client = setupServerClient defaultClientProfile | ||
"TestData/testDefinitionWorksInAspNetProject" | ||
client.StartAndWaitForSolutionLoad() | ||
|
||
use indexCsHtmlCs = client.Open("Project/Pages/Index.cshtml.cs") | ||
|
||
let definitionParams1: DefinitionParams = | ||
{ TextDocument = { Uri = indexCsHtmlCs.Uri } | ||
Position = { Line = 7u; Character = 8u } | ||
WorkDoneToken = None | ||
PartialResultToken = None | ||
} | ||
|
||
let declaration1: Declaration option = indexCsHtmlCs.Request("textDocument/definition", definitionParams1) | ||
|
||
match declaration1.Value with | ||
| U2.C1 _ -> failwith "Location[] was expected" | ||
| U2.C2 declaration1Locations -> | ||
let expectedLocations1: Location array = | ||
[| | ||
{ Uri = indexCsHtmlCs.Uri | ||
Range = { Start = { Line = 4u; Character = 19u } | ||
End = { Line = 4u; Character = 24u } } | ||
} | ||
|] | ||
|
||
Assert.AreEqual(expectedLocations1, declaration1Locations) | ||
Check warning on line 76 in tests/CSharpLanguageServer.Tests/DefinitionTests.fs GitHub Actions / build (windows-latest, 8.0.404)
Check warning on line 76 in tests/CSharpLanguageServer.Tests/DefinitionTests.fs GitHub Actions / build (windows-latest, 8.0.404)
Check warning on line 76 in tests/CSharpLanguageServer.Tests/DefinitionTests.fs GitHub Actions / build (ubuntu-24.04, 8.0.404)
|
11 changes: 11 additions & 0 deletions
11
tests/CSharpLanguageServer.Tests/TestData/testDefinitionWorks/Project/Class.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,11 @@ | ||
class Class | ||
{ | ||
public void MethodA(string arg) | ||
{ | ||
} | ||
|
||
public void MethodB(string arg) | ||
{ | ||
MethodA(arg); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/CSharpLanguageServer.Tests/TestData/testDefinitionWorks/Project/Project.csproj
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,6 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
3 changes: 3 additions & 0 deletions
3
...nguageServer.Tests/TestData/testDefinitionWorksInAspNetProject/Project/Pages/Index.cshtml
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,3 @@ | ||
@page | ||
@model IndexModel | ||
<div>@Model.Value</div> |
10 changes: 10 additions & 0 deletions
10
...ageServer.Tests/TestData/testDefinitionWorksInAspNetProject/Project/Pages/Index.cshtml.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,10 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
namespace test_csharp_web.Pages; | ||
public class IndexModel : PageModel | ||
{ | ||
public string? Value { get; set; } | ||
public void OnGet() | ||
{ | ||
Value = "test"; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...erver.Tests/TestData/testDefinitionWorksInAspNetProject/Project/Pages/_ViewImports.cshtml
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,3 @@ | ||
@using test_csharp_web | ||
@namespace test_csharp_web.Pages | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
7 changes: 7 additions & 0 deletions
7
...CSharpLanguageServer.Tests/TestData/testDefinitionWorksInAspNetProject/Project/Program.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,7 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.AddRazorPages(); | ||
|
||
var app = builder.Build(); | ||
app.UseRouting(); | ||
app.MapRazorPages(); | ||
app.Run(); |
8 changes: 8 additions & 0 deletions
8
...rpLanguageServer.Tests/TestData/testDefinitionWorksInAspNetProject/Project/Project.csproj
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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<RootNamespace>test_csharp_web</RootNamespace> | ||
</PropertyGroup> | ||
</Project> |
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