Get commented typing working

This commit is contained in:
Nathan McRae
2024-02-22 22:09:13 -08:00
parent c8202b4f9a
commit 695ad1f110
2 changed files with 219 additions and 61 deletions

View File

@ -3,39 +3,39 @@ using System.Text;
internal class Program
{
public class TestRecord : SaneTsv.SaneTsvRecord
public class TestRecord : SaneTsv.TsvRecord
{
[SaneTsv.SaneTsvColumn("string-test")]
[SaneTsv.TypedTsvColumn("string-test")]
public string StringTest { get; set; }
[SaneTsv.SaneTsvColumn("bool-test")]
[SaneTsv.TypedTsvColumn("bool-test")]
public bool BoolTest { get; set; }
[SaneTsv.SaneTsvColumn("float32-test")]
[SaneTsv.TypedTsvColumn("float32-test")]
public float Float32Test { get; set; }
[SaneTsv.SaneTsvColumn("float32-le-test", typeof(SaneTsv.Float32LEType))]
[SaneTsv.TypedTsvColumn("float32-le-test", typeof(SaneTsv.Float32LEType))]
public float Float32LETest { get; set; }
[SaneTsv.SaneTsvColumn("float64-test")]
[SaneTsv.TypedTsvColumn("float64-test")]
public double Float64Test { get; set; }
[SaneTsv.SaneTsvColumn("float64-le-test", typeof(SaneTsv.Float64LEType))]
[SaneTsv.TypedTsvColumn("float64-le-test", typeof(SaneTsv.Float64LEType))]
public double Float64LETest { get; set; }
[SaneTsv.SaneTsvColumn("uint32-test")]
[SaneTsv.TypedTsvColumn("uint32-test")]
public UInt32 UInt32Test { get; set; }
[SaneTsv.SaneTsvColumn("uint64-test")]
[SaneTsv.TypedTsvColumn("uint64-test")]
public UInt64 UInt64Test { get; set; }
[SaneTsv.SaneTsvColumn("int32-test")]
[SaneTsv.TypedTsvColumn("int32-test")]
public Int32 Int32Test { get; set; }
[SaneTsv.SaneTsvColumn("int64-test")]
[SaneTsv.TypedTsvColumn("int64-test")]
public Int64 Int64Test { get; set; }
[SaneTsv.SaneTsvColumn("binary-test")]
[SaneTsv.TypedTsvColumn("binary-test")]
public byte[] BinaryTest { get; set; }
public TestRecord(string stringTest, bool boolTest, float float32Test, float float32LETest, double float64Test, double float64LETest, UInt32 uInt32Test, UInt64 uInt64Test, Int32 int32Test, Int64 int64Test, byte[] binaryTest)
@ -56,48 +56,48 @@ internal class Program
public TestRecord() { }
}
public class BoolTestRecord : SaneTsv.SaneTsvRecord
public class BoolTestRecord : SaneTsv.CommentedTsvRecord
{
[SaneTsv.SaneTsvColumn("column1:ty#pe")]
[SaneTsv.TypedTsvColumn("column1:ty#pe")]
public bool Column1 { get; set; }
[SaneTsv.SaneTsvColumn]
[SaneTsv.TypedTsvColumn]
public byte[] column2 { get; set; }
[SaneTsv.SaneTsvColumn("columnthree\nyep")]
[SaneTsv.TypedTsvColumn("columnthree\nyep")]
public string Column3 { get; set; }
}
public class BoolTestRecord2 : SaneTsv.SaneTsvRecord
public class BoolTestRecord2 : SaneTsv.CommentedTsvRecord
{
[SaneTsv.SaneTsvColumn("column1:type")]
[SaneTsv.TypedTsvColumn("column1:type")]
public bool Column1 { get; set; }
[SaneTsv.SaneTsvColumn]
[SaneTsv.TypedTsvColumn]
public byte[] column2 { get; set; }
[SaneTsv.SaneTsvColumn("columnthree\nyep")]
[SaneTsv.TypedTsvColumn("columnthree\nyep")]
public string Column3 { get; set; }
}
public class SerdeTestRecord : SaneTsv.SaneTsvRecord
public class SerdeTestRecord : SaneTsv.CommentedTsvRecord
{
[SaneTsv.SaneTsvColumn("column1")]
[SaneTsv.TypedTsvColumn("column1")]
public bool Column1 { get; set; }
[SaneTsv.SaneTsvColumn]
[SaneTsv.TypedTsvColumn]
public byte[] column2 { get; set; }
[SaneTsv.SaneTsvColumn("columnthree\nyep")]
[SaneTsv.TypedTsvColumn("columnthree\nyep")]
public string Column3 { get; set; }
}
public class FloatTestRecord : SaneTsv.SaneTsvRecord
public class FloatTestRecord : SaneTsv.CommentedTsvRecord
{
[SaneTsv.SaneTsvColumn("somefloat")]
[SaneTsv.TypedTsvColumn("somefloat")]
public double SomeFloat { get; set; }
[SaneTsv.SaneTsvColumn("binfloat", typeof(SaneTsv.Float64LEType))]
[SaneTsv.TypedTsvColumn("binfloat", typeof(SaneTsv.Float64LEType))]
public double BinFloat { get; set; }
}
@ -148,7 +148,7 @@ internal class Program
"\nTRUE\tvalue\\\\t\0woo\tvaluetrhee" +
"\nFALSE\tnother\tno\\ther";
Tsv<BoolTestRecord2> parsed = SaneTsv.ParseCommentedTsv<BoolTestRecord2>(Encoding.UTF8.GetBytes(testString1));
CommentedTsv<BoolTestRecord2> parsed = SaneTsv.ParseCommentedTsv<BoolTestRecord2>(Encoding.UTF8.GetBytes(testString1));
}
//{
@ -188,8 +188,6 @@ internal class Program
}
}
Console.WriteLine("Done with tests");
{
string testName = "Serde test";
@ -215,5 +213,87 @@ internal class Program
Console.WriteLine($"Failed {testName}");
}
}
{
string testName = "Trying to parse a not commented record as a Commented TSV test";
// These should not compile:
//byte[] serialized = SaneTsv.SerializeCommentedTsv(data);
// Gives this error: error CS7036: There is no argument given that corresponds to the required parameter 'fileComment' of 'SaneTsv.SerializeCommentedTsv<T>(IList<T>, string)'
//Tsv<TestRecord> parsed = SaneTsv.ParseCommentedTsv<TestRecord>(serialized);
// Gives this error: error CS0311: The type 'Program.TestRecord' cannot be used as type parameter 'T' in the generic type or method 'SaneTsv.ParseCommentedTsv<T>(byte[])'. There is no implicit reference conversion from 'Program.TestRecord' to 'NathanMcRae.SaneTsv.CommentedTsvRecord'.
}
{
string testName = "Try to parsed a Commented TSV as a Simple TSV";
string testString1 = "#This is a file comment\n" +
"#One more file comment line\n" +
"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";
try
{
Tsv<BoolTestRecord2> parsed = SaneTsv.ParseSimpleTsv<BoolTestRecord2>(Encoding.UTF8.GetBytes(testString1));
Console.WriteLine($"Failed {testName}");
}
catch (Exception e)
{
Console.WriteLine($"Passed {testName}");
}
}
{
string testName = "Try to parsed a Commented TSV as a Typed TSV";
string testString1 = "#This is a file comment\n" +
"#One more file comment line\n" +
"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";
try
{
Tsv<BoolTestRecord2> parsed = SaneTsv.ParseTypedTsv<BoolTestRecord2>(Encoding.UTF8.GetBytes(testString1));
Console.WriteLine($"Failed {testName}");
}
catch (Exception e)
{
Console.WriteLine($"Passed {testName}");
}
}
{
string testName = "Try to parsed a Typed TSV as a Simple TSV";
string testString1 =
"column1:type:boolean\tcolumn2:binary\tcolumnthree\\nyep:string" +
"\nTRUE\tvalue\\\\t\0woo\tvaluetrhee" +
"\nFALSE\tnother\tno\\ther";
try
{
Tsv<BoolTestRecord2> parsed = SaneTsv.ParseSimpleTsv<BoolTestRecord2>(Encoding.UTF8.GetBytes(testString1));
Console.WriteLine($"Failed {testName}");
}
catch (Exception e)
{
Console.WriteLine($"Passed {testName}");
}
}
Console.WriteLine("Done with tests");
}
}