Example #1
0
        public void BugFix_Nullable_ArgBinding()
        {
            var test = new NullableTest();

            engine.Script.test = test;
            Assert.IsNull(engine.Evaluate("test.Method(null)"));
            Assert.AreEqual(test.Method(5), engine.Evaluate("test.Method(5)"));
            Assert.AreEqual(test.Method(5.1), engine.Evaluate("test.Method(5.1)"));
        }
Example #2
0
        public void Test_ReadNullableJson(string json, string durationString)
        {
            // Validate parameters.
            if (string.IsNullOrWhiteSpace(json))
            {
                throw new ArgumentNullException(nameof(json));
            }

            // Get the expected value.
            TimeSpan?expected = string.IsNullOrWhiteSpace(durationString) ?
                                (TimeSpan?)null : TimeSpan.Parse(durationString);

            // Map to an object.
            NullableTest actual = JsonSerializer.Deserialize <NullableTest>(json);

            // Equal.
            Assert.Equal(expected, actual.Value);
        }
Example #3
0
        public void TestNullable()
        {
            var obj = new NullableTest();

            var onlyNum = new Dictionary <string, Variant>();

            onlyNum["num1"] = new Variant(10);
            onlyNum["num2"] = new Variant(20);

            ParameterParser.Parse(obj, onlyNum);

            Assert.True(obj.num1.HasValue);
            Assert.True(obj.num2.HasValue);
            Assert.False(obj.num3.HasValue);

            Assert.AreEqual(10, obj.num1.Value);
            Assert.AreEqual(20, obj.num2.Value);
        }
Example #4
0
        public void Test_ReadNullableJson(string json, string durationString)
        {
            // Validate parameters.
            if (string.IsNullOrWhiteSpace(json))
            {
                throw new ArgumentNullException(nameof(json));
            }

            // Get the expected value.
            TimeSpan?expected = string.IsNullOrWhiteSpace(durationString) ?
                                (TimeSpan?)null : TimeSpan.Parse(durationString);

            // Parse/etc.
            JObject obj = JObject.Parse(json);

            // Map to an object.
            NullableTest test = obj.ToObject <NullableTest>();

            // Equal.
            Assert.Equal(expected, test.Value);
        }
 public void BugFix_Nullable_ArgBinding()
 {
     var test = new NullableTest();
     engine.Script.test = test;
     Assert.IsNull(engine.Evaluate("test.Method(null)"));
     Assert.AreEqual(test.Method(5), engine.Evaluate("test.Method(5)"));
     Assert.AreEqual(test.Method(5.1), engine.Evaluate("test.Method(5.1)"));
 }
Example #6
0
        private static void Basic()
        {
            // 1. DataType
            Console.WriteLine("=================== Data Type ================");
            var dt = new DataType();

            dt.Test();

            // 2. Variable And Constant
            Console.WriteLine("=================== Variable & Constant ================");
            var vnc = new VariableAndConstant();

            vnc.Test();

            // 3. Array
            Console.WriteLine("=================== Array ================");
            var arr = new ArrayTest();

            arr.Test();

            // 4. String
            Console.WriteLine("=================== String ================");
            var strTest = new StringTest();

            strTest.Test();

            // 5. Enum
            Console.WriteLine("=================== Enum ================");
            var enumTest = new EnumTest();

            enumTest.Test();

            // 6. Operator
            Console.WriteLine("=================== Operator ================");
            var operatorTest = new OperatorTest();

            operatorTest.Test();

            // 7. If
            Console.WriteLine("=================== If ================");
            var ifTest = new IfTest();

            ifTest.Test();

            // 8. loop
            Console.WriteLine("=================== Loop ================");
            var loopTest = new LoopTest();

            loopTest.Test();

            // 9. yield keword: when collection data can be returned one by one in turn
            Console.WriteLine("=================== yield return ================");
            var yieldReturnTest = new yieldTest();

            yieldReturnTest.Test();

            // 10. Exception
            Console.WriteLine("=================== Exception ================");
            var exceptionTest = new ExceptionTest();

            exceptionTest.Test(0, 0);

            // 11. Struct
            Console.WriteLine("=================== Struct ================");
            var structTest = new StructTest();

            structTest.ToString();

            // 12. Nullable
            Console.WriteLine("=================== Nullable ================");
            var nullableTest = new NullableTest();

            nullableTest.Test(null, null, DateTime.Now, null);

            // 13. Method
            Console.WriteLine("=================== Method ================");
            var methodTest = new MethodTest();
            // 13-1
            int val = 1000;

            methodTest.TestPassByValue(val);

            Console.WriteLine("variable val's value is not changed: {0}", val);
            // 13-2
            int    x   = 0;
            double y   = 1.0;
            double ret = methodTest.TestPassByRef(ref x, ref y);

            Console.WriteLine("variable val's value is actually changed: x: {0} y: {1}", x, y);

            Console.WriteLine(x);
            Console.WriteLine(y);

            // 13-3
            int  c, d;
            bool bret = methodTest.TestPassByOut(10, 20, out c, out d);

            Console.WriteLine("variable val's value is actually changed: c: {0} d: {1}", c, d);

            // differenc between ref keyword and out keyword

            // 13-4.
            var returnValue = methodTest.TestDefaultParam(1, 2);

            Console.WriteLine("Default parameter test: " + returnValue);
            var returnValue2 = methodTest.TestDefaultParam(1, 2, "-----");

            // 13-5.
            var returnParamsValue = methodTest.TestParams(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            Console.WriteLine("params keyword test: " + returnParamsValue);
        }