public void JaggedTable() { const string ValueDelimeter = "|"; const string RecordDelimeter = "\r\n"; const int NumRecords = 4; const int NumValuesOddRow = 3; const int NumValuesEvenRow = 5; var builder = new StringBuilder(128); for (var recordNum = 0; recordNum < NumRecords; recordNum++) { if (recordNum > 0) { builder.Append(RecordDelimeter); } var numValues = recordNum % 2 == 0 ? NumValuesEvenRow : NumValuesOddRow; AddRecord(builder, ValueDelimeter, recordNum, numValues); } var parser = new DsvParser(builder.ToString(), ValueDelimeter, RecordDelimeter); var numRecords = parser.RecordsLength; Assert.AreEqual(NumRecords, numRecords); for (var recordNum = 0; recordNum < numRecords; recordNum++) { var numValues = parser.GetRecordLength(recordNum); Assert.AreEqual(recordNum % 2 == 0 ? NumValuesEvenRow : NumValuesOddRow, numValues); for (var valueNum = 0; valueNum < numValues; valueNum++) { var value = parser.GetValue(recordNum, valueNum); Assert.AreEqual($"Value {recordNum}-{valueNum}", value.ToString()); } } }
public void LongDelimeters() { const string ValueDelimeter = "This is a very long and terrible value delimeter"; const string RecordDelimeter = "This is a very long and terrible record delimeter"; const int NumRecords = 3; const int NumValues = 4; var builder = CreateTable(ValueDelimeter, RecordDelimeter, NumRecords, NumValues); var parser = new DsvParser(builder.ToString(), ValueDelimeter, RecordDelimeter); var numRecords = parser.RecordsLength; Assert.AreEqual(NumRecords, numRecords); for (var recordNum = 0; recordNum < numRecords; recordNum++) { var numValues = parser.GetRecordLength(recordNum); Assert.AreEqual(NumValues, numValues); for (var valueNum = 0; valueNum < numValues; valueNum++) { var value = parser.GetValue(recordNum, valueNum); Assert.AreEqual($"Value {recordNum}-{valueNum}", value.ToString()); } } }
public void LargeTable() { const string ValueDelimeter = "|"; const string RecordDelimeter = "\r\n"; const int NumRecords = 10_000; const int NumValues = 100; var builder = CreateTable(ValueDelimeter, RecordDelimeter, NumRecords, NumValues); var parser = new DsvParser(builder.ToString(), ValueDelimeter, RecordDelimeter); var numRecords = parser.RecordsLength; Assert.AreEqual(NumRecords, numRecords); for (var recordNum = 0; recordNum < numRecords; recordNum++) { var numValues = parser.GetRecordLength(recordNum); Assert.AreEqual(NumValues, numValues); for (var valueNum = 0; valueNum < numValues; valueNum++) { var value = parser.GetValue(recordNum, valueNum); Assert.AreEqual($"Value {recordNum}-{valueNum}", value.ToString()); } } }