Ejemplo n.º 1
0
 protected GenScope(Rila runtime)
 {
     Runtime        = runtime;
     Definitions    = new Dictionary <string, DLR.ParameterExpression>();
     BreakTarget    = DLR.Expression.Label("@break");
     ContinueTarget = DLR.Expression.Label("@continue");
 }
Ejemplo n.º 2
0
        public void ExecuteBasicOperations()
        {
            var code = File.ReadAllText("TestPrograms/ETGen/basic.rila");

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 100);
        }
Ejemplo n.º 3
0
        public void BasicFunction()
        {
            var code = File.ReadAllText("TestPrograms/ETGen/basic_function.rila");

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 10);
        }
Ejemplo n.º 4
0
        public void Booleans()
        {
            var code = "not(not true and false)";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == true);
        }
Ejemplo n.º 5
0
        public void ReferenceVariableAfterScopeShouldThrow()
        {
            var code = File.ReadAllText("TestPrograms/ETGen/reference_destroyed_variable.rila");

            var engine = Rila.CreateRilaEngine();

            Func <dynamic> wrapper = () => engine.Execute(code);

            Assert.Throws <SyntaxErrorException>(wrapper);
        }
Ejemplo n.º 6
0
        public void RangeOperationWithNonNumericalTypesThrows()
        {
            var code = "5..true";

            var engine = Rila.CreateRilaEngine();

            Func <dynamic> wrapper = () => engine.Execute(code);

            Assert.Throws <RuntimeBinderException>(wrapper);
        }
Ejemplo n.º 7
0
        public void RangeOperationWithBadParamsThrows()
        {
            var code = "5..4";

            var engine = Rila.CreateRilaEngine();

            Func <dynamic> wrapper = () => engine.Execute(code);

            Assert.Throws <ArgumentException>(wrapper);
        }
Ejemplo n.º 8
0
        public void DuplicateAliasThrows()
        {
            var    code   = @"
use System as sys
use System.Text as sys
";
            var    engine = Rila.CreateRilaEngine();
            Action action = () => engine.Execute(code);

            Assert.Throws <RilaRuntimeException>(action);
        }
Ejemplo n.º 9
0
        public void ImportingTheSameNamespaceTwiceThrows()
        {
            var    code   = @"
use System
use System
";
            var    engine = Rila.CreateRilaEngine();
            Action action = () => engine.Execute(code);

            Assert.Throws <RilaRuntimeException>(action);
        }
Ejemplo n.º 10
0
        public void CreateCellInstance()
        {
            var code = @"
a = cell(5)
a 
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.IsType <int>(result.Value);
        }
Ejemplo n.º 11
0
        public void TypeOfWorksWithAlias()
        {
            var code = @"
use System.Text as text

typeof(text.StringBuilder)
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result.Name == "StringBuilder");
        }
Ejemplo n.º 12
0
        public void NewExpressionWithAlias()
        {
            var code   = @"
use System.Text as text

a = new text.StringBuilder(5, 10)
a
";
            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.IsType <StringBuilder>(result);
        }
Ejemplo n.º 13
0
        public void TypeOfReturnsCorrectType()
        {
            var code = @"
use System.Text

typeof(StringBuilder)
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result.Name == "StringBuilder");
        }
Ejemplo n.º 14
0
        public void StaticMemberAccessWithAlias()
        {
            var code   = @"
use System as sys

a = sys.String.Empty
a
";
            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.IsType <string>(result);
        }
Ejemplo n.º 15
0
        public void StaticCallWithAlias()
        {
            var code   = @"
use System as sys

a = sys.Guid.NewGuid()
a
";
            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.IsType <Guid>(result);
        }
Ejemplo n.º 16
0
        public void GetIndex()
        {
            var code = @"
use System

a = Array.CreateInstance(typeof(Int32), 10)
a[5]
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 0);
        }
Ejemplo n.º 17
0
        public void NewExpressionWithoutArguments()
        {
            var code   = @"
use System.Text

a = new StringBuilder()
a.Append(""test"")
a.ToString()
";
            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == "test");
        }
Ejemplo n.º 18
0
        public void ProgramAlwaysReturnsAValue()
        {
            var code = @"
a = 10

if a > 10
    a = 5
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result is null);
        }
Ejemplo n.º 19
0
        public void DotExpressionSetMember()
        {
            var code = @"
use System.Net

o = new Cookie()
o.Comment = ""test""
o.Comment
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == "test");
        }
Ejemplo n.º 20
0
        public void RangeOperationWithEqualParamsCantMoveNext()
        {
            var code = "5..5";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result is RangeIterator <int>);

            var enumerator = result.GetEnumerator();

            enumerator.MoveNext();
            Assert.True(enumerator.Current == 5);

            Assert.True(enumerator.MoveNext() == false);
        }
Ejemplo n.º 21
0
        public void ForLoopWithRange()
        {
            var code = @"
a = 0
b = 10

for i in 0..b
    a = i

a
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 10);
        }
Ejemplo n.º 22
0
        public void MultipleReturnsFunction()
        {
            var code = @"
fun IsBiggerThanTen(number)
    if number > 10
        return true
    else
        return false

IsBiggerThanTen(10)
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == false);
        }
Ejemplo n.º 23
0
        public void RangeOperationReturnsEnumerable()
        {
            var code = "10..21";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result is RangeIterator <int>);
            var enumerator = result.GetEnumerator();

            Assert.True(enumerator.Current == 0);

            while (enumerator.MoveNext())
            {
            }

            Assert.True(enumerator.Current == 21);
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No file provided. Exiting...");
                return;
            }

            try
            {
                var engine = Rila.CreateRilaEngine();
                engine.ExecuteFile(args[0]);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
Ejemplo n.º 25
0
        public void ForLoopWithIfs()
        {
            var code = @"
a = 0

for i in 0..10
    if i % 2 == 0
        a = a + i
    else
        a = a + 1

a
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 35);
        }
Ejemplo n.º 26
0
        public void RangeOperationWorksWithNestedExpressions()
        {
            var code = "0..5+5";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result is RangeIterator <int>);

            var enumerator = result.GetEnumerator();

            Assert.True(enumerator.Current == 0);

            while (enumerator.MoveNext())
            {
            }

            Assert.True(enumerator.Current == 10);
        }
Ejemplo n.º 27
0
        public void ForLoopBreak()
        {
            var code = @"
a = 0

for i in 0..10
    if i == 5
        break

    a = i

a
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 4);
        }
Ejemplo n.º 28
0
        public void ForLoopContinue()
        {
            var code = @"
a = 0

for i in 0..10
    if i % 2 == 0
        continue

    a = 9

a
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 9);
        }
Ejemplo n.º 29
0
        public void NotUsingAtSignDoesntCaptureCell()
        {
            var code = @"
a = cell(5)
b = cell(5)

signal = { @a.Value + b.Value + 1 }

a.Value = 2
a.Value = 3
b.Value = 3

signal.Value
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 9);
        }
Ejemplo n.º 30
0
        public void IntSignal()
        {
            var code = @"
a = cell(5)
b = cell(5)

signal = { @a.Value + @b.Value + 1 }

a.Value = 2
a.Value = 3
b.Value = 3

signal.Value
";

            var engine = Rila.CreateRilaEngine();
            var result = engine.Execute(code);

            Assert.True(result == 7);
        }