Пример #1
0
        public void TestParsingsEmptyFunctionEmptWithBooleanExpressionBothSides()
        {
            Expression exp = new ExpressionLib().Parse("fn:empty(EmptyArray) && fn:empty(EmptyArray)");

            Assert.IsTrue(exp is And);

            var and = (And)exp;

            Assert.IsTrue(and.Lhs is Function);
            Assert.IsTrue(and.Rhs is Function);

            var emptyLhs = (Function)and.Lhs;

            Assert.IsTrue(emptyLhs.Nested is Brackets);

            var bracketsLhs = (Brackets)emptyLhs.Nested;

            Assert.IsTrue(bracketsLhs.Nested is PropertyOrConstant);

            var emptyRhs = (Function)and.Rhs;

            Assert.IsTrue(emptyLhs.Nested is Brackets);

            var bracketsRhs = (Brackets)emptyRhs.Nested;

            Assert.IsTrue(bracketsRhs.Nested is PropertyOrConstant);
        }
Пример #2
0
        public void TestChechkParsingWithArithmeticBothSide()
        {
            Expression exp = new ExpressionLib().Parse("fn:length('aaa')+fn:length('aaa')");

            Assert.IsTrue(exp is Add);

            var add = (Add)exp;

            Assert.IsTrue(add.Lhs is Function);
            Assert.IsTrue(add.Rhs is Function);

            var funcLhs = (Function)add.Lhs;

            Assert.IsTrue(funcLhs.Nested is Brackets);

            var bracketsLhs = (Brackets)funcLhs.Nested;

            Assert.IsTrue(bracketsLhs.Nested is Constant);

            var funcRhs = (Function)add.Rhs;

            Assert.IsTrue(funcRhs.Nested is Brackets);

            var bracketsRhs = (Brackets)funcRhs.Nested;

            Assert.IsTrue(bracketsRhs.Nested is Constant);
        }
Пример #3
0
 public TagLibParserFactory(TagLibForParsing lib, ExpressionLib expressionLib, IResourceLocatorFactory factory, ITagValidator tagValidator)
 {
     _lib           = lib;
     _expressionLib = expressionLib;
     _factory       = factory;
     _tagValidator  = tagValidator;
 }
Пример #4
0
 public TagLibParserFactory(TagLibForParsing lib, ExpressionLib expressionLib, IResourceLocatorFactory factory, ITagValidator tagValidator)
 {
     _lib = lib;
     _expressionLib = expressionLib;
     _factory = factory;
     _tagValidator = tagValidator;
 }
Пример #5
0
 public Formatter()
 {
     _lib           = new TagLib();
     _expressionLib = new ExpressionLib();
     _lib.Register(new Sharp());
     _lib.Register(new Macro());
 }
Пример #6
0
 public AbstractTagLibParser(TagLibForParsing lib, ExpressionLib expressionLib, ParseHelper helper, IResourceLocator locator, IResourceLocatorFactory factory, ITagValidator tagValidator)
 {
     _lib = lib;
     _expressionLib = expressionLib;
     _helper = helper;
     _locator = locator;
     _factory = factory;
     _tagValidator = tagValidator;
 }
 public AbstractTagLibParser(TagLibForParsing lib, ExpressionLib expressionLib, ParseHelper helper, IResourceLocator locator, IResourceLocatorFactory factory, ITagValidator tagValidator)
 {
     _lib           = lib;
     _expressionLib = expressionLib;
     _helper        = helper;
     _locator       = locator;
     _factory       = factory;
     _tagValidator  = tagValidator;
 }
Пример #8
0
 public InternalFormatter(ITagLibParserFactory tagLibHelper, ExpressionLib expressionLib, string template, bool allowTags, IResourceLocator locator, ParseContext offSet = null)
 {
     _tagLibHelper   = tagLibHelper;
     _locator        = locator;
     _expectCloseTag = false;
     _allowTags      = allowTags;
     _parser         = new ParseHelper(new Tokenizer(template, Configuration).AddOffSet(offSet));
     _expressionLib  = expressionLib;
 }
Пример #9
0
 public Formatter OverrideExpressionLib(ExpressionLib lib)
 {
     if (lib == null)
     {
         return(this);
     }
     _expressionLib = lib;
     return(this);
 }
Пример #10
0
 public InternalFormatter(ITagLibParserFactory tagLibHelper, ExpressionLib expressionLib, ParseHelper parser, bool allowTags, bool expectCloseTag, IResourceLocator locator)
 {
     _tagLibHelper   = tagLibHelper;
     _locator        = locator;
     _allowTags      = allowTags;
     _expectCloseTag = expectCloseTag;
     _parser         = parser;
     _expressionLib  = expressionLib;
 }
Пример #11
0
 public void TestCastingWithParseDictionary()
 {
     var dict = new Dictionary<String, String>
     {
         {"Code", "Dutch National"}
     };
     var eq = new ExpressionLib().Parse("Code == 1");
     Assert.IsFalse((bool)eq.Evaluate(new Reflection(dict)));
 }
Пример #12
0
        public void TestParseConcatWithSpaceExpression()
        {
            var parsed = new ExpressionLib().Parse("'Lhs' ~ 'Rhs' ");

            Assert.That(parsed.GetType(), Is.EqualTo(typeof(ConcatWithSpace)));
            var concat = (ConcatWithSpace)parsed;

            Assert.That(((Constant)concat.Lhs).Value, Is.EqualTo("Lhs"));
            Assert.That(((Constant)concat.Rhs).Value, Is.EqualTo("Rhs"));
        }
Пример #13
0
        public void TestCastingWithParseDictionary()
        {
            var dict = new Dictionary <String, String>
            {
                { "Code", "Dutch National" }
            };
            var eq = new ExpressionLib().Parse("Code == 1");

            Assert.IsFalse((bool)eq.Evaluate(new Reflection(dict)));
        }
Пример #14
0
 public DocumentModel(TagLib subject, bool all, ResourceBundle bundle, IList <Func <ITag, TagDocumentation, bool> > specials = null)
 {
     _expressionlib       = new ExpressionLib();
     _tagDictionary       = new Dictionary <int, TagDocumentation>();
     _subject             = subject;
     _all                 = all;
     _specials            = specials ?? new List <Func <ITag, TagDocumentation, bool> >();
     _additionalResources = new Dictionary <string, string>();
     _resouceKey          = new ResourceKeyStack(bundle);
     GatherExpressions();
     GatherFunctions();
     GatherGroups();
 }
Пример #15
0
        public DocumentModel(TagLib subject, bool all, ResourceBundle bundle, IList<Func<ITag, TagDocumentation, bool>> specials=null)
        {
            _expressionlib = new ExpressionLib();

            _subject = subject;
            _all = all;
            _specials = specials??new List<Func<ITag, TagDocumentation, bool>>();
            _additionalResources = new Dictionary<string, string>();
            _resouceKey = new ResourceKeyStack(bundle);
            GatherExpressions();
            GatherFunctions();
            GatherGroups();
        }
Пример #16
0
        public void TestParsingEmptyFunctionEmptWithBooleanExpressionLeftRightSide()
        {
            Expression exp = new ExpressionLib().Parse("fn:empty(EmptyArray) && 'true'");

            Assert.IsTrue(exp is And);

            var and = (And)exp;

            Assert.IsTrue(and.Lhs is Function);
            Assert.IsTrue(and.Rhs is Constant);

            var empty = (Function)and.Lhs;

            Assert.IsTrue(empty.Nested is Brackets);

            var brackets = (Brackets)empty.Nested;

            Assert.IsTrue(brackets.Nested is PropertyOrConstant);
        }
Пример #17
0
        public void TestChechkParsingWithArithmeticBothSide()
        {
            Expression exp = new ExpressionLib().Parse("fn:length('aaa')+fn:length('aaa')");
            Assert.IsTrue(exp is Add);

            var add = (Add) exp;
            Assert.IsTrue(add.Lhs is Function);
            Assert.IsTrue(add.Rhs is Function);

            var funcLhs = (Function) add.Lhs;
            Assert.IsTrue(funcLhs.Nested is Brackets);

            var bracketsLhs = (Brackets) funcLhs.Nested;
            Assert.IsTrue(bracketsLhs.Nested is Constant);

            var funcRhs = (Function) add.Rhs;
            Assert.IsTrue(funcRhs.Nested is Brackets);

            var bracketsRhs = (Brackets) funcRhs.Nested;
            Assert.IsTrue(bracketsRhs.Nested is Constant);
        }
Пример #18
0
 public void TestComparisonTypeCheckWrongRightHandSide()
 {
     Expression exp = new ExpressionLib().Parse("FirstInt<Bool");
     try
     {
         exp.Evaluate(new Reflection(new SampleModel()));
         Assert.Fail("Expected type error");
     }
     catch (ComparisionException CPe)
     {
         Assert.That(CPe.MessageWithOutContext, Is
                                      .EqualTo(ComparisionException.UnComparable(
                                                   typeof(decimal),
                                                   typeof(bool)
                                                  ).Message));
     }
 }
Пример #19
0
 public void TestComparisonTypeBooleansOnBothSides()
 {
     Expression exp = new ExpressionLib().Parse("'true'<'false'");
     Assert.That(exp.Evaluate(new Reflection(new SampleModel())), Is.False);
     exp = new ExpressionLib().Parse("'false'<'true'");
     Assert.That(exp.Evaluate(new Reflection(new SampleModel())), Is.True);
 }
Пример #20
0
 public void ShouldHaveReturnTypeOfConstants_bool()
 {
     var reflection = new Reflection(new SampleModel());
     var e = new ExpressionLib().Parse("'false'");
     Assert.That(e.ReturnType, Is.Not.Null);
     Assert.That(e.ReturnType, Is.EqualTo(typeof(bool)));
 }
Пример #21
0
 public Formatter()
 {
     _lib = new TagLib();
     _expressionLib = new ExpressionLib();
     _lib.Register(new Sharp());
 }
Пример #22
0
 public ExpressionParserHelper(ExpressionLib expressionLib, Tokenizer tokenizer)
     : base(tokenizer)
 {
     _expressionLib = expressionLib;
 }
Пример #23
0
 public void EagerShouldAllowForEmptyString()
 {
     var reflection = new Reflection(new SampleModel());
     var e = new ExpressionLib().Parse("Name == ''");
     Assert.That(e.Evaluate(reflection), Is.False);
 }
Пример #24
0
 public void Should_Handle_Function_With_Zero_Arguments()
 {
     var reflection = new Reflection(new SampleModel());
     var e = new ExpressionLib().Parse("fn:now()");
     Assert.That(e.ReturnType, Is.Not.Null);
     Assert.That(e.ReturnType, Is.EqualTo(typeof(DateTime)));
 }
Пример #25
0
        public void TestTwoBracketsInOneExpressionSameLevel()
        {
            Expression exp = new ExpressionLib().Parse("('14'+'6')/('2'*'5')");
            Assert.That(exp.GetType(), Is.EqualTo(typeof (Divide)));

            var divide = (Divide) exp;

            Assert.That(divide.Lhs.GetType(), Is.EqualTo(typeof (Brackets)));
            Assert.That(divide.Rhs.GetType(), Is.EqualTo(typeof (Brackets)));

            Assert.That(exp.Evaluate(new Reflection(new SampleModel())),
                        Is.EqualTo(2)
                );
        }
Пример #26
0
        public void TestParsingEmptyFunctionEmptWithBooleanExpressionLeftRightSide()
        {
            Expression exp = new ExpressionLib().Parse("fn:empty(EmptyArray) && 'true'");

            Assert.IsTrue(exp is And);

            var and = (And) exp;
            Assert.IsTrue(and.Lhs is Function);
            Assert.IsTrue(and.Rhs is Constant);

            var empty = (Function) and.Lhs;
            Assert.IsTrue(empty.Nested is Brackets);

            var brackets = (Brackets) empty.Nested;
            Assert.IsTrue(brackets.Nested is PropertyOrConstant);
        }
Пример #27
0
        public void TestPrecendeOverridenByBracketsMultipleAboveAddDifferentOrder()
        {
            Expression exp = new ExpressionLib().Parse("'3'*('3'+'2')");
            Assert.That(exp.GetType(), Is.EqualTo(typeof (Multiply)));
            var multipy = (Multiply) exp;
            Assert.That(multipy.Lhs.GetType(), Is.EqualTo(typeof (Constant)));
            Assert.That(multipy.Rhs.GetType(), Is.EqualTo(typeof (Brackets)));
            var brackets = (Brackets) multipy.Rhs;
            Assert.That(brackets.Nested.GetType(), Is.EqualTo(typeof (Add)));
            var add = (Add) brackets.Nested;
            Assert.That(add.Lhs.GetType(), Is.EqualTo(typeof (Constant)));
            Assert.That(add.Rhs.GetType(), Is.EqualTo(typeof (Constant)));

            Assert.That(exp.Evaluate(new Reflection(new SampleModel())),
                        Is.EqualTo(15)
                );
        }
Пример #28
0
 public void TestPrecendeOverridenByBracketsBeforeAndAfterNormal()
 {
     Expression exp = new ExpressionLib().Parse("'2'+('3'*'7')+'2'");
     Assert.That(exp.Evaluate(new Reflection(new SampleModel())),
                 Is.EqualTo(25)
         );
 }
Пример #29
0
        public void TestPrecendeOverridenByBrackets()
        {
            Expression exp = new ExpressionLib().Parse("('2'+'3')*'3'+'2'");

            Assert.That(exp.GetType(), Is.EqualTo(typeof (Add)));

            var add = (Add) exp;
            Assert.That(add.Lhs.GetType(), Is.EqualTo(typeof (Multiply)));
            Assert.That(add.Rhs.GetType(), Is.EqualTo(typeof (Constant)));

            var multipy = (Multiply) add.Lhs;
            Assert.That(multipy.Lhs.GetType(), Is.EqualTo(typeof (Brackets)));
            Assert.That(multipy.Rhs.GetType(), Is.EqualTo(typeof (Constant)));

            Assert.That(exp.Evaluate(new Reflection(new SampleModel())),
                        Is.EqualTo(17)
                );
        }
Пример #30
0
 public void TestComparisonTypeCheckWrongRightHandSide_Static()
 {
     try
     {
         Expression exp = new ExpressionLib().Parse("'8'<'true'");
         Assert.Fail("Expected type error");
     }
     catch (ConvertException CPe)
     {
         Assert.That(CPe.Message, Is
                                      .EqualTo(ConvertException.StaticTypeSafety(
                                                   typeof(decimal),
                                                   typeof(bool),
                                                   "'true'"
                                                  ).Message));
     }
 }
Пример #31
0
 public void TestArithmeticTypeCheckWrongBothSides_Static()
 {
     try
     {
         Expression exp = new ExpressionLib().Parse("'true'+'true'");
         Assert.Fail("Expected type error");
     }
     catch (ConvertException EPe)
     {
         Assert.That(EPe.Message, Is
                                      .EqualTo(ConvertException.StaticTypeSafety(
                                                   typeof(decimal),
                                                   typeof(bool),
                                                   "'true'").Message));
     }
 }
Пример #32
0
 public void TestComparisonTypeForcedStringsOnBothSides()
 {
     Expression exp = new ExpressionLib().Parse("@'8'<@'false'");
     Assert.That(exp.Evaluate(new Reflection(new SampleModel())), Is.True);
     exp = new ExpressionLib().Parse("@'false'<@'8'");
     Assert.That(exp.Evaluate(new Reflection(new SampleModel())), Is.False);
 }
Пример #33
0
 public void TestArithmeticTypeCheckWrongRightHandSide()
 {
     Expression exp = new ExpressionLib().Parse("FirstInt+Bool");
     try
     {
         exp.Evaluate(new Reflection(new SampleModel()));
         Assert.Fail("Expected type error");
     }
     catch (ConvertException EPe)
     {
         Assert.That(EPe.Message, Is
                                      .EqualTo(ConvertException.CannotConvert(
                                                   typeof (decimal),
                                                   true.ToString()).Message));
     }
 }
Пример #34
0
 public void EagerShouldFailOnUnparsedEnd()
 {
     var reflection = new Reflection(new SampleModel());
     try
     {
         var e = new ExpressionLib().Parse("'true' or false'");
         Assert.Fail("Parse error expected");
     }
     catch (ParseException  EPe)
     {
         Assert.That(EPe.MessageWithOutContext, Is.EqualTo(ParseException.ExpectedToken().Message));
     }
 }
Пример #35
0
 public void TestBooleanTupleTypeCheckWrongLeftHandSide_Static()
 {
     try
     {
         Expression exp = new ExpressionLib().Parse("'9'&&'true'");
         Assert.Fail("Expected type error");
     }
     catch (ConvertException EPe)
     {
         Assert.That(EPe.Message, Is
                                      .EqualTo(ConvertException.StaticTypeSafety(
                                                   typeof(bool),
                                                   typeof(decimal),
                                                   "'9'").Message));
     }
 }
 public RelaxedResolveTagLibParser(TagLibForParsing lib, ExpressionLib expressionLib,ParseHelper helper, IResourceLocator locator, IResourceLocatorFactory factory, ITagValidator tagValidator)
     : base(lib, expressionLib, helper, locator,factory,tagValidator)
 {
 }
Пример #37
0
 public void TestBooleanTupleTypeCheckWrongRightHandSide()
 {
     Expression exp = new ExpressionLib().Parse("Bool&&FirstInt");
     try
     {
         exp.Evaluate(new Reflection(new SampleModel()));
         Assert.Fail("Expected type error");
     }
     catch (ConvertException EPe)
     {
         Assert.That(EPe.Message, Is
                                      .EqualTo(ConvertException.CannotConvert(
                                                   typeof (bool),
                                                   "42").Message));
     }
 }
Пример #38
0
 public Formatter OverrideExpressionLib(ExpressionLib lib)
 {
     if (lib == null) return this;
     _expressionLib = lib;
     return this;
 }
Пример #39
0
 public void TestBracketTypeCheckWrongNestedOfProperty()
 {
     Expression exp = new ExpressionLib().Parse("!(FirstInt)");
     try
     {
         exp.Evaluate(new Reflection(new SampleModel()));
         Assert.Fail("Expected type error");
     }
     catch (ConvertException EPe)
     {
         Assert.That(EPe.Message, Is
                                      .EqualTo(ConvertException.CannotConvert(
                                                   typeof (bool),
                                                   "42").Message));
     }
 }
Пример #40
0
 public void ShouldHaveReturnTypeOfExpression_bool2()
 {
     try
     {
         var e = new ExpressionLib().Parse("Name=='NAME VALUE' || '7'");
     }
     catch (ConvertException Pe)
     {
         Assert.That(Pe.Message, Is.EqualTo(ConvertException.StaticTypeSafety(typeof(bool), typeof(decimal), "'7'").Message));
     }
 }
 public StrictResolveTagLibParser(TagLibForParsing lib, ExpressionLib expressionLib, ParseHelper helper, IResourceLocator locator, IResourceLocatorFactory factory, ITagValidator tagValidator)
     : base(lib, expressionLib, helper, locator, factory, tagValidator)
 {
 }
Пример #42
0
        public void TestParsingsEmptyFunctionEmptWithBooleanExpressionBothSides()
        {
            Expression exp = new ExpressionLib().Parse("fn:empty(EmptyArray) && fn:empty(EmptyArray)");
            Assert.IsTrue(exp is And);

            var and = (And) exp;
            Assert.IsTrue(and.Lhs is Function);
            Assert.IsTrue(and.Rhs is Function);

            var emptyLhs = (Function) and.Lhs;
            Assert.IsTrue(emptyLhs.Nested is Brackets);

            var bracketsLhs = (Brackets) emptyLhs.Nested;
            Assert.IsTrue(bracketsLhs.Nested is PropertyOrConstant);

            var emptyRhs = (Function) and.Rhs;
            Assert.IsTrue(emptyLhs.Nested is Brackets);

            var bracketsRhs = (Brackets) emptyRhs.Nested;
            Assert.IsTrue(bracketsRhs.Nested is PropertyOrConstant);
        }
Пример #43
0
 public void ShouldHaveReturnTypeOfExpression_int()
 {
     var reflection = new Reflection(new SampleModel());
     var e = new ExpressionLib().Parse("'6' + '7'");
     Assert.That(e.ReturnType, Is.Not.Null);
     Assert.That(e.ReturnType, Is.EqualTo(typeof(decimal)));
 }