This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Added tests for Microsoft.VisualBasic.CompilerServices.Conversions #1… #26744
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7316066
Added tests for Microsoft.VisualBasic.CompilerServices.Conversions #1…
f75ad82
Merge branch 'master' of https://github.com/dotnet/corefx into add-te…
9cca9e4
added tests for ToBoolean fro Object
2dfa9ac
Merge branch 'master' into add-tests-visual-basic
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.VisualBasic.CompilerServices; | ||
using Xunit; | ||
|
||
namespace Microsoft.VisualBasic.Tests | ||
{ | ||
public class ConversionsTests | ||
{ | ||
[Theory] | ||
[InlineData("true", true)] | ||
[InlineData("false", false)] | ||
[InlineData("5", true)] | ||
[InlineData("0", false)] | ||
[InlineData("5.5", true)] | ||
[InlineData("0.0", false)] | ||
[InlineData("&h5", true)] | ||
[InlineData("&h0", false)] | ||
[InlineData("&o5", true)] | ||
[InlineData("&o0", false)] | ||
public void ToBoolean_String_ReturnsExpected(string str, bool expected) | ||
{ | ||
Assert.Equal(expected, Conversions.ToBoolean(str)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("yes")] | ||
[InlineData("contoso")] | ||
public void ToBoolean_String_ThrowsOnInvalidFormat(string str) | ||
{ | ||
Assert.Throws<InvalidCastException>(() => Conversions.ToBoolean(str)); | ||
} | ||
|
||
public static IEnumerable<object[]> ToBoolean_Object_ReturnsExpected_TestData() | ||
{ | ||
yield return new object[] { null, false }; | ||
yield return new object[] { false, false }; | ||
yield return new object[] { true, true }; | ||
yield return new object[] { (sbyte)0, false }; | ||
yield return new object[] { (sbyte)42, true }; | ||
yield return new object[] { (byte)0, false }; | ||
yield return new object[] { (byte)42, true }; | ||
yield return new object[] { (System.Int16)0, false }; | ||
yield return new object[] { (System.Int16)42, true }; | ||
yield return new object[] { (System.UInt16)0, false }; | ||
yield return new object[] { (System.UInt16)42, true }; | ||
yield return new object[] { (System.Int32)0, false }; | ||
yield return new object[] { (System.Int32)42, true }; | ||
yield return new object[] { (System.UInt32)0, false }; | ||
yield return new object[] { (System.UInt32)42, true }; | ||
yield return new object[] { (System.Int64)0, false }; | ||
yield return new object[] { (System.Int64)42, true }; | ||
yield return new object[] { (System.UInt64)0, false }; | ||
yield return new object[] { (System.UInt64)42, true }; | ||
yield return new object[] { 0.0m, false }; | ||
yield return new object[] { 0.42m, true }; | ||
yield return new object[] { (float)0.0, false }; | ||
yield return new object[] { (float)0.42, true }; | ||
yield return new object[] { (double)0.0, false }; | ||
yield return new object[] { (double)0.42, true }; | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(ToBoolean_Object_ReturnsExpected_TestData))] | ||
public void ToBoolean_Object_ReturnsExpected(object obj, bool expected) | ||
{ | ||
Assert.Equal(expected, Conversions.ToBoolean(obj)); | ||
} | ||
|
||
[Fact] | ||
public void ToBoolean_Object_ThrowsOn_List() | ||
{ | ||
Assert.Throws<InvalidCastException>(() => Conversions.ToBoolean(new List<string>())); | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: blank line.