提交 d551f6a9 编写于 作者: T Tom Meschter

Add unit tests

上级 e0b3a592
......@@ -5848,5 +5848,51 @@ static void F(object[] c)
Assert.Null(model.GetSymbolInfo(expr).Symbol);
Assert.Equal(SpecialType.System_Boolean, model.GetTypeInfo(expr).Type.SpecialType);
}
[Fact]
public void GetSpecialType_ThrowsOnLessThanZero()
{
var source = "class C1 { }";
var comp = CreateStandardCompilation(source);
var specialType = (SpecialType)(-1);
var exceptionThrown = false;
try
{
comp.GetSpecialType(specialType);
}
catch (ArgumentOutOfRangeException e)
{
exceptionThrown = true;
Assert.StartsWith(expectedStartString: $"Unexpected SpecialType: '{(int)specialType}'.", actualString: e.Message);
}
Assert.True(exceptionThrown, $"{nameof(comp.GetSpecialType)} did not throw when it should have.");
}
[Fact]
public void GetSpecialType_ThrowsOnGreaterThanCount()
{
var source = "class C1 { }";
var comp = CreateStandardCompilation(source);
var specialType = SpecialType.Count + 1;
var exceptionThrown = false;
try
{
comp.GetSpecialType(specialType);
}
catch (ArgumentOutOfRangeException e)
{
exceptionThrown = true;
Assert.StartsWith(expectedStartString: $"Unexpected SpecialType: '{(int)specialType}'.", actualString: e.Message);
}
Assert.True(exceptionThrown, $"{nameof(comp.GetSpecialType)} did not throw when it should have.");
}
}
}
......@@ -6353,5 +6353,54 @@ BC30383: 'End Try' must be preceded by a matching 'Try'.
Assert.Equal(SpecialType.System_Boolean, model.GetTypeInfo(expr).Type.SpecialType)
End Sub
<Fact()>
Public Sub GetSpecialType_ThrowsOnLessThanZero()
Dim compilation = CompilationUtils.CreateCompilationWithMscorlib(
<compilation>
<file name="a.vb">
Class C1
End Class
</file>
</compilation>)
Dim type = CType(SpecialType.None - 1, SpecialType)
Dim exceptionThrown = False
Try
compilation.GetSpecialType(type)
Catch ex As ArgumentOutOfRangeException
exceptionThrown = True
Assert.StartsWith(expectedStartString:=$"Unexpected SpecialType: '{SpecialType.None - 1}'.", actualString:=ex.Message)
End Try
Assert.True(exceptionThrown, $"{NameOf(GetSpecialType)} did not throw when it should have.")
End Sub
<Fact()>
Public Sub GetSpecialType_ThrowsOnGreaterThanCount()
Dim compilation = CompilationUtils.CreateCompilationWithMscorlib(
<compilation>
<file name="a.vb">
Class C1
End Class
</file>
</compilation>)
Dim type = CType(SpecialType.Count + 1, SpecialType)
Dim exceptionThrown = False
Try
compilation.GetSpecialType(type)
Catch ex As ArgumentOutOfRangeException
exceptionThrown = True
Assert.StartsWith(expectedStartString:=$"Unexpected SpecialType: '{SpecialType.Count + 1}'.", actualString:=ex.Message)
End Try
Assert.True(exceptionThrown, $"{NameOf(GetSpecialType)} did not throw when it should have.")
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册