示例#1
0
        public void ExprOp_Calc_O_NOT_Considers_Int_10_ToBe_True_AndInversesIt()
        {
            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_NOT);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(10)
            };
            Assert.False(exprOp1.Calc(null).Bool);
        }
示例#2
0
        public void ExprOp_Calc_O_GTE_ReturnsTrueIfLeftEqualsToRight()
        {
            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_GTE);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(2)
            };
            exprOp1.Right = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(2)
            };
            Assert.Equal(2 >= 2, exprOp1.Calc(null).Bool);
        }
示例#3
0
        public void ExprOp_Calc_O_OR_Considers_Left_Int_10_ToBe_True()
        {
            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_OR);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(10)
            };
            exprOp1.Right = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.False
            };
            Assert.True(exprOp1.Calc(null).Bool);
        }
示例#4
0
        public void ExprOp_Calc_O_AND_Considers_Left_Int_0_ToBe_False()
        {
            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_AND);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(0)
            };
            exprOp1.Right = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.True
            };
            Assert.IsFalse(exprOp1.Calc(null).Bool);
        }
示例#5
0
        public void ExprOp_Calc_O_GTE_ReturnsFalseIfLeftLessThanRight()
        {
            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_GTE);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(1)
            };
            exprOp1.Right = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(2)
            };
            Assert.AreEqual(1 >= 2, exprOp1.Calc(null).Bool);
        }
示例#6
0
文件: Xact.cs 项目: taiab/nledger
        private static Value FnAny(CallScope args)
        {
            Post   post = args.Context <Post>();
            ExprOp expr = args.Get <ExprOp>(0);

            foreach (Post p in post.Xact.Posts)
            {
                BindScope boundScope = new BindScope(args, p);
                if (expr.Calc(boundScope, args.Locus, args.Depth).AsBoolean)
                {
                    return(Value.True);
                }
            }
            return(Value.False);
        }
示例#7
0
        private static Value FnAll(CallScope args)
        {
            Account account = args.Context <Account>();
            ExprOp  expr    = args.Get <ExprOp>(0);

            foreach (Post p in account.Posts)
            {
                BindScope boundScope = new BindScope(args, p);
                if (!expr.Calc(boundScope, args.Locus, args.Depth).AsBoolean)
                {
                    return(Value.False);
                }
            }
            return(Value.True);
        }
示例#8
0
        public void ExprOp_Calc_O_DIV_DoesNotModifyOriginalLeftArgument()
        {
            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_DIV);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(10)
            };
            exprOp1.Right = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = Value.Get(5)
            };
            Value result = exprOp1.Calc(null);

            Assert.Equal(10, exprOp1.Left.AsValue.AsLong);
            Assert.Equal(2, result.AsLong);
        }
示例#9
0
        public void ExprOp_Calc_O_OR_ReturnsLeftValueInCaseItIsConsideredAsTrue()
        {
            Value leftValue  = Value.StringValue("some-left-string-value");
            Value rightValue = Value.False;

            ExprOp exprOp1 = new ExprOp(OpKindEnum.O_OR);

            exprOp1.Left = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = leftValue
            };
            exprOp1.Right = new ExprOp(OpKindEnum.VALUE)
            {
                AsValue = rightValue
            };
            Value result = exprOp1.Calc(null);

            Assert.Equal("some-left-string-value", result.AsString);
        }
示例#10
0
        public void ExprParser_Parse_HandlesAddExpression()
        {
            string          expr     = "2+3";
            InputTextStream inStream = new InputTextStream(expr);

            ExprParser parser = new ExprParser();
            ExprOp     result = parser.Parse(inStream);

            Assert.IsNotNull(result);
            Assert.AreEqual(OpKindEnum.O_ADD, result.Kind);
            Assert.AreEqual(2, result.Left.AsValue.AsLong);
            Assert.AreEqual(3, result.Right.AsValue.AsLong);

            // Just in case...
            EmptyScope scope = new EmptyScope();
            Value      val   = result.Calc(scope);

            Assert.AreEqual(5, val.AsLong);
        }
示例#11
0
文件: Post.cs 项目: maznabili/nledger
        private static Value FnAll(CallScope args)
        {
            Post   post = args.Context <Post>();
            ExprOp expr = args.Get <ExprOp>(0);

            foreach (Post p in post.Xact.Posts)
            {
                BindScope boundScope = new BindScope(args, p);
                if (p == post && args.Has <ExprOp>(1) && !args.Get <ExprOp>(1).Calc(boundScope, args.Locus, args.Depth).AsBoolean)
                {
                    // If the user specifies any(EXPR, false), and the context is a
                    // posting, then that posting isn't considered by the test.
                    ;                       // skip it
                }
                else if (expr.Calc(boundScope, args.Locus, args.Depth).AsBoolean)
                {
                    return(Value.False);
                }
            }
            return(Value.True);
        }