-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DecimalTypeTests.cs
76 lines (68 loc) · 2.7 KB
/
DecimalTypeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Globalization;
using Microsoft.VisualBasic.CompilerServices;
using Xunit;
namespace Microsoft.VisualBasic.Tests
{
public class DecimalTypeTests
{
[Theory]
[InlineData(true, -1)]
[InlineData(false, 0)]
public void FromBoolean(bool value, decimal expected)
{
Assert.Equal(expected, DecimalType.FromBoolean(value));
}
[Theory]
[InlineData(null, 0)]
[InlineData("&H123", 291)]
[InlineData("&O123", 83)]
[InlineData("123", 123)]
public void FromString(string value, decimal expected)
{
Assert.Equal(expected, DecimalType.FromString(value));
}
[Fact]
public void FromString_Invalid()
{
Assert.Throws<OverflowException>(() => DecimalType.FromString("9999999999999999999999999999999999999"));
Assert.Throws<InvalidCastException>(() => DecimalType.FromString("abc"));
}
[Fact]
public void FromObject()
{
Assert.Equal(0m, DecimalType.FromObject(null));
Assert.Equal(-1m, DecimalType.FromObject(true));
Assert.Equal(123m, DecimalType.FromObject((byte)123));
Assert.Equal(123m, DecimalType.FromObject((short)123));
Assert.Equal(123m, DecimalType.FromObject((int)123));
Assert.Equal(123m, DecimalType.FromObject((long)123));
Assert.Equal(123m, DecimalType.FromObject((float)123));
Assert.Equal(123m, DecimalType.FromObject((double)123));
Assert.Equal(123m, DecimalType.FromObject((decimal)123));
Assert.Equal(123m, DecimalType.FromObject("123"));
}
[Fact]
public void FromObject_Invalid()
{
Assert.Throws<InvalidCastException>(() => DecimalType.FromObject('1'));
Assert.Throws<InvalidCastException>(() => DecimalType.FromObject(DateTime.MinValue));
Assert.Throws<InvalidCastException>(() => DecimalType.FromObject(Guid.Empty));
}
[Theory]
[InlineData("123", 123)]
[InlineData("\u00A4123", 123)]
public void Parse(string value, decimal expected)
{
Assert.Equal(expected, DecimalType.Parse(value, CultureInfo.InvariantCulture.NumberFormat));
}
[Fact]
public void Parse_Invalid()
{
Assert.Throws<ArgumentNullException>(() => DecimalType.Parse(null, null));
Assert.Throws<FormatException>(() => DecimalType.Parse("abc", CultureInfo.InvariantCulture.NumberFormat));
}
}
}