示例#1
0
        public void OperatorAdd()
        {
            _left  = 10;
            _right = 5;
            Assert.AreEqual(_left + _right, MondValue.Number(10 + 5));

            _left  = "abc";
            _right = "def";
            Assert.AreEqual(_left + _right, MondValue.String("abc" + "def"));

            _left  = "abc";
            _right = 123;
            Assert.AreEqual(_left + _right, MondValue.String("abc" + 123));

            _left  = 123;
            _right = "abc";
            Assert.AreEqual(_left + _right, MondValue.String(123 + "abc"));

            _left  = MondValue.Null;
            _right = "abc";
            Assert.AreEqual(_left + _right, MondValue.String("null" + "abc")); // TODO: this shouldn't be allowed imo

            _left  = MondValue.Null;
            _right = MondValue.Null;
            Assert.Throws <MondRuntimeException>(() => { _left += _right; });
        }
示例#2
0
        public void OperatorNot()
        {
            _left = 10;
            Assert.AreEqual(~_left, MondValue.Number(~10));

            _left = "10";
            Assert.Throws <MondRuntimeException>(() => { _left = ~_left; });
        }
示例#3
0
        public void OperatorPow()
        {
            _left  = 10.0;
            _right = 7.0;
            Assert.AreEqual(_left.Pow(_right), MondValue.Number(Math.Pow(10.0, 7.0)));

            _left  = 123;
            _right = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left = _left.Pow(_right); });
        }
示例#4
0
        public void OperatorModulo()
        {
            _left  = 10.0;
            _right = 7.0;
            Assert.AreEqual(_left % _right, MondValue.Number(10.0 % 7.0));

            _left  = 123;
            _right = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left %= _right; });
        }
示例#5
0
        public void OperatorMultiply()
        {
            _left  = 10;
            _right = 5;
            Assert.AreEqual(_left * _right, MondValue.Number(10 * 5));

            _left  = 123;
            _right = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left *= _right; });
        }
示例#6
0
        public void OperatorSubtract()
        {
            _left  = 10;
            _right = 5;
            Assert.AreEqual(_left - _right, MondValue.Number(10 - 5));

            _left  = 123;
            _right = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left -= _right; });
        }
示例#7
0
文件: Utility.cs 项目: foobit/Mond
        public static MondValue JsonProgram(ProgramInfo program)
        {
            var obj = MondValue.Object();

            obj["FileName"]    = program.FileName;
            obj["SourceCode"]  = program.DebugInfo.SourceCode;
            obj["FirstLine"]   = FirstLineNumber(program.DebugInfo);
            obj["Breakpoints"] = MondValue.Array(program.Breakpoints.Select(e => MondValue.Number(e)));
            return(obj);
        }
示例#8
0
        public void OperatorLShift()
        {
            _left  = 10.0;
            _right = 7.0;
            Assert.AreEqual(_left.LShift(_right), MondValue.Number(10 << 7));

            _left = 10.0;
            Assert.AreEqual(_left << 7, MondValue.Number(10 << 7));

            _left  = 123;
            _right = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left = _left.LShift(_right); });

            _left = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left = _left.LShift(_right); });
        }
示例#9
0
        public void OperatorRShift()
        {
            _left  = 10.0;
            _right = 2.0;
            Assert.AreEqual(_left.RShift(_right), MondValue.Number(10 >> 2));

            _left = 10.0;
            Assert.AreEqual(_left >> 2, MondValue.Number(10 >> 2));

            _left  = 123;
            _right = "abc";
            Assert.Throws <MondRuntimeException>(() => { _left = _left.RShift(_right); });

            _left  = "abc";
            _right = 2.0;
            Assert.Throws <MondRuntimeException>(() => { _left = _left.RShift(_right); });
        }
示例#10
0
            public MondValue ParseValue()
            {
                var token = Take();

                switch (token.Type)
                {
                case TokenType.True:
                    return(MondValue.True);

                case TokenType.False:
                    return(MondValue.False);

                case TokenType.Null:
                    return(MondValue.Null);

                case TokenType.Undefined:
                    return(MondValue.Undefined);

                case TokenType.String:
                    return(MondValue.String(token.Value));

                case TokenType.Number:
                    double number;

                    if (!double.TryParse(token.Value, out number))
                    {
                        throw new MondRuntimeException(DeserializePrefix + "invalid number '{0}'", token.Value);
                    }

                    return(MondValue.Number(number));

                case TokenType.ObjectStart:
                    return(ParseObject());

                case TokenType.ArrayStart:
                    return(ParseArray());

                default:
                    throw new MondRuntimeException(DeserializePrefix + "expected Value but got {0}", token.Type);
                }
            }
示例#11
0
        private void VisitProgram(MondProgram program)
        {
            var debugInfo = program.DebugInfo;

            if (IsMissingDebugInfo(debugInfo))
            {
                return;
            }

            int         id;
            ProgramInfo programInfo;

            lock (_sync)
            {
                if (_seenPrograms.Contains(program))
                {
                    return;
                }

                _seenPrograms.Add(program);

                id          = _programs.Count;
                programInfo = new ProgramInfo(program);

                _programs.Add(programInfo);
            }

            var message = MondValue.Object();

            message["Type"]        = "NewProgram";
            message["Id"]          = id;
            message["FileName"]    = programInfo.FileName;
            message["SourceCode"]  = debugInfo.SourceCode;
            message["FirstLine"]   = Utility.FirstLineNumber(debugInfo);
            message["Breakpoints"] = MondValue.Array(programInfo.Breakpoints.Select(e => MondValue.Number(e)));

            Broadcast(message);
        }