Skip to content

Commit

Permalink
Add new test and move existing tests together
Browse files Browse the repository at this point in the history
The existing test may need an update to work for icsharpcode#749 and icsharpcode#1062
  • Loading branch information
GrahamTheCoder committed Dec 21, 2023
1 parent b8c5a10 commit 6986791
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CodeConverter/CSharp/OperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static bool IsAssignableExpression(this IOperation operation)
case OperationKind.DynamicMemberReference:
return true;

//Just documenting since it's the only one mentioning reference that can't be assigned to AFAIK
//Just documenting since it's the only one mentioning reference that can't necessarily be assigned to AFAIK
case OperationKind.PropertyReference:
return false;
}
Expand Down
142 changes: 86 additions & 56 deletions Tests/CSharp/MemberTests/MemberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,92 @@ public partial class FooBar : IFoo, IBar
}");
}

[Fact]
public async Task ExplicitInterfaceImplementationOptionalParameters_1062_Async()
{
await TestConversionVisualBasicToCSharpAsync(
@"
Public Interface InterfaceWithOptionalParameters
Sub S(Optional i As Integer = 0)
End Interface
Public Class ImplInterfaceWithOptionalParameters : Implements InterfaceWithOptionalParameters
Public Sub InterfaceWithOptionalParameters_S(Optional i As Integer = 0) Implements InterfaceWithOptionalParameters.S
End Sub
End Class", @"
public partial interface InterfaceWithOptionalParameters
{
void S(int i = 0);
}
public partial class ImplInterfaceWithOptionalParameters : InterfaceWithOptionalParameters
{
public void InterfaceWithOptionalParameters_S(int i = 0)
{
}
void InterfaceWithOptionalParameters.S(int i = 0) => InterfaceWithOptionalParameters_S(i);
}
");
}


[Fact]
public async Task ExplicitInterfaceImplementationOptionalParametersAsync()
{
await TestConversionVisualBasicToCSharpAsync(
@"Public Interface IFoo
Property ExplicitProp(Optional str As String = """") As Integer
Function ExplicitFunc(Optional str2 As String = """", Optional i2 As Integer = 1) As Integer
End Interface
Public Class Foo
Implements IFoo
Private Function ExplicitFunc(Optional str As String = """", Optional i2 As Integer = 1) As Integer Implements IFoo.ExplicitFunc
Return 5
End Function
Private Property ExplicitProp(Optional str As String = """") As Integer Implements IFoo.ExplicitProp
Get
Return 5
End Get
Set(value As Integer)
End Set
End Property
End Class", @"
public partial interface IFoo
{
int get_ExplicitProp(string str = """");
void set_ExplicitProp(string str = """", int value = default);
int ExplicitFunc(string str2 = """", int i2 = 1);
}
public partial class Foo : IFoo
{
private int ExplicitFunc(string str = """", int i2 = 1)
{
return 5;
}
int IFoo.ExplicitFunc(string str, int i2) => ExplicitFunc(str, i2);
private int get_ExplicitProp(string str = """")
{
return 5;
}
private void set_ExplicitProp(string str = """", int value = default)
{
}
int IFoo.get_ExplicitProp(string str) => get_ExplicitProp(str);
void IFoo.set_ExplicitProp(string str, int value) => set_ExplicitProp(str, value);
}
");
}

[Fact]
public async Task RenamedInterfaceMethodFullyQualifiedAsync()
{
Expand Down Expand Up @@ -3506,62 +3592,6 @@ private void set_ExplicitProp(string str, int value)
}");
}

[Fact]
public async Task ExplicitInterfaceImplementationOptionalParametersAsync()
{
await TestConversionVisualBasicToCSharpAsync(
@"Public Interface IFoo
Property ExplicitProp(Optional str As String = """") As Integer
Function ExplicitFunc(Optional str2 As String = """", Optional i2 As Integer = 1) As Integer
End Interface
Public Class Foo
Implements IFoo
Private Function ExplicitFunc(Optional str As String = """", Optional i2 As Integer = 1) As Integer Implements IFoo.ExplicitFunc
Return 5
End Function
Private Property ExplicitProp(Optional str As String = """") As Integer Implements IFoo.ExplicitProp
Get
Return 5
End Get
Set(value As Integer)
End Set
End Property
End Class", @"
public partial interface IFoo
{
int get_ExplicitProp(string str = """");
void set_ExplicitProp(string str = """", int value = default);
int ExplicitFunc(string str2 = """", int i2 = 1);
}
public partial class Foo : IFoo
{
private int ExplicitFunc(string str = """", int i2 = 1)
{
return 5;
}
int IFoo.ExplicitFunc(string str, int i2) => ExplicitFunc(str, i2);
private int get_ExplicitProp(string str = """")
{
return 5;
}
private void set_ExplicitProp(string str = """", int value = default)
{
}
int IFoo.get_ExplicitProp(string str) => get_ExplicitProp(str);
void IFoo.set_ExplicitProp(string str, int value) => set_ExplicitProp(str, value);
}
");
}

/// <summary>
///
/// </summary>
Expand Down

0 comments on commit 6986791

Please sign in to comment.