Exemple #1
0
        public async Task CanResolveOperatorsOnKnownTypes()
        {
            string code = @"
import Test.SampleClass;
function<SampleClass> testFunc(SampleClass sc1, SampleClass sc2)
{
    return sc1 + sc2;
}";

            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());
            GlobalContext module = await MakeModule(code);

            Lambda      lambda = module.LookupVariable("testFunc") as Lambda;
            SampleClass sc1    = new SampleClass
            {
                SampleField    = 5,
                SampleProperty = 2
            };

            SampleClass sc2 = new SampleClass
            {
                SampleField    = 7,
                SampleProperty = 2
            };
            object result = lambda.Run(sc1, sc2);

            Assert.IsType <SampleClass>(result);
            SampleClass scResult = result as SampleClass;

            Assert.Equal(12, scResult.SampleField);
            Assert.Equal(4, scResult.SampleProperty);
        }
Exemple #2
0
        public async Task CanCallMethods()
        {
            string code = @"
function<?> testFunc()
{
    import Test.SampleClass;
    function<int> callMethod(SampleClass sc, int x)
    {
        return sc.SampleMethod(x);
    }
    return callMethod;
}";

            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());
            Lambda lambda = await MakeLambda(code);

            Lambda      innerLambda = lambda.Run() as Lambda;
            SampleClass sc          = new SampleClass
            {
                SampleField = 5
            };

            Assert.Equal(5, innerLambda.Run(sc, 11));
            Assert.Equal(11, sc.SampleField);
        }
Exemple #3
0
        public async Task CanAccessPropertiesAndFields()
        {
            string code = @"
import Test.SampleClass;
function<int> testFunc(SampleClass sc, int x)
{
    return sc.SampleField + sc.SampleProperty + x;
}";

            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());
            GlobalContext module = await MakeModule(code);

            Lambda      lambda = module.LookupVariable("testFunc") as Lambda;
            SampleClass sc     = new SampleClass
            {
                SampleField    = 5,
                SampleProperty = 3
            };

            Assert.Equal(10, lambda.Run(sc, 2));
        }
Exemple #4
0
        public async Task CanParseModules()
        {
            string code = @"
import Test.SampleClass;
function<int> testFunc(SampleClass sc, int x)
{
    return sc.SampleMethod(x);
}";

            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());
            GlobalContext module = await MakeModule(code);

            Lambda      lambda = module.LookupVariable("testFunc") as Lambda;
            SampleClass sc     = new SampleClass
            {
                SampleField = 5
            };

            Assert.Equal(5, lambda.Run(sc, 11));
            Assert.Equal(11, sc.SampleField);
        }
Exemple #5
0
        public async Task RunTestFromFile(string filename)
        {
            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());

            Parser   parser = new Parser(new StreamReader("FileTests/" + filename));
            TopLevel top    = await parser.ParseModule(
                Path.GetFileNameWithoutExtension(filename)
                );

            GlobalContext context = await Compiler.CompileModule(
                top,
                new DirectoryResourceProvider("FileTests/")
                );

            Lambda lambda = context.LookupVariable("testMain") as Lambda;

            Assert.NotNull(lambda);

            RAssert assert = new RAssert();

            lambda.Run(assert);
            Assert.NotEqual(0, assert.AssertionsCount);
        }