Exemple #1
0
        public void CommentsAsFirstRecord(string csv, ReadRowEnding expected)
        {
            Assert.StartsWith("#", csv);

            var config =
                (ConcreteBoundConfiguration <_Test>)
                Configuration.For <_Test>(
                    Options.CreateBuilder(Options.Default)
                    .WithReadRowEnding(ReadRowEnding.Detect)
                    .WithCommentCharacter('#')
                    .WithValueSeparator(",")
                    .BuildInternal()
                    );

            using (var str = new StringReader(csv))
            {
                var charLookup = CharacterLookup.MakeCharacterLookup(config.Options, out _);
                {
                    var detector = new RowEndingDetector(new ReaderStateMachine(), config.Options, MemoryPool <char> .Shared, charLookup, new TextReaderAdapter(str), config.Options.ValueSeparator.AsMemory());
                    var detect   = detector.Detect();
                    Assert.True(detect.HasValue);
                    Assert.Equal(expected, detect.Value.Ending);
                }
            }
        }
Exemple #2
0
        public async Task Async(string csv, ReadRowEnding expected, string valueSep = ",")
        {
            var opts = Options.CreateBuilder(Options.Default).WithReadRowEnding(ReadRowEnding.Detect).WithValueSeparator(valueSep).BuildInternal();

            await RunAsyncReaderVariants <_Test>(
                opts,
                async (config, getReader) =>
            {
                var configForced = config as AsyncCountingAndForcingConfig <_Test>;
                var configCancel = config as AsyncCancelControlConfig <_Test>;
                var cInner       = (ConcreteBoundConfiguration <_Test>)(configForced?.Inner ?? configCancel?.Inner ?? config);

                await using (var str = await getReader(csv))
                {
                    var stateMachine = new ReaderStateMachine();
                    var charLookup   = CharacterLookup.MakeCharacterLookup(cInner.Options, out _);
                    using (var detector = new RowEndingDetector(stateMachine, cInner.Options, MemoryPool <char> .Shared, charLookup, str, cInner.Options.ValueSeparator.AsMemory()))
                    {
                        if (configForced != null)
                        {
                            configForced.Set(detector);
                        }

                        var detect = await detector.DetectAsync(CancellationToken.None);
                        Assert.True(detect.HasValue);
                        Assert.Equal(expected, detect.Value.Ending);
                    }
                }
            },
                cancellable : false
                );
        }