コード例 #1
0
        public void ReadColumnsSetTest()
        {
            const byte separator = BytesSplitReader.Comma;
            var        expecteds = new string[] { "A", "B", "C", "D", "", };
            var        text      = string.Join(((char)separator).ToString(), expecteds);
            var        raw       = Encoding.UTF8.GetBytes(text);
            var        columns   = new int[expecteds.Length];

            for (var column = columns.Length - 1; column >= 0; --column)
            {
                columns[column] = column;
            }
            var actuals = new BytesColumn[expecteds.Length];
            var appends = new Action <byte[], int, int> [expecteds.Length];

            for (var i = actuals.Length - 1; i >= 0; --i)
            {
                var actual = new BytesColumn();
                actuals[i] = actual;
                appends[i] = actual.AppendLength;
            }
            using (var readerStream = new MemoryStream(raw))
                using (var reader = new BytesSplitReader(readerStream))
                {
                    Assert.IsTrue(reader.ReadColumnsLength(separator, appends), "!ReadColumns");
                    for (var i = expecteds.Length - 1; i >= 0; --i)
                    {
                        Assert.AreEqual(expecteds[i], actuals[i].ToString(Encoding.UTF8), i.ToString());
                    }
                }
        }
コード例 #2
0
        public void PositionTest()
        {
            const byte separator = BytesSplitReader.Comma;
            var        expecteds = new string[] { "A", "B", "C", "D", "", };
            var        text      = string.Join(((char)separator).ToString(), expecteds);
            var        raw       = Encoding.UTF8.GetBytes(text);

            using (var readerStream = new MemoryStream(raw))
                using (var reader = new BytesSplitReader(readerStream))
                {
                    Assert.IsTrue(reader.ReadColumns());
                    Assert.AreEqual(raw.Length, reader.Position);
                }
        }
コード例 #3
0
        public void ReadColumnTest()
        {
            const byte separator = BytesSplitReader.Comma;
            var        expecteds = new string[] { "A", "B", "C", "D", "", };
            var        text      = string.Join(((char)separator).ToString(), expecteds);
            var        raw       = Encoding.UTF8.GetBytes(text);

            for (var i = expecteds.Length - 1; i >= 0; --i)
            {
                var actual = new BytesColumn();
                using (var readerStream = new MemoryStream(raw))
                    using (var reader = new BytesSplitReader(readerStream))
                    {
                        Assert.IsTrue(reader.ReadColumnsLength(separator, i, actual.AppendLength), "!ReadColumn");
                        Assert.AreEqual(expecteds[i], actual.ToString(Encoding.UTF8), i.ToString());
                    }
            }
        }