Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record-structs: validate and fix a number of IDE tests #52261

Merged
merged 9 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ public void TestNormalizeDeclaration1()
TestNormalizeDeclaration("class c{void M([a]int x,[b] [c,d]int y){}}", "class c\r\n{\r\n void M([a] int x, [b][c, d] int y)\r\n {\r\n }\r\n}");
}

[Fact]
public void TestSpacingOnRecord()
{
TestNormalizeDeclaration("record class C(int I, int J);", "record class C(int I, int J);");
TestNormalizeDeclaration("record struct S(int I, int J);", "record struct S(int I, int J);");
}

[Fact]
[WorkItem(23618, "https://github.com/dotnet/roslyn/issues/23618")]
public void TestSpacingOnInvocationLikeKeywords()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,19 @@ public interface IAsyncEnumerator<out T> : IAsyncDisposable
internal override Type GetCompletionProviderType()
=> typeof(DeclarationNameCompletionProvider);

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[Theory, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(48310, "https://github.com/dotnet/roslyn/issues/48310")]
public async Task TreatRecordPositionalParameterAsProperty()
[InlineData("record")]
[InlineData("record class")]
[InlineData("record struct")]
public async Task TreatRecordPositionalParameterAsProperty(string record)
{
var markup = @"
var markup = $@"
public class MyClass
{
}
{{
}}

public record R(MyClass $$
public {record} R(MyClass $$
";
await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7485,14 +7485,17 @@ struct C
await VerifyItemExistsAsync(markup, "C");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task RecordDestructor()
[Theory, Trait(Traits.Feature, Traits.Features.Completion)]
[InlineData("record")]
[InlineData("record class")]
[InlineData("record struct")]
public async Task RecordDestructor(string record)
{
var markup = @"
record C
{
var markup = $@"
{record} C
{{
~$$
}";
}}";
await VerifyItemExistsAsync(markup, "C");
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting :) #Resolved

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public async Task TestMethod()
{
await TestInRegularAndScript1Async(
@"
public class Foo
public class Goo
{
public abstract void [|M|]();
}",
@"
public abstract class Foo
public abstract class Goo
{
public abstract void M();
}");
Expand All @@ -46,12 +46,12 @@ public async Task TestMethodEnclosingClassWithoutAccessibility()
{
await TestInRegularAndScript1Async(
@"
class Foo
class Goo
{
public abstract void [|M|]();
}",
@"
abstract class Foo
abstract class Goo
{
public abstract void M();
}");
Expand All @@ -65,15 +65,15 @@ await TestInRegularAndScript1Async(
/// <summary>
/// Some class comment.
/// </summary>
public class Foo
public class Goo
{
public abstract void [|M|]();
}",
@"
/// <summary>
/// Some class comment.
/// </summary>
public abstract class Foo
public abstract class Goo
{
public abstract void M();
}");
Expand All @@ -84,12 +84,12 @@ public async Task TestPropertyGetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
public class Goo
{
public abstract object P { [|get|]; }
}",
@"
public abstract class Foo
public abstract class Goo
{
public abstract object P { get; }
}");
Expand All @@ -100,12 +100,12 @@ public async Task TestPropertySetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
public class Goo
{
public abstract object P { [|set|]; }
}",
@"
public abstract class Foo
public abstract class Goo
{
public abstract object P { set; }
}");
Expand All @@ -116,12 +116,12 @@ public async Task TestIndexerGetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
public class Goo
{
public abstract object this[object o] { [|get|]; }
}",
@"
public abstract class Foo
public abstract class Goo
{
public abstract object this[object o] { get; }
}");
Expand All @@ -132,12 +132,12 @@ public async Task TestIndexerSetter()
{
await TestInRegularAndScript1Async(
@"
public class Foo
public class Goo
{
public abstract object this[object o] { [|set|]; }
}",
@"
public abstract class Foo
public abstract class Goo
{
public abstract object this[object o] { set; }
}");
Expand All @@ -148,21 +148,21 @@ public async Task TestPartialClass()
{
await TestInRegularAndScript1Async(
@"
public partial class Foo
public partial class Goo
{
public abstract void [|M|]();
}

public partial class Foo
public partial class Goo
{
}",
@"
public partial abstract class Foo
public partial abstract class Goo
{
public abstract void M();
}

public partial class Foo
public partial class Goo
{
}");
}
Expand All @@ -172,7 +172,7 @@ public async Task TestEventAdd()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
public class Goo
{
public abstract event System.EventHandler E { [|add|]; }
}");
Expand All @@ -183,7 +183,7 @@ public async Task TestEventRemove()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
public class Goo
{
public abstract event System.EventHandler E { [|remove|]; }
}");
Expand All @@ -194,7 +194,7 @@ public async Task TestMethodWithBody()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
public class Goo
{
public abstract int [|M|]() => 3;
}");
Expand All @@ -205,7 +205,7 @@ public async Task TestPropertyGetterWithArrowBody()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
public class Goo
{
public abstract int [|P|] => 3;
}");
Expand All @@ -216,7 +216,7 @@ public async Task TestPropertyGetterWithBody()
{
await TestMissingInRegularAndScriptAsync(
@"
public class Foo
public class Goo
{
public abstract int P
{
Expand All @@ -234,7 +234,7 @@ public class C
{
public struct S
{
public abstract void [|Foo|]();
public abstract void [|Goo|]();
}
}");
}
Expand All @@ -244,7 +244,7 @@ public async Task TestMethodEnclosingClassStatic()
{
await TestMissingInRegularAndScriptAsync(
@"
public static class Foo
public static class Goo
{
public abstract void [|M|]();
}");
Expand All @@ -255,17 +255,43 @@ public async Task TestRecord()
{
await TestInRegularAndScript1Async(
@"
public record Foo
public record Goo
{
public abstract void [|M|]();
}",
@"
public abstract record Foo
public abstract record Goo
{
public abstract void M();
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeTypeAbstract)]
public async Task TestRecordClass()
{
await TestInRegularAndScript1Async(
@"
public record class Goo
{
public abstract void [|M|]();
}",
@"
public abstract record class Goo
{
public abstract void M();
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeTypeAbstract)]
public async Task TestRecordStruct()
{
await TestMissingInRegularAndScriptAsync(@"
public record struct Goo
{
public abstract void [|M|]();
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeTypeAbstract)]
public async Task FixAll()
{
Expand Down
37 changes: 37 additions & 0 deletions src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Editor.UnitTests.NavigateTo;
Expand Down Expand Up @@ -69,6 +70,42 @@ await TestAsync(
});
}

[Theory]
[CombinatorialData]
public async Task FindRecordClass(TestHost testHost)
{
await TestAsync(
testHost, @"record class Goo
{
}", async w =>
{
var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method");
VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
});
}

[Theory]
[CombinatorialData]
public async Task FindRecordStruct(TestHost testHost)
{
var content = XElement.Parse(@"
<Workspace>
<Project Language=""C#"" LanguageVersion=""preview"" CommonReferences=""true"">
<Document FilePath=""File1.cs"">
record struct Goo
{
}
</Document>
</Project>
</Workspace>
");
await TestAsync(testHost, content, async w =>
{
var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method");
VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Structure, Glyph.StructureInternal);
});
}

[Theory]
[CombinatorialData]
public async Task FindVerbatimClass(TestHost testHost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ private static string GetKind(string kind)
// This should be updated whenever NavigateToItemKind has a record.
CodeAnalysis.NavigateTo.NavigateToItemKind.Record
=> VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Class,
// VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind doesn't have a record struct, fall back to struct.
// This should be updated whenever NavigateToItemKind has a record struct.
Comment on lines +104 to +105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to route this to the appropriate team?

Not sure if it's the editor team who owns this?

cc: @jinujoseph @olegtk

CodeAnalysis.NavigateTo.NavigateToItemKind.RecordStruct
=> VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Structure,
CodeAnalysis.NavigateTo.NavigateToItemKind.Structure
=> VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Structure,
_ => throw ExceptionUtilities.UnexpectedValue(kind)
Expand Down
Loading