Example #1
0
        public void TestClosure()
        {
            var    yearFrom = DateTime.Today.Year - 18;
            string result   = Js <User> .Convert(u => DateTime.Today.Year - u.Age > yearFrom);

            Assert.AreEqual("function (u) { return ((2018 - u.Age) > 2000); }", result);
        }
Example #2
0
        public void TestLinqWhere()
        {
            string result = Js <User[], int> .Convert((x, age) => x.Where(t => t.Age > age));

            Assert.AreEqual("function (x, age) { var r = []; for(var i=0;i<x.length;i++) { if (x[i].Age > age) r.push(x[i]); } return r; }", result);
        }
Example #3
0
        public void TestLinqSelect()
        {
            string result = Js <User[]> .Convert((x) => x.Select(t => t.Name));

            Assert.AreEqual("function (x) { var r = []; for(var i=0;i<x.length;i++) { r.push(x[i].Name); } return r; }", result);
        }
Example #4
0
        public void TestEnums()
        {
            string result = Js <User> .Convert(u => u.Gender == Gender.Female);

            Assert.AreEqual("function (u) { return (u.Gender == 1); }", result);
        }
Example #5
0
        public void TestFuncName()
        {
            string result = Js <int> .Convert(x => x, "SomeName");

            Assert.AreEqual("function SomeName(x) { return x; }", result);
        }
Example #6
0
        public void TestSimpleConstant()
        {
            string result = Js.Convert(() => 2 * 2);

            Assert.AreEqual("function () { return 4; }", result);
        }
Example #7
0
        public void TestArrayIndexerObject()
        {
            string result = Js <User> .Convert(u => u.Name[5]);

            Assert.AreEqual("function (u) { return u.Name[5]; }", result);
        }
Example #8
0
        public void TestAdvancedOperators()
        {
            string result = Js <int, int> .Convert((x, y) => (x % y / 2) >> 5);

            Assert.AreEqual("function (x, y) { return (((x % y) / 2) >> 5); }", result);
        }
Example #9
0
        public void TestMemberAccess()
        {
            string result = Js <User> .Convert(u => u.Age);

            Assert.AreEqual("function (u) { return u.Age; }", result);
        }
Example #10
0
        public void TestArrayIndexer()
        {
            string result = Js <int[]> .Convert(x => x[5]);

            Assert.AreEqual("function (x) { return x[5]; }", result);
        }
Example #11
0
        public void TestNull()
        {
            string result = Js <User> .Convert(u => u.Name == null);

            Assert.AreEqual("function (u) { return (u.Name == null); }", result);
        }
Example #12
0
        public void TestConditionalOperator()
        {
            string result = Js <int> .Convert(x => x > 2? 3 : 1);

            Assert.AreEqual("function (x) { return ((x > 2) ? 3 : 1); }", result);
        }
Example #13
0
        public void TestCoalesceOperator()
        {
            string result = Js <User> .Convert(u => u.Balance ?? 0);

            Assert.AreEqual("function (u) { return ((u.Balance == null || u.Balance == undefined) ? 0 : u.Balance); }", result);
        }
Example #14
0
 public void TestNotLinqWhere()
 {
     Js.Convert(() => new User().Where());
 }
Example #15
0
        public void TestObjectInitializer()
        {
            string result = Js <User> .Convert(u => new { NormalizedAge = u.Age - 18, UpperName = u.Name.ToUpper() });

            Assert.AreEqual("function (u) { return { NormalizedAge: (u.Age - 18), UpperName: u.Name.toUpperCase() }; }", result);
        }
Example #16
0
        public void TestLinqCombinedX2()
        {
            string result = Js <User[], int> .Convert((x, age) => from t in x where t.Age > age where t.Gender == Gender.Male select t.Name);

            Assert.AreEqual("function (x, age) { var r = []; for(var i=0;i<x.length;i++) { if ((x[i].Gender == 0) && (x[i].Age > age)) r.push(x[i].Name); } return r; }", result);
        }
Example #17
0
        public void TestSimpleOperators()
        {
            string result = Js <int> .Convert(x => x + 1 *x);

            Assert.AreEqual("function (x) { return (x + (1 * x)); }", result);
        }