|
1 | 1 | using Parlot.Tests.Calc; |
2 | 2 | using System; |
3 | 3 | using System.Buffers; |
4 | | - |
| 4 | +using System.Globalization; |
5 | 5 | using Xunit; |
6 | 6 |
|
7 | 7 | namespace Parlot.Tests; |
@@ -401,14 +401,34 @@ public void ShouldReadDecimalWithGroupSeparator(string input, string expected) |
401 | 401 | [Theory] |
402 | 402 | [InlineData("123.456", "123.456")] |
403 | 403 | [InlineData("123.456a", "123.456")] |
404 | | - [InlineData("123.a", "123")] |
| 404 | + [InlineData("123.a", "123.")] |
405 | 405 | [InlineData("123.456.789", "123.456")] |
406 | | - [InlineData("123.", "123")] |
| 406 | + [InlineData("123.", "123.")] |
407 | 407 | public void ShouldReadDecimalWithDecimalSeparator(string input, string expected) |
408 | 408 | { |
409 | 409 | Scanner s = new(input); |
410 | 410 |
|
411 | 411 | Assert.True(s.ReadDecimal(Fluent.NumberOptions.AllowDecimalSeparator, out var result, decimalSeparator: '.')); |
| 412 | + Assert.True(decimal.TryParse(expected, NumberStyles.Float, CultureInfo.InvariantCulture, out _)); |
| 413 | + Assert.Equal(expected, result); |
| 414 | + } |
| 415 | + |
| 416 | + [Theory] |
| 417 | + [InlineData("123.456", "123")] |
| 418 | + [InlineData("123.456a", "123")] |
| 419 | + [InlineData("123.a", "123")] |
| 420 | + [InlineData("123.456.789", "123")] |
| 421 | + [InlineData("123.", "123")] |
| 422 | + [InlineData("123.e", "123")] |
| 423 | + [InlineData("123.e1", "123")] |
| 424 | + [InlineData("123e", "123")] |
| 425 | + [InlineData("123e1", "123e1")] |
| 426 | + public void ShouldReadIntegerWithExponent(string input, string expected) |
| 427 | + { |
| 428 | + Scanner s = new(input); |
| 429 | + |
| 430 | + Assert.True(s.ReadDecimal(Fluent.NumberOptions.Integer | Fluent.NumberOptions.AllowExponent, out var result, decimalSeparator: '.')); |
| 431 | + Assert.True(decimal.TryParse(expected, NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out _)); |
412 | 432 | Assert.Equal(expected, result); |
413 | 433 | } |
414 | 434 | } |
0 commit comments