Skip to content

Commit

Permalink
Add SepReaderColTest for Infinity/-Infinity, adjust description and R…
Browse files Browse the repository at this point in the history
…EADME (#135)
  • Loading branch information
nietras committed Apr 21, 2024
1 parent 858b3e0 commit e4382c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ is, using `Sep` for `Separator` and `Col` for `Column` to keep code succinct.
|`Col` | Short for column, also called *field*. |
|`Line` | Horizontal set of characters until a line ending; `\r\n`, `\r`, `\n`. |
|`Index` | 0-based that is `RowIndex` will be 0 for first row (or the header if present). |
|`Number` | 1-based that is `LineNumber` will be 1 for the first line (as in `notepad`). Given a row may span multiple lines a row can have a *From* line number and an *ToExcl* line number matching the C# range indexing syntax `[LineNumberFrom..LineNumberToExcl]`. |
|`Number` | 1-based that is `LineNumber` will be 1 for the first line (as in `notepad`). Given a row may span multiple lines a row can have a *From* line number and a *ToExcl* line number matching the C# range indexing syntax `[LineNumberFrom..LineNumberToExcl]`. |

## Application Programming Interface (API)
Besides being the succinct name of the library, `Sep` is both the main entry
Expand Down
21 changes: 21 additions & 0 deletions src/Sep.Test/AssemblyInitializeCultureTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Globalization;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IHFood.Sep.Test;

[TestClass]
public static class AssemblyInitializeCultureTest
{
// Sets up InvariantCulture for all tests
[AssemblyInitialize]
public static void AssemblyInitializeCultureTest_InvariantCulture(TestContext _)
{
// Change current culture to invariant
CultureInfo culture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
}
12 changes: 12 additions & 0 deletions src/Sep.Test/SepReaderColTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,15 @@ static void AssertParseFloats(Func<SepReaderOptions, SepReaderOptions> configure
Run(col => Assert.AreEqual(float.NaN, col.Parse<float>()), "NaN", configure: configure);
Run(col => Assert.AreEqual(float.NaN, col.Parse<float>()), "+NaN", configure: configure);
Run(col => Assert.AreEqual(float.NaN, col.Parse<float>()), "-NaN", configure: configure);
Run(col => Assert.AreEqual(float.PositiveInfinity, col.Parse<float>()), "Infinity", configure: configure);
Run(col => Assert.AreEqual(float.NegativeInfinity, col.Parse<float>()), "-Infinity", configure: configure);

Run(col => Assert.AreEqual(ColValue, col.Parse<double>()), ColText, configure: configure);
Run(col => Assert.AreEqual(double.NaN, col.Parse<double>()), "NaN", configure: configure);
Run(col => Assert.AreEqual(double.NaN, col.Parse<double>()), "+NaN", configure: configure);
Run(col => Assert.AreEqual(double.NaN, col.Parse<double>()), "-NaN", configure: configure);
Run(col => Assert.AreEqual(double.PositiveInfinity, col.Parse<double>()), "Infinity", configure: configure);
Run(col => Assert.AreEqual(double.NegativeInfinity, col.Parse<double>()), "-Infinity", configure: configure);
}

static void AssertTryParseReturnFloats(Func<SepReaderOptions, SepReaderOptions> configure)
Expand All @@ -184,12 +188,16 @@ static void AssertTryParseReturnFloats(Func<SepReaderOptions, SepReaderOptions>
Run(col => Assert.AreEqual(float.NaN, col.TryParse<float>()), "NaN", configure: configure);
Run(col => Assert.AreEqual(float.NaN, col.TryParse<float>()), "+NaN", configure: configure);
Run(col => Assert.AreEqual(float.NaN, col.TryParse<float>()), "-NaN", configure: configure);
Run(col => Assert.AreEqual(float.PositiveInfinity, col.TryParse<float>()), "Infinity", configure: configure);
Run(col => Assert.AreEqual(float.NegativeInfinity, col.TryParse<float>()), "-Infinity", configure: configure);
Run(col => Assert.AreEqual(null, col.TryParse<float>()), "a", configure: configure);

Run(col => Assert.AreEqual(ColValue, col.TryParse<double>()), ColText, configure: configure);
Run(col => Assert.AreEqual(double.NaN, col.TryParse<double>()), "NaN", configure: configure);
Run(col => Assert.AreEqual(double.NaN, col.TryParse<double>()), "+NaN", configure: configure);
Run(col => Assert.AreEqual(double.NaN, col.TryParse<double>()), "-NaN", configure: configure);
Run(col => Assert.AreEqual(double.PositiveInfinity, col.TryParse<double>()), "Infinity", configure: configure);
Run(col => Assert.AreEqual(double.NegativeInfinity, col.TryParse<double>()), "-Infinity", configure: configure);
Run(col => Assert.AreEqual(null, col.TryParse<double>()), "a", configure: configure);
}

Expand All @@ -200,11 +208,15 @@ static void AssertTryParseOutFloats(Func<SepReaderOptions, SepReaderOptions> con
Run(col => Assert.AreEqual((float?)float.NaN, col.TryParse<float>(out var v) ? v : null), "NaN", configure: configure);
Run(col => Assert.AreEqual((float?)float.NaN, col.TryParse<float>(out var v) ? v : null), "+NaN", configure: configure);
Run(col => Assert.AreEqual((float?)float.NaN, col.TryParse<float>(out var v) ? v : null), "-NaN", configure: configure);
Run(col => Assert.AreEqual((float?)float.PositiveInfinity, col.TryParse<float>(out var v) ? v : null), "Infinity", configure: configure);
Run(col => Assert.AreEqual((float?)float.NegativeInfinity, col.TryParse<float>(out var v) ? v : null), "-Infinity", configure: configure);

Run(col => Assert.AreEqual((double?)ColValue, col.TryParse<double>(out var v) ? v : null), configure: configure);
Run(col => Assert.AreEqual((double?)null, col.TryParse<double>(out var v) ? v : null), "a", configure: configure);
Run(col => Assert.AreEqual((double?)double.NaN, col.TryParse<double>(out var v) ? v : null), "NaN", configure: configure);
Run(col => Assert.AreEqual((double?)double.NaN, col.TryParse<double>(out var v) ? v : null), "+NaN", configure: configure);
Run(col => Assert.AreEqual((double?)double.NaN, col.TryParse<double>(out var v) ? v : null), "-NaN", configure: configure);
Run(col => Assert.AreEqual((double?)double.PositiveInfinity, col.TryParse<double>(out var v) ? v : null), "Infinity", configure: configure);
Run(col => Assert.AreEqual((double?)double.NegativeInfinity, col.TryParse<double>(out var v) ? v : null), "-Infinity", configure: configure);
}
}
2 changes: 1 addition & 1 deletion src/Sep/Sep.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>0.5.0</PackageValidationBaselineVersion>

<Description>Modern, minimal, fast, zero allocation, reading and writing of separated values (csv, tsv etc.). Cross-platform, trimmable and AOT/NativeAOT compatible.</Description>
<Description>World's Fastest .NET CSV Parser. Modern, minimal, fast, zero allocation, reading and writing of separated values (csv, tsv etc.). Cross-platform, trimmable and AOT/NativeAOT compatible.</Description>

<!-- NuGet -->
<PackageId>Sep</PackageId>
Expand Down

0 comments on commit e4382c5

Please sign in to comment.