Example #1
0
        private Object PerformWrite(Object value)
        {
            var str = Stringify.This(value);

            _interactivity.Write(str);
            return(null);
        }
Example #2
0
        private void Evaluate(String content, Boolean showOutput)
        {
            try
            {
                var result = _interactivity.Run(_engine, content);

                if (showOutput)
                {
                    var output = default(String);

                    if (result != null)
                    {
                        output = Stringify.This(result);
                    }

                    _interactivity.Info(output);
                    _engine.Scope["ans"] = result;
                }
            }
            catch (ParseException ex)
            {
                _interactivity.Display(ex.Error, content);
            }
            catch (Exception ex)
            {
                _interactivity.Error(ex.Message);
            }

            _interactivity.Write(Environment.NewLine);
        }
        public void StringifyNullIsUndefined()
        {
            var value     = default(Object);
            var result    = Stringify.This(value);
            var undefined = Stringify.Undefined();

            Assert.AreEqual(undefined, result);
        }
Example #4
0
        private String Info(String topic, Object value)
        {
            var sb       = new StringBuilder();
            var type     = value.ToType();
            var typeName = $"{type["name"]}";

            sb.AppendFormat("Type of '{0}': ", topic);
            sb.AppendLine(typeName);
            sb.Append("Number value: ");
            sb.Append(Stringify.This(value.ToNumber()));
            sb.AppendLine();
            sb.Append("Boolean value: ");
            sb.Append(Stringify.This(value.ToBoolean()));
            sb.AppendLine();
            sb.Append("String value: ");
            sb.Append(Stringify.This(value));

            switch (typeName)
            {
            case "Number":
            case "Complex":
            case "String":
            case "Boolean":
            case "Function":
            case "Undefined":
                break;

            case "CMatrix":
                sb.AppendLine();
                sb.Append("Columns: ");
                sb.Append(((Complex[, ])value).GetLength(1));
                sb.AppendLine();
                sb.Append("Rows: ");
                sb.Append(((Complex[, ])value).GetLength(0));
                break;

            case "Matrix":
                sb.AppendLine();
                sb.Append("Columns: ");
                sb.Append(((Double[, ])value).GetLength(1));
                sb.AppendLine();
                sb.Append("Rows: ");
                sb.Append(((Double[, ])value).GetLength(0));
                break;

            case "Object":
                sb.AppendLine();
                sb.Append("Keys: ");
                sb.Append(String.Join(", ", ((IDictionary <String, Object>)value).Select(m => m.Key)));
                break;
            }

            return(sb.ToString());
        }
        public void StringifyDelegateIsFunction()
        {
            var del   = new Function(args => null);
            var value = default(Object);

            value = del;
            var result = Stringify.This(value);
            var func   = Stringify.This(del);

            Assert.AreEqual(func, result);
        }
        public void StringifyStringIsIdentity()
        {
            var str   = "Hallo";
            var value = default(Object);

            value = str;
            var result = Stringify.This(value);
            var self   = Stringify.This(str);

            Assert.AreEqual(self, result);
        }
        public void StringifyBooleanIsBoolean()
        {
            var bln   = true;
            var value = default(Object);

            value = bln;
            var result  = Stringify.This(value);
            var boolean = Stringify.This(bln);

            Assert.AreEqual(boolean, result);
        }
        public void StringifyDoubleIsNumber()
        {
            var dbl   = 2.0;
            var value = default(Object);

            value = dbl;
            var result = Stringify.This(value);
            var number = Stringify.This(dbl);

            Assert.AreEqual(number, result);
        }
        public void StringifyDoubleUsesInvariantCulture()
        {
            var dbl     = 2.8;
            var thread  = Thread.CurrentThread;
            var culture = thread.CurrentUICulture;

            thread.CurrentCulture = new CultureInfo("de-de");
            Assert.AreEqual("2,8", dbl.ToString());
            Assert.AreEqual("2.8", Stringify.This(dbl));
            thread.CurrentCulture = culture;
        }
        public void StringifyDictionaryIsObject()
        {
            var dict = new Dictionary <String, Object>
            {
                { "Foo", "Bar" }
            };
            var value = default(Object);

            value = dict;
            var result = Stringify.This(value);
            var obj    = Stringify.This(dict);

            Assert.AreEqual(obj, result);
        }
Example #11
0
 public void Info(Object result)
 {
     if (result == null)
     {
         Console.ForegroundColor = ConsoleColor.Yellow;
         Console.Write("Undefined");
         Console.ResetColor();
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.White;
         Console.Write(Stringify.This(result));
         Console.ResetColor();
     }
 }
        public void StringifyDoubleArrayIsMatrix()
        {
            var array = new Double[, ]
            {
                { 1, 2 },
                { 3, 4 }
            };
            var value = default(Object);

            value = array;
            var result = Stringify.This(value);
            var mat    = Stringify.This(array);

            Assert.AreEqual(mat, result);
        }
Example #13
0
        public static Object To(this Object value, String type)
        {
            switch (type)
            {
            case "Number": return(value.ToNumber());

            case "String": return(Stringify.This(value));

            case "Boolean": return(value.ToBoolean());

            case "Matrix": return(value.ToNumber().ToMatrix());

            case "Function": return(value as Function);

            case "Object": return(value as IDictionary <String, Object>);

            case "Undefined": return(null);
            }

            return(null);
        }
Example #14
0
        private String Info(String topic, Object value)
        {
            var sb = new StringBuilder();
            var type = value.ToType();
            sb.AppendFormat("Type of '{0}': ", topic);
            sb.AppendLine(type);
            sb.Append("Number value: ");
            sb.Append(Stringify.This(value.ToNumber()));
            sb.AppendLine();
            sb.Append("Boolean value: ");
            sb.Append(Stringify.This(value.ToBoolean()));
            sb.AppendLine();
            sb.Append("String value: ");
            sb.Append(Stringify.This(value));

            switch (type)
            {
                case "Number":
                    break;
                case "String":
                    break;
                case "Boolean":
                    break;
                case "Matrix":
                    break;
                case "Function":
                    break;
                case "Object":
                    sb.AppendLine();
                    sb.Append("Keys: ");
                    sb.Append(String.Join(", ", ((IDictionary<String, Object>)value).Select(m => m.Key)));
                    break;
                case "Undefined":
                    break;
            }

            return sb.ToString();
        }
Example #15
0
 void ITreeWalker.Visit(ConstantExpression expression)
 {
     Header("Expression/Constant/" + expression.Value.GetType().Name);
     WriteLine("- Value: " + Stringify.This(expression.Value));
 }
Example #16
0
        public void WriteLine(Object value)
        {
            var str = Stringify.This(value);

            Console.WriteLine(str);
        }