コード例 #1
0
        public void ValidationShouldSucceed_Empty()
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep>());

            // act
            var result = validator.Validate(new[] { "" });

            // assert
            Assert.IsTrue(result, "Validation should succeed if no steps are specified");
        }
コード例 #2
0
        public void ValidationShouldFail_HasMatchingQuotes(string[] lines)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new HasMatchingQuotes()
            });

            // act
            var result = validator.Validate(lines);

            // assert
            Assert.IsFalse(result, $"Testcase {string.Join(" ", lines)} failed");
        }
コード例 #3
0
        public void ValidationShouldSucceed_HasMatchingQuotes(string[] lines)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new HasMatchingQuotes()
            });

            // act
            var result = validator.Validate(lines);

            // assert
            Assert.IsTrue(result);
        }
コード例 #4
0
        public void ValidationShouldFail_HasValidLineEnds(string line)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new HasValidLineEndsStep()
            });

            // act
            var result = validator.Validate(new[] { line });

            // assert
            Assert.IsFalse(result);
        }
コード例 #5
0
        public void ValidationShouldFail_PropertiesOk(string prop)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new PropertiesOk()
            });

            // act
            var result = validator.Validate(new[] { prop });

            // assert
            Assert.IsFalse(result, $"Testcase {prop} failed");
        }
コード例 #6
0
        public void ValidationShouldFail_ConstantsOk(string constant)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new ConstantsOk()
            });

            // act
            var result = validator.Validate(new[] { constant });

            // assert
            Assert.IsFalse(result, $"Testcase {constant} failed");
        }
コード例 #7
0
        public void ValidationShouldFail_BlockDeclarationsOk(string block)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new BlockDeclarationsOk()
            });

            // act
            var result = validator.Validate(new[] { block });

            // assert
            Assert.IsFalse(result, $"Testcase {block} failed");
        }
コード例 #8
0
        public void ValidationShouldFail_ContainsStartFunction(string[] lines)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new ContainsStartFunction()
            });

            // act
            var result = validator.Validate(lines);

            // assert
            Assert.IsFalse(result, $"Testcase {string.Join(" ", lines)} failed");
        }
コード例 #9
0
        public void ValidationShouldSucceed_ContainsProgramUtility(string[] lines)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new ContainsProgramUtility()
            });

            // act
            var result = validator.Validate(lines);

            // assert
            Assert.IsTrue(result, $"Testcase {string.Join(" ", lines)} failed");
        }
コード例 #10
0
        public void ValidationShouldFail_BlockOpeningsOk(string nextLine)
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new BlockOpeningsOk()
            });
            var result = false;

            // act
            foreach (var block in PreValidator.Blocks)
            {
                result = validator.Validate(new[] { block, nextLine });
            }

            // assert
            Assert.IsFalse(result, $"Testcase {nextLine} failed");
        }
コード例 #11
0
        public void ValidationShouldSucceed_BlockOpeningsOk()
        {
            // arrange
            var validator = new PreValidator(new List <IPreValidationStep> {
                new BlockOpeningsOk()
            });
            var result = false;

            // act
            foreach (var block in PreValidator.Blocks)
            {
                result = validator.Validate(new[] { block, "{" });
            }

            // assert
            Assert.IsTrue(result);
        }
コード例 #12
0
ファイル: Worker.cs プロジェクト: tjhlansbergen/E
        private void _preValidate()
        {
            Extensions.WriteColoredLine("Pre-validation: ", ConsoleColor.DarkCyan);

            var validator = new PreValidator(new List <IPreValidationStep>
            {
                new HasValidLineEndsStep(),
                new HasMatchingQuotes(),
                new HasMatchingBraces(),
                new ContainsProgramUtility(),
                new ContainsStartFunction(),
                new BlockOpeningsOk(),
                new BlockDeclarationsOk(),
                new ConstantsOk(),
                new PropertiesOk(),
                new AssignemtnsOk(),
            });

            var preValidationResult = validator.Validate(_lines);

            if (Verbose)
            {
                foreach (var validationStepResult in validator.Results)
                {
                    Extensions.WriteColoredLine(" - " + validationStepResult.Output, validationStepResult.Valid ? ConsoleColor.DarkGreen : ConsoleColor.Red);
                }
            }

            Console.WriteLine();
            Console.WriteLine(preValidationResult ? $"Pre-validation for `{_name}` successful" : $"Pre-validation for {_name} failed!");
            Console.WriteLine();
            if (preValidationResult == false)
            {
                throw new PreValidationException("EInterpreter stopped before execution because of failing Pre-validation");
            }
        }