Example #1
0
        /// <summary>
        /// Constructor that reads a file that is supplied from the path that is
        /// from the parameter: <paramref name="inpfile"/>
        /// </summary>
        /// <param name="inpfile">The supplied path to the file that will be used</param>
        public InpProject(string inpfile) : this()
        {
            // Validate that this file exits and set the full path
            // to the file
            InpFile = FileValitation(inpfile);

            // Set the project name to the filename without extension
            ProjectName = Path.GetFileNameWithoutExtension(InpFile);

            // Create a new file stream for the file and an new InpFileReader
            using var fs     = new FileStream(InpFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            using var reader = new InpFileReader(fs);

            // Create a new parser and parse the file supplied
            new InpParser().ParseFile(this, reader);
        }
Example #2
0
        /// <summary>
        /// Set up a parser test. This method will <see cref="Initialize(string)"/>
        /// the <paramref name="value"/> passed, read the value using an <see cref="InpFileReader"/>,
        /// parse the file using an <see cref="InpParser"/> and then return the created
        /// <see cref="InpProject"/>.
        /// </summary>
        /// <param name="value">The string that will be parsed</param>
        protected virtual IInpProject SetupProject(string value)
        {
            // Initialize the project from the string passed to
            // this method
            Initialize(value);

            // Initialize the project, reader and parser
            var project = new InpProject();
            var reader  = new InpFileReader(MemoryStream);
            var parser  = new InpParser();

            // Parse the file using the above project, reader and parser
            parser.ParseFile(project, reader);

            // return the project
            return(project);
        }
Example #3
0
        public void ReadLineTests(string inString, string[] expectedLines)
        {
            // Initialize the stream
            Initialize(inString);

            // The strings the will compared with the expected lines
            var strings = new List <string>(expectedLines.Length);

            // Set up the reader and strings
            using var reader = new InpFileReader(MemoryStream);

            // Read all of the lines in the stream
            while (!reader.EndOfStream)
            {
                strings.Add(reader.ReadLine());
            }

            // Assert that the lines from the stream are
            // equal to the expected lines
            Assert.Equal(expectedLines, strings.ToArray());
        }
Example #4
0
        public void PeekedLineTests(string inString, string[] expectedLines)
        {
            // Initialize the stream
            Initialize(inString);

            // The array that the lines will be added to
            var stringArray = new List <string>(expectedLines.Length);

            // The reader which will be used for this test
            using var reader = new InpFileReader(MemoryStream);

            // The peeked line should be the first line in the
            // expected array
            Assert.Equal(expectedLines[0], reader.PeekLine());

            // Read the fist line into the array
            stringArray.Add(reader.ReadLine());

            // Now peek the second line
            Assert.Equal(expectedLines[1], reader.PeekLine());

            // read the second line
            stringArray.Add(reader.ReadLine());

            // Now peek the final line
            Assert.Equal(expectedLines[2], reader.PeekLine());

            // Read the final line into the array
            stringArray.Add(reader.ReadLine());

            // Reading past the end of the stream should return null
            Assert.Null(reader.PeekLine());

            // Finally the expected lines should match the
            // outputed string array
            Assert.Equal(expectedLines, stringArray);
        }