Exemple #1
0
        public void LiteralTest()
        {
            var intlit = new LiteralIntExpression(5);

            Assert.AreEqual(5, intlit.Value);
            Assert.AreEqual("5", intlit.ToString());

            var fltlit = new LiteralFloatExpression(9.9);

            Assert.AreEqual(9.9, fltlit.Value);
            Assert.IsTrue(fltlit.ToString().StartsWith("9.9"));

            var strlit = new LiteralStringExpression("hello");

            Assert.AreEqual("hello", strlit.Value);
            Assert.AreEqual("\"hello\"", strlit.ToString());

            //foreach (var l in new Literal[] { intlit, fltlit, strlit })
            //    Assert.IsInstanceOf<Literal>(Expression.FromPtr(l.Ptr, IntPtr.Zero));
        }
Exemple #2
0
        public void ApplicationTest()
        {
            var arg1  = new LiteralIntExpression(1);
            var arg2  = new LiteralStringExpression("xyz");
            var fname = "hello";

            var expr = new ApplicationExpression(fname, new Expression[] { arg1, arg2 });

            Assert.AreEqual("hello 1 \"xyz\"", expr.ToString());
            Assert.IsInstanceOf <ApplicationExpression>(expr.Function);
            Assert.IsInstanceOf <LiteralExpression>(expr.Argument);
            Assert.AreEqual("xyz", (expr.Argument as LiteralStringExpression).Value);
            var inner = expr.Function as ApplicationExpression;

            Assert.IsInstanceOf <FunctionExpression>(inner.Function);
            var fun = inner.Function as FunctionExpression;

            Assert.AreEqual("hello", fun.Name);

            Assert.AreEqual(1, (inner.Argument as LiteralIntExpression).Value);
        }