Skip to content

Commit

Permalink
Add support for ushort, uint and ulong.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Dec 2, 2022
1 parent 1407030 commit 0377148
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/FileParser/Utils/TypeValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ internal static class TypeValidator
typeof(bool),
typeof(char),
typeof(string),
typeof(ushort),
typeof(short),
typeof(int),
typeof(uint),
typeof(ulong),
typeof(long),
typeof(double),
typeof(object)
Expand Down
6 changes: 0 additions & 6 deletions tests/FileParser.Test/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ public class ExceptionTests
[Fact]
public void NotSupportedException()
{
Assert.Throws<NotSupportedException>(() => new ParsedFile(_validPath + "Sample_file.txt").ToList<uint>());
Assert.Throws<NotSupportedException>(() => ParsedFile.ReadAllGroupsOfLines<uint>(_validPath + "Sample_file.txt"));
Assert.Throws<NotSupportedException>(() => new ParsedFile(_validPath + "Sample_file.txt").ToList<DateTime>());
Assert.Throws<NotSupportedException>(() => ParsedFile.ReadAllGroupsOfLines<DateTime>(_validPath + "Sample_file.txt"));

var line = new ParsedLine(new Queue<string>(new string[] { "1234" }));
Assert.Throws<NotSupportedException>(() => line.NextElement<ulong>());
Assert.Throws<NotSupportedException>(() => ParsedFile.ReadAllGroupsOfLines<ulong>(_validPath + "Sample_file.txt"));

IParsedFile parsedFile = new ParsedFile(_validPath + "Sample_file.txt");
IParsedLine firstParsedLine = parsedFile.NextLine();

Expand Down
36 changes: 36 additions & 0 deletions tests/FileParser.Test/ParsedLineTest/ParseUnsignedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Xunit;

namespace FileParser.Test.ParsedLineTest
{
public class ParseUnsignedTests
{
private readonly string _sampleFolderPath = "TestFiles" + Path.DirectorySeparatorChar;

[Fact]
public void ParsedDoubleWithCommas()
{
IParsedFile parsedFile = new ParsedFile(Path.Combine(_sampleFolderPath, "Unsigned.txt"));

ValidateUnsignedFile(parsedFile.NextLine(), parsedFile.NextLine());

Assert.True(parsedFile.Empty);
}

private static void ValidateUnsignedFile(IParsedLine firstLine, IParsedLine secondLine)
{
Assert.Equal(0, firstLine.PeekNextElement<ushort>());
Assert.Equal(0u, firstLine.PeekNextElement<uint>());
Assert.Equal(0ul, firstLine.NextElement<ulong>());
Assert.Equal(1234, firstLine.PeekNextElement<ushort>());
Assert.Equal(1234u, firstLine.PeekNextElement<uint>());
Assert.Equal(1234ul, firstLine.NextElement<ulong>());
Assert.Equal(2147483648, firstLine.PeekNextElement<uint>());
Assert.Equal(2147483648, firstLine.NextElement<ulong>());
Assert.True(firstLine.Empty);

Assert.Throws<ArgumentException>(() => secondLine.PeekNextElement<ushort>());
Assert.Throws<ArgumentException>(() => secondLine.PeekNextElement<uint>());
Assert.Throws<ArgumentException>(() => secondLine.PeekNextElement<ulong>());
}
}
}
2 changes: 2 additions & 0 deletions tests/FileParser.Test/TestFiles/Unsigned.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 1234 2147483648
-1234 -2147483648

0 comments on commit 0377148

Please sign in to comment.