2024-02-14 02:56:20 +00:00
|
|
|
|
using NathanMcRae;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2024-02-14 22:30:36 +00:00
|
|
|
|
{
|
|
|
|
|
string testName = "Bool test";
|
2024-02-15 00:16:23 +00:00
|
|
|
|
string testString1 = "column1:ty\\#pe:boolean\tcolumn2:binary\tcolumnthree\\nyep:string" +
|
2024-02-14 22:30:36 +00:00
|
|
|
|
"\nTRUE\tvalue\\\\t\0woo\tvaluetrhee" +
|
|
|
|
|
"\nFALSE\tnother\tno\\ther";
|
2024-02-14 02:56:20 +00:00
|
|
|
|
|
2024-02-15 00:16:23 +00:00
|
|
|
|
SaneTsv parsed = SaneTsv.ParseTypedTsv(Encoding.UTF8.GetBytes(testString1));
|
|
|
|
|
if (parsed.Records[0]["column1:ty#pe"] is bool result && result)
|
2024-02-14 22:30:36 +00:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Passed {testName}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Failed {testName}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
string testName = "Bad bool test";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string testString1 = "column1:type:boolean\tcolumn2:binary\tcolumnthree\\nyep:string" +
|
|
|
|
|
"\nTUE\tvalue\\\\t\0woo\tvaluetrhee" +
|
|
|
|
|
"\nFALSE\tnother\tno\\ther";
|
|
|
|
|
|
2024-02-15 00:16:23 +00:00
|
|
|
|
SaneTsv parsed = SaneTsv.ParseTypedTsv(Encoding.UTF8.GetBytes(testString1));
|
2024-02-14 22:30:36 +00:00
|
|
|
|
Console.WriteLine($"Failed {testName}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Passed {testName}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-02-15 02:32:31 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
string testName = "Comment test";
|
|
|
|
|
string testString1 = "#This is a file comment\n" +
|
2024-02-15 20:52:27 +00:00
|
|
|
|
"#One more file comment line\n" +
|
2024-02-15 02:32:31 +00:00
|
|
|
|
"column1:type:boolean\tcolumn2:binary\tcolumnthree\\nyep:string" +
|
|
|
|
|
"\n#This is a comment" +
|
|
|
|
|
"\n#Another comment line" +
|
|
|
|
|
"\nTRUE\tvalue\\\\t\0woo\tvaluetrhee" +
|
|
|
|
|
"\nFALSE\tnother\tno\\ther";
|
|
|
|
|
|
|
|
|
|
SaneTsv parsed = SaneTsv.ParseCommentedTsv(Encoding.UTF8.GetBytes(testString1));
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 20:52:27 +00:00
|
|
|
|
{
|
|
|
|
|
string testName = "Serde test";
|
|
|
|
|
string testString1 = "column1\tcolumn2\tcolumnthree\\nyep" +
|
|
|
|
|
"\nTRUE\tvalue\\\\twoo\tvaluetrhee" +
|
|
|
|
|
"\nFALSE\tnother\tno\\ther";
|
|
|
|
|
|
|
|
|
|
SaneTsv parsed = SaneTsv.ParseSimpleTsv(Encoding.UTF8.GetBytes(testString1));
|
|
|
|
|
string serialized = Encoding.UTF8.GetString(SaneTsv.SerializeSimpleTsv(parsed.ColumnNames, parsed.Records.Select(r => r.Fields.Select(f => f.ToString()).ToArray()).ToArray()));
|
|
|
|
|
|
|
|
|
|
if (testString1 == serialized)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Passed {testName}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Failed {testName}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 02:32:31 +00:00
|
|
|
|
Console.WriteLine("Done with tests");
|
2024-02-16 04:26:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Check qNaN, sNaN, +inf, -inf values for float types
|