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

Add some EE and EnC tests for primary constructors #66677

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 @@ -18540,5 +18540,228 @@ public void TopLevelStatements_Reorder()
}

#endregion

#region Primary Constructors

[Theory]
[CombinatorialData]
public void PrimaryConstructors_01([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C() { void M() { } }";
var src2 = keyword + " C() { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, keyword + " C", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_02([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C() { }";
var src2 = keyword + " C() { void M() { } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Insert, "void M()", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_03([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C() { void M() { } }";
var src2 = keyword + " C() { void M() { ToString(); } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "void M()", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_04([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C(int a) { }";
var src2 = keyword + " C(int a, int b) { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Insert, "int b", FeaturesResources.parameter));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_05([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C(int a, int b) { }";
var src2 = keyword + " C(int a) { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, keyword + " C", FeaturesResources.parameter));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_06([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C { }";
var src2 = keyword + " C() { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics();
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_07([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C() { }";
var src2 = keyword + " C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics();
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_08([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C() { }";
var src2 = keyword + " C(int b) { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Insert, "int b", FeaturesResources.parameter));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_09([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C(int b) { }";
var src2 = keyword + " C() { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, keyword + " C", FeaturesResources.parameter));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_10([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C { }";
var src2 = keyword + " C(int b) { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Insert, "int b", FeaturesResources.parameter));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_11([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C(int b) { }";
var src2 = keyword + " C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, keyword + " C", FeaturesResources.parameter));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_12([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = "partial " + keyword + " C(); partial " + keyword + " C { void M() { } }";
var src2 = "partial " + keyword + " C(); partial " + keyword + " C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "partial " + keyword + " C", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_13([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = "partial " + keyword + " C(); partial " + keyword + " C { }";
var src2 = "partial " + keyword + " C(); partial " + keyword + " C { void M() { } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Insert, "void M()", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_14([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = "partial " + keyword + " C(); partial " + keyword + " C { void M() { } }";
var src2 = "partial " + keyword + " C(); partial " + keyword + " C { void M() { ToString(); } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "void M()", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_15([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = "partial " + keyword + " C(); partial " + keyword + " C { void M() { } }";
var src2 = "partial " + keyword + " C {} partial " + keyword + " C { void M() { ToString(); } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "void M()", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_16([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = "partial " + keyword + " C {} partial " + keyword + " C { void M() { } }";
var src2 = "partial " + keyword + " C(); partial " + keyword + " C { void M() { ToString(); } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "void M()", FeaturesResources.method));
}

[Theory]
[CombinatorialData]
public void PrimaryConstructors_17([CombinatorialValues("class", "struct")] string keyword)
{
var src1 = keyword + " C(int a) { }";
var src2 = keyword + " C(long a) { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "long a", FeaturesResources.parameter));
}

#endregion
Copy link
Member

@cston cston Feb 3, 2023

Choose a reason for hiding this comment

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

#endregion

Consider testing edits of explicit constructors other than the primary constructor, and edits of other members such as instance and static methods and fields. #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Feb 3, 2023

Choose a reason for hiding this comment

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

Consider testing edits of explicit constructors other than the primary constructor, and edits of other members such as instance and static methods and fields.

Testing of field initializers is not particularly interesting at the moment because they do not change capturing of primary constructor parameters. Also, at the moment, I do not care if their edits are flagged as rude edits or not. The goal is to error on the safe side.

Same goes for static methods.

Explicit constructors other than the primary constructors cannot refer to primary constructor parameters. So, same as for fields, I do not care what happens for them at the moment.

Addition/removal/edit of instance methods is covered. For example, PrimaryConstructors_01, PrimaryConstructors_02, PrimaryConstructors_03.

}
}
Loading