Ejemplo n.º 1
0
        public void CompareArgument(string parameter, string condition, object value)
        {
            var compiled = CompileAndGetClassWith(@"
                public function Compare(" + parameter + @")
                    return " + condition + @"
                end
            ");

            var returned = compiled.Compare(TestArgumentConverter.Convert(value));

            Assert.IsTrue(returned);
        }
Ejemplo n.º 2
0
        public void NearbyMethodCallOnNewObject(string parameters, string returnValue, string arguments, object expectedValue)
        {
            var caller = CompilationHelper.CompileAndGetInstance(string.Format(@"
                public class Callee
                    function GetValue({0})
                        return {2}
                    end
                end
                
                public class Caller
                    function GetValueFromCallee()
                        let callee = new Callee()
                        return callee.GetValue({1})
                    end
                end
            ", parameters, arguments, returnValue).Trim(), "Caller");

            Assert.AreEqual(TestArgumentConverter.Convert(expectedValue), caller.GetValueFromCallee());
        }
Ejemplo n.º 3
0
        public void NearbyMethodCallOnParameter(string returnValue, object expectedValue)
        {
            var compiled = CompilationHelper.CompileCode(string.Format(@"
                public class Callee
                    function GetValue()
                        return {0}
                    end
                end
                
                public class Caller
                    function GetValueFromCallee(Callee callee)
                        return callee.GetValue()
                    end
                end
            ", returnValue).Trim());

            var callee = (dynamic)Activator.CreateInstance(compiled.GetType("Callee"));
            var caller = (dynamic)Activator.CreateInstance(compiled.GetType("Caller"));

            Assert.AreEqual(TestArgumentConverter.Convert(expectedValue), caller.GetValueFromCallee(callee));
        }
Ejemplo n.º 4
0
        public void WriteAndReadPropertyThroughMethods <T>(string propertyType, object rawValue)
        {
            var value = (T)TestArgumentConverter.Convert(rawValue);
            var code  = string.Format(@"
                public class Test
                    private {0} x
                    
                    public function SetValue({0} value)
                        x = value
                    end

                    public function GetValue()
                        return x
                    end
                end
            ", propertyType).Trim();

            var instance = CompilationHelper.CompileAndGetInstance(code, "Test");

            instance.SetValue(value);

            Assert.AreEqual(value, instance.GetValue());
        }
Ejemplo n.º 5
0
        public void Simple(string valueString, object expectedValue)
        {
            var value = CompilationHelper.CompileAndEvaluate(valueString);

            Assert.AreEqual(TestArgumentConverter.Convert(expectedValue), value);
        }
Ejemplo n.º 6
0
        public void Simple(string expressionString, object[] expectedValues)
        {
            var compiled = ((Array)CompilationHelper.CompileAndEvaluate(expressionString)).Cast <object>().ToArray();

            Assert.AreElementsEqual(TestArgumentConverter.Convert(expectedValues), compiled);
        }