Esempio n. 1
0
        public void CustomLineParse()
        {
            const string fileName      = "CustomLineParse.txt";
            const string sampleContent = "  3  1154 508 100    vegetable ";

            List <long>  expectedList   = new() { 1154, 508, 100 };
            const string expectedString = "vegetable";

            using (StreamWriter writer = new(fileName))
            {
                writer.WriteLine(sampleContent);
            }

            IParsedLine line = new ParsedFile(fileName).NextLine();

            int n_ints = line.NextElement <int>();

            for (int i = 0; i < n_ints; ++i)
            {
                long data = line.NextElement <long>();
                Assert.Equal(expectedList[i], data);
            }

            string rawString  = line.PeekNextElement <string>(); // Raw string
            string lastString = line.NextElement <string>();     // Converted string => string

            Assert.Equal(rawString, lastString);

            Assert.Equal(expectedString, lastString);

            Assert.True(line.Empty);
        }