public async Task Should_be_able_to_parse_lines_asynchronously_from_a_stream_and_split() { using (var stream = new StringReader(Text)) { var first = await new TextReaderStreamTextReader(stream, Environment.NewLine).Text; var parser = new LineTextParser(); TextCursor result = await StreamTextCursor.ParseText(first, new TextSpan(0, first.Length), parser); while (result.HasCurrent) { Console.WriteLine(result.Current); var fields = _toListParser.Parse(result.Current, result.CurrentSpan); Assert.That(fields.HasResult, Is.True); Assert.That(fields.Result.Count, Is.EqualTo(5)); if (result.HasNext == false) { break; } result = await result.Next(); } } }
public void Setup() { var parser = new DelimitedTextParser(','); _lineParser = new LineTextParser(); _parser = parser; _toListParser = parser.ToList(); }
public async Task Should_parse_a_file_line_by_line_async() { const string fileContent = @"Line 1. Line 2. Line 3. Line 4. Line 5. Line 6. Line 7. Line 8."; using (var stream = new StringReader(fileContent)) { var first = await new TextReaderStreamTextReader(stream, Environment.NewLine).Text; var parser = new LineTextParser(); TextCursor result = await StreamTextCursor.ParseText(first, new TextSpan(0, first.Length), parser); while (result.HasCurrent) { Console.WriteLine(result.Current); if (result.HasNext == false) { break; } result = await result.Next(); } // var span = await new ReadLineStreamTextSpanProvider(stream, Environment.NewLine).TextSpan; // while (span.CanExtend) // span = await span.Extend(); // // Console.WriteLine(span.Text); } }