示例#1
0
        public void ShouldReturnCorrectResults(string programName)
        {
            var sourceCodeFileName = programName + SourceCodeFileExtension;
            var sourceCodePath     = Path.Combine(SourceCodesDirectoryPath, programName, sourceCodeFileName);
            var sourceCode         = File.ReadAllText(sourceCodePath);

            var inputDataDirectoryPath = Path.Combine(SourceCodesDirectoryPath, programName, InputDataDirectoryName);
            var inputDataDirectoryInfo = new DirectoryInfo(inputDataDirectoryPath);
            var inputDataFiles         = inputDataDirectoryInfo.GetFiles().Where(f => f.Extension.Equals(InputDataFileExtension));

            var outputDataDirectoryPath = Path.Combine(SourceCodesDirectoryPath, programName, OutputDataDirectoryName);

            foreach (var inputDataFile in inputDataFiles)
            {
                var inputDataPath = inputDataFile.FullName;

                var outputDataPath     = Path.ChangeExtension(Path.Combine(outputDataDirectoryPath, inputDataFile.Name), OutputDataFileExtension);
                var expectedOutputData = File.ReadAllText(outputDataPath);

                using (var inputDataStream = new StreamReader(inputDataPath))
                {
                    using (var outputMemoryStream = new MemoryStream())
                    {
                        _engine.Process(sourceCode, inputDataStream, new StreamWriter(outputMemoryStream));

                        outputMemoryStream.Position = 0;
                        var outputDataReader = new StreamReader(outputMemoryStream);
                        var outputData       = outputDataReader.ReadToEnd();

                        Assert.Equal(expectedOutputData, outputData);
                    }
                }
            }
        }
示例#2
0
        private static void Main(string[] args)
        {
            Console.WriteLine(Messages.WelcomeMessage);

            var config = CollectConfiguration(args);

            if (!config.Validate())
            {
                Console.WriteLine();
                Console.WriteLine(Messages.BadUsageMessage);
                Console.WriteLine();
                Console.WriteLine(Messages.UsageInfoMessage);
                return;
            }

            //try
            {
                var sourceCode = File.ReadAllText(config.SourceCodeFilePath);

                var consoleReader = new StreamReader(Console.OpenStandardInput());
                var consoleWriter = new StreamWriter(Console.OpenStandardOutput());

                Console.WriteLine();
                _cilantroEngine.Process(sourceCode, consoleReader, consoleWriter);

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(Messages.ThankYouMessage);
                Console.WriteLine(Messages.CloseProgramMessage);
                Console.ReadKey();
            }
            //catch(Exception ex)
            //{
            //    Console.WriteLine();
            //    Console.WriteLine(Messages.ErrorMessage);
            //    Console.WriteLine(ex.Message);
            //    Console.WriteLine();

            //    Console.WriteLine(Messages.CloseProgramMessage);
            //    Console.ReadKey();
            //}
        }
示例#3
0
        static void Main(string[] args)
        {
            var sourceCodePath = args[0];
            var sourceCode     = File.ReadAllText(sourceCodePath);

            var mode = ConsoleUIMode.Normal;

            if (args.Length > 1)
            {
                var modeString = args[1];
                switch (modeString.ToLower())
                {
                case "parse-only":
                    mode = ConsoleUIMode.ParseOnly;
                    break;
                }
            }

            var cilantroEngine = new CILantroEngine(sourceCode);

            if (mode == ConsoleUIMode.Normal)
            {
                var consoleReader = new StreamReader(Console.OpenStandardInput());
                var consoleWriter = new StreamWriter(Console.OpenStandardOutput());
                consoleWriter.AutoFlush = true;

                cilantroEngine.Process(consoleReader, consoleWriter);

                Console.ReadKey();
            }
            else if (mode == ConsoleUIMode.ParseOnly)
            {
                var programTree = cilantroEngine.Parse();
                if (programTree == null)
                {
                    throw new ArgumentException("An error occurred while parsing the source code.");
                }
            }
        }