Example #1
0
        protected override bool IsSubmissionComplete(string text)
        {
            text = previous + text;
            var src         = new SourceText(text, "<stdin>");
            var compilation = Compilation.CompileScript(src, "Main", Compilation.StandardReferencePaths);

            return(!compilation.Diagnostics.Any(d => shouldContinueMessages.Contains(d.Message)));
        }
Example #2
0
        protected override void EvaluateSubmission(string text)
        {
            text = previous + text;
            var src = new SourceText(text, "<stdin>");

            compilation = Compilation.CompileScript(src, "Main", Compilation.StandardReferencePaths);
            Console.WriteLine();
            compilation.Evaluate();
            compilation.Diagnostics.WriteTo(Console.Out);
            history.Push(string.Join(Environment.NewLine, compilation.GetFunctionDeclarations()));
            previous = history.Peek();
        }
Example #3
0
        public static void Test_Correct_Value(string text, object value)
        {
            text = $"print({text})";
            var expected    = value.ToString();
            var compilation = Compilation.CompileScript(new SourceText(text, null), "Hello", Compilation.StandardReferencePaths);

            Assert.Empty(compilation.Diagnostics);

            using (var writer = new StringWriter())
            {
                var original = Console.Out;
                Console.SetOut(writer);
                compilation.Evaluate();
                var res = writer.ToString();
                Assert.Equal(expected, res);
            }
        }
Example #4
0
        private static void AssertDiagnostic(string text, string message)
        {
            var annotatedText = AnnotatedText.Parse(text);
            var compilation   = Compilation.CompileScript(new SourceText(annotatedText.Text, null), "Hello", Compilation.StandardReferencePaths);


            if (annotatedText.Spans.Length < 1)
            {
                throw new Exception($"Enter at least one diagnostic <{annotatedText.Spans.Length}>");
            }
            else if (annotatedText.Spans.Length < 1)
            {
                throw new Exception($"Only one diagnostic is should be enterd <{annotatedText.Spans.Length}>");
            }

            var diagnostic = Assert.Single(compilation.Diagnostics.Errors);

            var actualMessage = diagnostic.Message;
            var expectedSpan  = annotatedText.Spans[0];
            var actualSpan    = diagnostic.Span;

            Assert.Equal(message, actualMessage);
            Assert.Equal(expectedSpan, actualSpan);
        }