Ejemplo n.º 1
0
        public void Evalate_WhenLineWithNumbered_AddsItToLines()
        {
            var parser = MakeParser();
            var rte    = MakeRunTimeEnvironment();
            var repl   = new ReadEvaluatePrintLoop(rte, parser);
            var line   = new Line("10", MakeStatement());

            var result = repl.Evaluate(line);

            Assert.IsTrue(rte.Lines.Contains(line));
        }
Ejemplo n.º 2
0
        public void Evaluate_WhenLineWithoutNumber_RunsStatementImmediately()
        {
            var parser      = MakeParser();
            var inputOutput = MakeInputOutput();
            var rte         = MakeRunTimeEnvironment(inputOutput);
            var repl        = new ReadEvaluatePrintLoop(rte, parser);
            var line        = new Line(MakeStatement(() => inputOutput.Write("Windows")));

            var result = repl.Evaluate(line);

            Assert.AreEqual("Windows", inputOutput.OutputStrings[0]);
        }
Ejemplo n.º 3
0
        public void Evaluate_WithResultedStatement_ReturnsResult()
        {
            var parser      = MakeParser();
            var inputOutput = MakeInputOutput();
            var rte         = MakeRunTimeEnvironment(inputOutput);
            var repl        = new ReadEvaluatePrintLoop(rte, parser);

            var statement = MakeStatement(new EvaluateResult("message"));

            var result = repl.Evaluate(statement);

            Assert.AreEqual("message", result.Message);
        }
Ejemplo n.º 4
0
        public void Evaluate_WithExceptedStatement_ThrowsRunTimeException()
        {
            var parser      = MakeParser();
            var inputOutput = MakeInputOutput();
            var rte         = MakeRunTimeEnvironment(inputOutput);
            var repl        = new ReadEvaluatePrintLoop(rte, parser);

            var statement = MakeStatement(() => { throw new Exception(); });

            repl.Evaluate(statement);

            var condition = repl.DoEvaluateImmediately(null);
        }