public void ItUsesTextWindowWhenNothingIsNeeded()
        {
            var compilation = new SmallBasicCompilation("x = 1");

            compilation.Analysis.UsesTextWindow.Should().Be(true);
            compilation.Analysis.UsesGraphicsWindow.Should().Be(false);
        }
Пример #2
0
        private static async Task <SmallBasicEngine> VerifyRuntimeAux(this SmallBasicCompilation compilation, IEngineLibraries libraries, string memoryContents)
        {
            compilation.VerifyDiagnostics();

            SmallBasicEngine engine = new SmallBasicEngine(compilation, libraries);

            while (engine.State != ExecutionState.Terminated)
            {
                engine.State.Should().Be(ExecutionState.Running, "loggers cannot move to another state");
                await engine.Execute().ConfigureAwait(false);
            }

            DebuggerSnapshot snapshot = engine.GetSnapshot();

            snapshot.ExecutionStack.Should().BeEmpty();

            if (!memoryContents.IsDefault())
            {
                string values = Environment.NewLine
                                + snapshot.Memory.Select(pair => $"{pair.Key} = {pair.Value.ToDisplayString()}").Join(Environment.NewLine);

                values.Should().Be(memoryContents);
            }

            return(engine);
        }
        public void ItDoesNotUseGraphicsWindowWhenNotNeeded()
        {
            var compilation = new SmallBasicCompilation("TextWindow.WriteLine(5)");

            compilation.Analysis.UsesTextWindow.Should().Be(true);
            compilation.Analysis.UsesGraphicsWindow.Should().Be(false);
        }
        static CompilationStore()
        {
            Compilation = new SmallBasicCompilation(
                @"' A new Program!
TextWindow.WriteLine(""What is your name?"")
name = TextWindow.Read()
TextWindow.WriteLine(""Hello "" + name + ""!"")");
        }
Пример #5
0
        public static SmallBasicCompilation VerifyDiagnostics(this SmallBasicCompilation compilation, params Diagnostic[] diagnostics)
        {
            string[] textLines = Regex.Split(compilation.Text, @"\r?\n");
            string   expected  = SerializeDiagnostics(textLines, diagnostics);
            string   actual    = SerializeDiagnostics(textLines, compilation.Diagnostics);

            expected.Should().Be(actual);
            return(compilation);
        }
        public static void NotifyCodeChanged(string code)
        {
            Compilation = new SmallBasicCompilation(code);

            if (!CodeChanged.IsDefault())
            {
                CodeChanged();
            }
        }
Пример #7
0
        public static async Task <SmallBasicEngine> VerifyLoggingRuntime(this SmallBasicCompilation compilation, string expectedLog = default, string memoryContents = default)
        {
            StringBuilder log    = new StringBuilder();
            var           engine = await VerifyRuntimeAux(compilation, new LoggingEngineLibraries(log), memoryContents).ConfigureAwait(false);

            if (!expectedLog.IsDefault())
            {
                (Environment.NewLine + log.ToString()).Should().Be(expectedLog);
            }

            return(engine);
        }
Пример #8
0
        public static async Task <SmallBasicEngine> VerifyExecutionState(this SmallBasicCompilation compilation, ExecutionState executionState, ExecutionMode mode = ExecutionMode.RunToEnd)
        {
            compilation.VerifyDiagnostics();

            SmallBasicEngine engine = new SmallBasicEngine(compilation, new LibrariesCollection());

            engine.Mode = mode;
            await engine.Execute().ConfigureAwait(false);

            engine.State.Should().Be(executionState);

            return(engine);
        }
Пример #9
0
        internal RuntimeAnalysis(SmallBasicCompilation compilation)
        {
            Debug.Assert(!compilation.Diagnostics.Any(), "Cannot analyze a compilation with errors.");
            this.Compilation = compilation;

            this.Visit(this.Compilation.MainModule);
            foreach (var subModule in this.Compilation.SubModules.Values)
            {
                this.Visit(subModule);
            }

            if (!this.UsesGraphicsWindow)
            {
                this.UsesTextWindow = true;
            }
        }
        private static void TestForHover(string text, params string[] expectedHover)
        {
            var markerCompilation = new SmallBasicCompilation(text);
            var marker            = markerCompilation.Diagnostics.Single(d => d.Code == DiagnosticCode.UnrecognizedCharacter && d.Args.Single() == "$");

            var start = marker.Range.Start;
            var end   = marker.Range.End;

            start.Line.Should().Be(end.Line);
            start.Column.Should().Be(end.Column);

            var compilation = new SmallBasicCompilation(text.Replace("$", string.Empty, StringComparison.CurrentCulture));
            var hover       = compilation.ProvideHover((start.Line, start.Column));

            hover.Should().Equal(expectedHover);
        }
Пример #11
0
 public static Task <SmallBasicEngine> VerifyRealRuntime(this SmallBasicCompilation compilation, string memoryContents = default)
 {
     return(VerifyRuntimeAux(compilation, new LibrariesCollection(), memoryContents));
 }