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); }
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); }
public TagLibParserFactory(TagLibForParsing lib, ExpressionLib expressionLib, IResourceLocatorFactory factory, ITagValidator tagValidator) { _lib = lib; _expressionLib = expressionLib; _factory = factory; _tagValidator = tagValidator; }
public Formatter() { _lib = new TagLib(); _expressionLib = new ExpressionLib(); _lib.Register(new Sharp()); _lib.Register(new Macro()); }
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 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; }
public Formatter OverrideExpressionLib(ExpressionLib lib) { if (lib == null) { return(this); } _expressionLib = lib; return(this); }
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; }
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))); }
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")); }
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))); }
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(); }
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(); }
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); }
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); }
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)); } }
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); }
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))); }
public Formatter() { _lib = new TagLib(); _expressionLib = new ExpressionLib(); _lib.Register(new Sharp()); }
public ExpressionParserHelper(ExpressionLib expressionLib, Tokenizer tokenizer) : base(tokenizer) { _expressionLib = expressionLib; }
public void EagerShouldAllowForEmptyString() { var reflection = new Reflection(new SampleModel()); var e = new ExpressionLib().Parse("Name == ''"); Assert.That(e.Evaluate(reflection), Is.False); }
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))); }
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) ); }
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); }
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) ); }
public void TestPrecendeOverridenByBracketsBeforeAndAfterNormal() { Expression exp = new ExpressionLib().Parse("'2'+('3'*'7')+'2'"); Assert.That(exp.Evaluate(new Reflection(new SampleModel())), Is.EqualTo(25) ); }
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) ); }
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)); } }
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)); } }
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); }
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)); } }
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)); } }
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) { }
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)); } }
public Formatter OverrideExpressionLib(ExpressionLib lib) { if (lib == null) return this; _expressionLib = lib; return this; }
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)); } }
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) { }
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); }
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))); }