public void Nested_Failure() { _checkError(".Lhs.Rhs.Value", () => { ParseItemEquals.CheckEquals( new BinOpItem( new BinOpItem( new LiteralItem(1.0), BinaryOperationType.Subtract, new LiteralItem(3.0)), BinaryOperationType.Add, new BinOpItem( new NameItem("foo"), BinaryOperationType.Subtract, new UnOpItem(new LiteralItem(3.0), UnaryOperationType.Minus))), new BinOpItem( new BinOpItem( new LiteralItem(1.0), BinaryOperationType.Subtract, new LiteralItem(2.0)), BinaryOperationType.Add, new BinOpItem( new NameItem("foo"), BinaryOperationType.Subtract, new UnOpItem(new LiteralItem(3.0), UnaryOperationType.Minus)))); }); }
public void Call_NotLastArgSingle() { ParseItemEquals.CheckEquals( new FuncCallItem( new NameItem("foo"), new[] { new FuncCallItem.ArgumentInfo( new BinOpItem(new NameItem("a"), BinaryOperationType.Add, new LiteralItem(1.0)), false), }) { IsLastArgSingle = false }, _parseExpression("foo((a)+1)")); ParseItemEquals.CheckEquals( new FuncCallItem( new NameItem("foo"), new[] { new FuncCallItem.ArgumentInfo(new NameItem("a"), false), new FuncCallItem.ArgumentInfo(new NameItem("b"), false), new FuncCallItem.ArgumentInfo(new NameItem("c"), false), }) { IsLastArgSingle = false }, _parseExpression("foo(a, (b), c)")); }
public void GenericFor() { ParseItemEquals.CheckEquals( new ForGenItem(new[] { new NameItem("x") }, new[] { new NameItem("foo") }, new BlockItem()), _parseStatement("for x in foo do end")); }
public void Call_WithTable() { ParseItemEquals.CheckEquals( new FuncCallItem( new NameItem("foo"), new[] { new FuncCallItem.ArgumentInfo(new TableItem(), false) }), _parseExpression("foo {}")); }
public void Assignment_NotLastArgSingle() { ParseItemEquals.CheckEquals( new AssignmentItem(new[] { new NameItem("x") }, new[] { new LiteralItem(1.0), new LiteralItem(2.0) }), _parseStatement("x = (1), 2")); }
public void NumericFor_NoStep() { ParseItemEquals.CheckEquals( new ForNumItem(new NameItem("x"), new LiteralItem(1.0), new LiteralItem(2.0), null, new BlockItem()), _parseStatement("for x = 1, 2 do end")); }
public void BasicValues_Success() { ParseItemEquals.CheckEquals(1, 1); ParseItemEquals.CheckEquals(2.3, 2.3); ParseItemEquals.CheckEquals("abc", "abc"); ParseItemEquals.CheckEquals(true, true); }
public void Call() { ParseItemEquals.CheckEquals( new FuncCallItem( new NameItem("foo"), new[] { new FuncCallItem.ArgumentInfo(new LiteralItem(1.0), false) }), _parseExpression("foo(1)")); }
public void Indexer() { ParseItemEquals.CheckEquals( new IndexerItem( new NameItem("foo"), new BinOpItem(new NameItem("a"), BinaryOperationType.Add, new NameItem("b"))), _parseExpression("foo[a + b]")); }
public void Literals() { ParseItemEquals.CheckEquals(new LiteralItem(null), _parseExpression("nil")); ParseItemEquals.CheckEquals(new LiteralItem(false), _parseExpression("false")); ParseItemEquals.CheckEquals(new LiteralItem(true), _parseExpression("true")); ParseItemEquals.CheckEquals(new LiteralItem(123.0), _parseExpression("123")); ParseItemEquals.CheckEquals(new LiteralItem("foo"), _parseExpression("'foo'")); }
public void Do() { ParseItemEquals.CheckEquals( new BlockItem(new[] { new AssignmentItem(new[] { new NameItem("x") }, new[] { new LiteralItem(1.0) }), }), _parseStatement("do x = 1 end")); }
public void Break() { ParseItemEquals.CheckEquals( new RepeatItem( new NameItem("i"), new BlockItem(new[] { new GotoItem("<break>") })), _parseStatement("repeat break until i")); }
public void Call_WithString() { ParseItemEquals.CheckEquals( new FuncCallItem( new NameItem("foo"), new[] { new FuncCallItem.ArgumentInfo(new LiteralItem("bar"), false) }), _parseExpression("foo 'bar'")); }
public void Call_InstanceMethod() { ParseItemEquals.CheckEquals( new FuncCallItem(new NameItem("foo")) { InstanceName = "bar" }, _parseExpression("foo:bar()")); }
public void UnaryExpression_WithPower() { // This should be parsed as -(foo^bar) ParseItemEquals.CheckEquals( new UnOpItem( new BinOpItem(new NameItem("foo"), BinaryOperationType.Power, new NameItem("bar")), UnaryOperationType.Minus), _parseExpression("-foo^bar")); }
public void List_Success() { var expected = new AssignmentItem( new[] { new NameItem("foo"), new NameItem("bar"), }, new[] { new LiteralItem("cat") }); var actual = new AssignmentItem( new[] { new NameItem("foo"), new NameItem("bar"), }, new[] { new LiteralItem("cat") }); ParseItemEquals.CheckEquals(expected, actual); }
public void Call_Statement() { ParseItemEquals.CheckEquals( new FuncCallItem(new NameItem("foo")) { Statement = true }, _parseStatement("foo()")); }
public void GenericFor_Multiples() { ParseItemEquals.CheckEquals( new ForGenItem( new[] { new NameItem("x"), new NameItem("y"), new NameItem("z") }, new IParseExp[] { new NameItem("foo"), new FuncCallItem(new NameItem("run")) }, new BlockItem()), _parseStatement("for x, y, z in foo, run() do end")); }
public void Table_NamedKeys() { ParseItemEquals.CheckEquals( new TableItem(new[] { new KeyValuePair <IParseExp, IParseExp>(new LiteralItem("x"), new LiteralItem(1.0)), new KeyValuePair <IParseExp, IParseExp>(new LiteralItem("y"), new LiteralItem(2.0)), }), _parseExpression("{x=1, y=2}")); }
public void Return_Empty() { ParseItemEquals.CheckEquals( new BlockItem() { Return = new ReturnItem() }, _parseBlock("return")); }
public void Repeat() { ParseItemEquals.CheckEquals( new RepeatItem( new NameItem("i"), new BlockItem(new[] { new AssignmentItem(new[] { new NameItem("x") }, new[] { new LiteralItem(1.0) }), })), _parseStatement("repeat x = 1 until i")); }
public void List_FailureValue() { var expected = new AssignmentItem( new[] { new NameItem("foo"), new NameItem("bar"), }, new[] { new LiteralItem("cat") }); var actual = new AssignmentItem( new[] { new NameItem("foo"), new NameItem("baz") }, new[] { new LiteralItem("cat") }); _checkError(".Names[1]", () => ParseItemEquals.CheckEquals(expected, actual)); }
public void UnaryExpression_Nested() { ParseItemEquals.CheckEquals( new UnOpItem( new UnOpItem( new UnOpItem(new NameItem("foo"), UnaryOperationType.Not), UnaryOperationType.Length), UnaryOperationType.Minus), _parseExpression("-#not foo")); }
public void Return_MultipleValues() { ParseItemEquals.CheckEquals( new BlockItem() { Return = new ReturnItem( new[] { new NameItem("a"), new NameItem("b"), new NameItem("c") }) }, _parseBlock("return a, b, c")); }
public void BinaryExpression_HandlesRightAssociative() { // This should be parsed as foo^(bar^baz) ParseItemEquals.CheckEquals( new BinOpItem( new NameItem("foo"), BinaryOperationType.Power, new BinOpItem(new NameItem("bar"), BinaryOperationType.Power, new NameItem("baz"))), _parseExpression("foo^bar^baz")); }
public void Assignment_LastArgSingle() { ParseItemEquals.CheckEquals( new AssignmentItem(new[] { new NameItem("x") }, new[] { new LiteralItem(1.0) }) { IsLastExpressionSingle = true }, _parseStatement("x = (1)")); }
public void Assignment_Local() { ParseItemEquals.CheckEquals( new AssignmentItem(new[] { new NameItem("x") }, new[] { new LiteralItem(1.0) }) { Local = true }, _parseStatement("local x = 1")); }
public void Table_PlainValues() { ParseItemEquals.CheckEquals( new TableItem(new[] { new KeyValuePair <IParseExp, IParseExp>(new LiteralItem(1.0), new LiteralItem(10.0)), new KeyValuePair <IParseExp, IParseExp>(new LiteralItem(2.0), new LiteralItem(20.0)), new KeyValuePair <IParseExp, IParseExp>(new LiteralItem(3.0), new LiteralItem(30.0)), }), _parseExpression("{10, 20, 30}")); }
public void Properties_Multiple() { ParseItemEquals.CheckEquals( new IndexerItem( new IndexerItem( new IndexerItem(new NameItem("foo"), new LiteralItem("bar")), new LiteralItem("baz")), new LiteralItem("cat")), _parseExpression("foo.bar.baz.cat")); }
public void Return_OneValue() { ParseItemEquals.CheckEquals( new BlockItem() { Return = new ReturnItem(new[] { new BinOpItem(new NameItem("a"), BinaryOperationType.Add, new NameItem("b")), }) }, _parseBlock("return a + b")); }