Example #1
0
        public void catchTest1()
        {
            var uvar    = new UserVariable();
            var target  = new Script(new StubEnv(), uvar);

            target.parse("#[try{ $(test = '123') }catch{ $(test2 = '456') }]");

            Assert.AreEqual(1, uvar.Variables.Count());
            Assert.AreEqual("123", uvar.get("test", null));
        }
Example #2
0
        public void catchTest2()
        {
            var uvar    = new UserVariable();
            var target  = new Script(new StubEnv(), uvar);

            Assert.AreEqual(0, uvar.Variables.Count());
            target.parse("#[try{ #[notrealcomponentToError]  $(test = '123') }catch{ $(test2 = '456') }]");

            Assert.AreEqual(1, uvar.Variables.Count());
            Assert.AreEqual("456", uvar.get("test2", null));
        }
Example #3
0
        public void catchTest3()
        {
            var uvar    = new UserVariable();
            var target  = new Script(new StubEnv(), uvar);

            Assert.AreEqual(0, uvar.Variables.Count());
            target.parse(@"
                            #[( false ){

                                #[try
                                {
                                     #[notrealcomponentToError]
                                }
                                catch(err, msg)
                                {
                                    $(test1 = '123')
                                }]

                            }
                            else{

                                #[try
                                {
                                     #[notrealcomponentToError]
                                }
                                catch(err, msg)
                                {
                                    $(test2 = '456')
                                    $(exErr = $(err))
                                    $(exMsg = $(msg))
                                }]

                            }] ");

            Assert.AreEqual(3, uvar.Variables.Count());
            Assert.AreEqual(null, uvar.get("test1", null));
            Assert.AreEqual("456", uvar.get("test2", null));
            Assert.AreEqual(true, !string.IsNullOrWhiteSpace(uvar.get("exErr", null)));
            Assert.AreEqual(true, !string.IsNullOrWhiteSpace(uvar.get("exMsg", null)));
            Assert.AreEqual(null, uvar.get("err", null));
            Assert.AreEqual(null, uvar.get("msg", null));
        }
Example #4
0
        public void catchTest4()
        {
            var uvar    = new UserVariable();
            var target  = new Script(new StubEnv(), uvar);

            Assert.AreEqual(0, uvar.Variables.Count());
            target.parse(@"
                            #[( false ){

                                #[try
                                {
                                     #[notrealcomponentToError]
                                }
                                catch
                                {
                                    $(test1 = '123')
                                }]

                            }
                            else{

                                #[try
                                {
                                     #[notrealcomponentToError]
                                }
                                catch
                                {
                                    $(test2 = '456')
                                }]

                            }] ");

            Assert.AreEqual(1, uvar.Variables.Count());
            Assert.AreEqual(null, uvar.get("test1", null));
            Assert.AreEqual("456", uvar.get("test2", null));
            Assert.AreEqual(null, uvar.get("err", null));
            Assert.AreEqual(null, uvar.get("msg", null));
        }