public void LoopStatementWithRequiresStatement()
        {
            LoopStatement statement = null;

            Expect.Throw <ArgumentNullException>(() => statement.Do(new Statement[0]));
            Expect.Throw <ArgumentNullException>(() => statement.Do(new List <Statement>()));
        }
        public void CallOperationExpressionHelpersRequiresExpression2()
        {
            Expression expression = null;
            IEnumerable <Expression> arguments = null;

            Expect.Throw <ArgumentNullException>(() => expression.Call(arguments));
        }
Example #3
0
        public void ObjectLiteralExpressionHelpersRequireExpression()
        {
            ObjectLiteralExpression expression = null;

            Expect.Throw <ArgumentNullException>(() => expression.WithProperty("name", "value"));
            Expect.Throw <ArgumentNullException>(() => expression.WithProperties(new Dictionary <Expression, Expression>()));
        }
Example #4
0
        public void WhileStatementHelpersRequireStatement()
        {
            WhileStatement statement = null;

            Expect.Throw <ArgumentNullException>(() => statement.Do());
            Expect.Throw <ArgumentNullException>(() => statement.Do(new List <Statement>()));
        }
Example #5
0
        public void IteratorHelpersRequiresIterator()
        {
            IteratorStatement iterator = null;

            Expect.Throw <ArgumentNullException>(() => iterator.In(null));
            Expect.Throw <ArgumentNullException>(() => iterator.Do());
            Expect.Throw <ArgumentNullException>(() => iterator.Do(new List <Statement>()));
        }
Example #6
0
        public void IteratorRequiresStatement()
        {
            var iterator = new IteratorStatement();

            iterator.Variable   = JS.Id("a");
            iterator.Collection = JS.Id("b");

            Expect.Throw <InvalidOperationException>(() => iterator.ToString());
        }
Example #7
0
        public void FunctionExpressionHelpersNeedsExpression()
        {
            FunctionExpression expression = null;

            Expect.Throw <ArgumentNullException>(() => expression.Parameters());
            Expect.Throw <ArgumentNullException>(() => expression.Parameters(new List <IdentifierExpression>()));
            Expect.Throw <ArgumentNullException>(() => expression.Do());
            Expect.Throw <ArgumentNullException>(() => expression.Do(new List <Statement>()));
        }
Example #8
0
        public void ThrowExpectsException()
        {
            Expect.Throw <Exception>(() =>
            {
                throw new Exception();
            });

            Expect.Throw <ApplicationException>("Ha!",
                                                () => { throw new ApplicationException("Ha!"); });
        }
Example #9
0
        public void ConditionalStatementHelpersRequireStatement()
        {
            ConditionalStatement statement = null;

            Expect.Throw <ArgumentNullException>(() => statement.Then());
            Expect.Throw <ArgumentNullException>(() => statement.Then(new List <Statement>()));
            Expect.Throw <ArgumentNullException>(() => statement.Else());
            Expect.Throw <ArgumentNullException>(() => statement.Else(new List <Statement>()));
            Expect.Throw <ArgumentNullException>(() => statement.ElseIf(null));
        }
Example #10
0
        public void ExceptionHandlingStatementRequiresCatchVariable()
        {
            var e = new ExceptionHandlingStatement
            {
                TryBlock   = new CompoundStatement(),
                CatchBlock = new CompoundStatement()
            };

            Expect.Throw <InvalidOperationException>(() => e.ToString());
        }
Example #11
0
        public void ExceptionHandlingStatementHelpersRequireStatement()
        {
            ExceptionHandlingStatement e = null;

            Expect.Throw <ArgumentNullException>(() => e.Catch(E));
            Expect.Throw <ArgumentNullException>(() => e.Catch(E, new List <Statement>()));
            Expect.Throw <ArgumentNullException>(() => e.Catch(E, new CompoundStatement()));
            Expect.Throw <ArgumentNullException>(() => e.Finally());
            Expect.Throw <ArgumentNullException>(() => e.Finally(new List <Statement>()));
            Expect.Throw <ArgumentNullException>(() => e.Finally(new CompoundStatement()));
        }
Example #12
0
        public void SwitchStatementDefaultMustComeLast()
        {
            var statement = JS.Switch(JS.Id("a"))
                            .Default()
                            .Do(JS.Break())
                            .Case((IEnumerable <Expression>)null)
                            .Case(1)
                            .Do(JS.Break());

            Expect.Throw <InvalidOperationException>(() => statement.ToString());
        }
Example #13
0
        public void IdentifierExpressionRefusesInvalidIdentifiers()
        {
            var id = new IdentifierExpression("Classname");

            Assert.AreEqual("Classname", id.Name);

            id.Name = "Namespace";
            Assert.AreEqual("Namespace", id.Name);

            Expect.Throw <ArgumentException>(() => id.Name = "Namespace.Classname");
        }
Example #14
0
        public void SwitchStatementHelpersRequireStatement()
        {
            SwitchStatement statement = null;

            Expect.Throw <ArgumentNullException>(() => statement.Default());
            Expect.Throw <ArgumentNullException>(() => statement.Case(1));
            Expect.Throw <ArgumentNullException>(() => statement.Case(new List <Expression>()));
            Expect.Throw <ArgumentNullException>(() => statement.Break());
            Expect.Throw <ArgumentNullException>(() => statement.Do());
            Expect.Throw <ArgumentNullException>(() => statement.Do(new List <Statement>()));
        }
Example #15
0
        public void GenerateJavaScriptOptionsCanBeSet()
        {
            ScriptOptions options = new ScriptOptions();

            options.PreferredQuoteChar = '\'';

            Assert.AreEqual('\'', options.PreferredQuoteChar);

            Expect.Throw <ArgumentException>(
                "The preferred quote char can only be one of the allowed quote chars.\r\nParameter name: value",
                () => options.PreferredQuoteChar = '@');
        }
        public void PropertyOperationExpressionRequiresLeftAndRightOperands()
        {
            var expression1 = new PropertyOperationExpression(JS.Id("a"), "b");

            expression1.OperandLeft = null;

            Expect.Throw <InvalidOperationException>(() => expression1.ToString());

            var expression2 = new PropertyOperationExpression(JS.Id("a"), JS.Id("b"));

            expression2.OperandRight = null;

            Expect.Throw <InvalidOperationException>(() => expression2.ToString());
        }
        public void ConditionalOperationExpressionRequiresConditionThenAndElse()
        {
            Expression condition = JS.Id("a").IsGreaterThan(0);
            Expression ifTrue    = JS.String("Yes!");
            Expression ifFalse   = JS.String("No!");

            var expression1 = new ConditionalOperationExpression(null, ifTrue, ifFalse);
            var expression2 = new ConditionalOperationExpression(condition, null, ifFalse);
            var expression3 = new ConditionalOperationExpression(condition, ifTrue, null);

            Expect.Throw <InvalidOperationException>(() => expression1.ToString());
            Expect.Throw <InvalidOperationException>(() => expression2.ToString());
            Expect.Throw <InvalidOperationException>(() => expression3.ToString());
        }
Example #18
0
        public void WhileStatementRequiresConditionAndStatement()
        {
            var statement = new WhileStatement();

            Expect.Throw <InvalidOperationException>(() => statement.ToString());

            statement.Condition = true;

            Expect.Throw <InvalidOperationException>(() => statement.ToString());

            statement.Statement = JS.Empty();

            Assert.AreEqual("while(true);", statement.ToString());
        }
        public void WithStatementRequiresExpressionAndStatement()
        {
            var statement = new WithStatement();

            Expect.Throw <InvalidOperationException>(() => statement.ToString());

            statement.Expression = JS.Id("a");

            Expect.Throw <InvalidOperationException>(() => statement.ToString());

            statement.Statement = JS.Block();

            Assert.AreEqual("a;", statement.Expression.ToString());
            Assert.AreEqual("{}", statement.Statement.ToString());
            Assert.AreEqual("with(a){}", statement.ToString());
        }
        public void UnaryOperationExpressionHelpersRequireExpression()
        {
            Expression expression = null;

            Expect.Throw <ArgumentNullException>(() => expression.BitwiseNot());
            Expect.Throw <ArgumentNullException>(() => expression.Delete());
            Expect.Throw <ArgumentNullException>(() => expression.Group());
            Expect.Throw <ArgumentNullException>(() => expression.LogicalNot());
            Expect.Throw <ArgumentNullException>(() => expression.Negative());
            Expect.Throw <ArgumentNullException>(() => expression.New());
            Expect.Throw <ArgumentNullException>(() => expression.Number());
            Expect.Throw <ArgumentNullException>(() => expression.PostDecrement());
            Expect.Throw <ArgumentNullException>(() => expression.PostIncrement());
            Expect.Throw <ArgumentNullException>(() => expression.PreDecrement());
            Expect.Throw <ArgumentNullException>(() => expression.PreIncrement());
            Expect.Throw <ArgumentNullException>(() => expression.TypeOf());
        }
        public void WithConvertedNullsRequiresStatements()
        {
            IEnumerable <Statement> enumerable = null;

            Expect.Throw <ArgumentNullException>(() => enumerable.WithConvertedNulls());
        }
Example #22
0
 public void ThrowsRequiresException()
 {
     Expect.Throw <InvalidOperationException>(() => { });
 }
        public void LabelHelperRequiresStatement()
        {
            Statement statement = null;

            Expect.Throw <ArgumentNullException>(() => statement.Labeled(null));
        }
Example #24
0
 public void ThrowsRequiresExceptionWithMessage()
 {
     Expect.Throw <InvalidOperationException>("Needs a message.",
                                              () => { throw new InvalidOperationException(); });
 }
Example #25
0
        public void ConditionalStatementProducesErrorWithMissingCondition()
        {
            var c = new ConditionalStatement();

            Expect.Throw <InvalidOperationException>(() => c.ToString());
        }
        public void ThrowStatementRequiresExpression()
        {
            var statement = new ThrowStatement(null);

            Expect.Throw <InvalidOperationException>(() => statement.ToString());
        }
        public void PropertyOperationExpressionHelpersRequireExpression()
        {
            Expression expression = null;

            Expect.Throw <ArgumentNullException>(() => expression.Dot("a"));
        }
        public void BinaryOperationExpressionRefusesUnknownEnum()
        {
            var a = new BinaryOperationExpression(null, null, (BinaryOperator)int.MaxValue);

            Expect.Throw <InvalidOperationException>(() => a.ToString());
        }
        public void AssignWithThrowsOnNull()
        {
            BinaryOperationExpression none = null;

            Expect.Throw <ArgumentNullException>(() => none.AndAssign());
        }
Example #30
0
        public void ExceptionHandlingStatementRequiresTryBlock()
        {
            var e = new ExceptionHandlingStatement();

            Expect.Throw <InvalidOperationException>(() => e.ToString());
        }