Beispiel #1
0
        public void Outputs([NotNull] string expectedValue)
        {
            var testCode = $"{GlobalCode()}\r\n" +
                           $"<ROUTINE GO () {Expression()}>";

            ZlrHelper.RunAndAssert(testCode, input.ToString(), expectedValue, warningChecks, wantCompileOutput);
        }
Beispiel #2
0
        public void GivesNumber([NotNull] string expectedValue)
        {
            var testCode = $"{GlobalCode()}\r\n" +
                           $"<ROUTINE GO () <PRINTN {Expression()}>>";

            ZlrHelper.RunAndAssert(testCode, input.ToString(), expectedValue, warningChecks);
        }
Beispiel #3
0
        public void DoesNotThrow()
        {
            var testCode = $"{GlobalCode()}\r\n" +
                           $"<ROUTINE GO ({argSpec})\r\n" +
                           $"\t{body}\r\n" +
                           "\t<QUIT>>";

            ZlrHelperRunResult result;

            try
            {
                result = ZlrHelper.Run(testCode, null, compileOnly: true, wantDebugInfo: wantDebugInfo);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but caught {0}", ex);

                // can't get here, but the compiler doesn't know that...
                // ReSharper knows, but we still can't remove the return

                // ReSharper disable once HeuristicUnreachableCode
                return;
            }

            CheckWarnings(result);
        }
Beispiel #4
0
        public void DoesNotCompile()
        {
            var testCode = $"{GlobalCode()}\r\n" +
                           $"<ROUTINE GO ({argSpec})\r\n" +
                           $"\t{body}\r\n" +
                           "\t<QUIT>>";

            var result = ZlrHelper.Run(testCode, null, compileOnly: true, wantDebugInfo: wantDebugInfo);

            Assert.AreEqual(ZlrTestStatus.CompilationFailed, result.Status);

            CheckWarnings(result);
        }
Beispiel #5
0
        public void Compiles()
        {
            var testCode =
                $"{GlobalCode()}\r\n" +
                "<GLOBAL DUMMY?VAR <>>\r\n" +
                "<ROUTINE GO ()\r\n" +
                $"\t<SETG DUMMY?VAR {Expression()}>\r\n" +
                "\t<QUIT>>";

            var result = ZlrHelper.Run(testCode, null, compileOnly: true, wantDebugInfo: wantDebugInfo);

            Assert.IsTrue(result.Status > ZlrTestStatus.CompilationFailed,
                          "Failed to compile");

            CheckWarnings(result);
        }
Beispiel #6
0
        public void Implies([ItemNotNull][NotNull] params string[] conditions)
        {
            var sb = new StringBuilder();

            foreach (var c in conditions)
            {
                sb.AppendFormat(
                    "<COND ({0}) (T <INC FAILS> <PRINTI \"FAIL: {1}|\">)>\r\n",
                    c,
                    c.Replace("\\", "\\\\").Replace("\"", "\\\""));
            }

            var testCode =
                $"{GlobalCode()}\r\n" +
                $"<ROUTINE TEST-IMPLIES (\"AUX\" FAILS) {sb} .FAILS>\r\n" +
                "<ROUTINE GO () <OR <TEST-IMPLIES> <PRINTI \"PASS\">>>";

            ZlrHelper.RunAndAssert(testCode, input.ToString(), "PASS", warningChecks);
        }
Beispiel #7
0
        public void DoesNotCompile([CanBeNull] Predicate <ZlrHelperRunResult> resultFilter = null,
                                   [CanBeNull] string message = null)
        {
            var testCode =
                $"{GlobalCode()}\r\n" +
                "<GLOBAL DUMMY?VAR <>>\r\n" +
                "<ROUTINE GO ()\r\n" +
                $"\t<SETG DUMMY?VAR {Expression()}>\r\n" +
                "\t<QUIT>>";

            var result = ZlrHelper.Run(testCode, null, compileOnly: true, wantDebugInfo: wantDebugInfo);

            Assert.AreEqual(ZlrTestStatus.CompilationFailed, result.Status);

            CheckWarnings(result);

            if (resultFilter != null)
            {
                Assert.IsTrue(resultFilter(result), message ?? "Result filter failed");
            }
        }
Beispiel #8
0
        CodeMatchingResult GeneratesCodeMatching([NotNull] Action <string> checkGeneratedCode)
        {
            var testCode = $"{GlobalCode()}\r\n" +
                           "<ROUTINE GO ()\r\n" +
                           $"\t{Expression()}\r\n" +
                           "\t<QUIT>>";

            var helper = new ZlrHelper(testCode, null);

            Assert.IsTrue(helper.Compile(wantDebugInfo: wantDebugInfo), "Failed to compile");

            var output = helper.GetZapCode();

            checkGeneratedCode(output);

            CheckWarnings(new ZlrHelperRunResult
            {
                WarningCount = helper.WarningCount,
                Diagnostics  = helper.Diagnostics,
            });

            return(new CodeMatchingResult(output));
        }
Beispiel #9
0
 public void Outputs([NotNull] string expectedValue)
 {
     ZlrHelper.RunAndAssert(code, null, expectedValue);
 }