Esempio n. 1
0
        public void capture_standard_output()
        {
            //Arrange
            var asFound = Console.Out;

            try
            {
                var current_level = new nutility.InputInstanceReplLevel("UC-2", new cli1.RootInput());
                var tree          = new nutility.Tree <string, nutility.InputReplLevel> {
                    Value = current_level
                };

                var input_lines = new[] { "-f1 -n=-132" };
                var reader      = new StringReader(Common.asTextContent(input_lines));
                var writer      = new StringWriter();
                Console.SetOut(writer);
                var repl = new nutility.REPL {
                    Reader = reader, Writer = writer
                };

                //Act
                repl.Loop(tree);

                //Assert
                Assert.IsTrue($"{writer}".Contains("N: -132"));
            }
            finally
            {
                Console.SetOut(asFound);
            }
        }
Esempio n. 2
0
 private void @new(string key, nutility.Tree <string, InputReplLevel> tree)
 {
     if (reserved.ContainsKey(key) || key.StartsWith("?"))
     {
         Writer.WriteLine($"For clarity, please choose another id because '{key}' is reserved.");
     }
     else if (tree.ContainsKey(key))
     {
         Writer.WriteLine($"{key} already identifies an existing input class or input instance.");
     }
     else
     {
         InputClassReplLevel current_class = tree.Value as InputClassReplLevel;
         if (current_class == null)
         {
             Writer.WriteLine($"A new input instance is currently supported only on input class levels.");
         }
         else
         {
             var new_instance = Activator.CreateInstance(current_class.InputClass);
             var new_level    = new nutility.InputInstanceReplLevel(key, new_instance);
             tree[new_level.ID] = new nutility.Tree <string, nutility.InputReplLevel> {
                 Value = new_level, Parent = tree
             };
             Writer.WriteLine($"\t{key} ({current_class.InputClass.FullName})");
         }
     }
 }
Esempio n. 3
0
        public void capture_TextWriter()
        {
            //Arrange
            var input_lines = new[] { "x1 -f1 -n=43" };
            var reader      = new StringReader(Common.asTextContent(input_lines));
            var repl        = new nutility.REPL {
                Reader = reader
            };

            var level_writer  = new StringWriter();
            var current_level = new nutility.InputInstanceReplLevel("x1", new InputY(level_writer));
            var tree          = new nutility.Tree <string, nutility.InputReplLevel> {
                Value = current_level
            };

            //Act
            repl.Loop(tree);

            //Assert
            Assert.AreEqual("N: 43\r\n", $"{level_writer}");
        }