コード例 #1
0
        public void ReadColumnsAddTest()
        {
            const char separator = StringSplitReader.Comma;
            var        expecteds = new string[] { "A", "B", "C", "D", "", };
            var        text      = string.Join(separator.ToString(), expecteds);
            var        raw       = Encoding.UTF8.GetBytes(text);
            var        actuals   = new List <string>();

            using (var readerStream = new MemoryStream(raw))
                using (var reader = new StringSplitReader(readerStream))
                {
                    Assert.IsTrue(reader.ReadColumnsAdd(separator, actuals), "!ReadColumns");
                    Assert.AreEqual(expecteds.Length, actuals.Count, "expecteds.Length != actuals.Count");
                    for (var i = expecteds.Length - 1; i >= 0; --i)
                    {
                        Assert.AreEqual(expecteds[i], actuals[i], i.ToString());
                    }
                }
        }
コード例 #2
0
 private static void ReadColumnsAddCompare()
 {
     using (var lineStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read))
         using (var lineReader = new StreamReader(lineStream))
             using (var splitStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                 using (var splitReader = new StringSplitReader(splitStream))
                 {
                     var splits = new List <string>();
                     while (true)
                     {
                         var line = lineReader.ReadLine();
                         splits.Clear();
                         var split = splitReader.ReadColumnsAdd(separator, splits);
                         if ((line != null) != split)
                         {
                             Console.WriteLine("Number of lines is not the same.");
                             return;
                         }
                         if (line == null || !split)
                         {
                             return;
                         }
                         var columns = line.Split(separators);
                         if (columns.Length != splits.Count)
                         {
                             Console.WriteLine("Number of columns is not the same.");
                             return;
                         }
                         for (var i = columns.Length - 1; i >= 0; --i)
                         {
                             if (columns[i] != splits[i])
                             {
                                 Console.WriteLine("A column is not the same.");
                                 return;
                             }
                         }
                     }
                 }
 }