Exemple #1
0
 static void Main(string[] args)
 {
     WriteLine(Contains("methods")(GetText()));
     WriteLine(Contains("anything")(GetText()));
     WriteLine(StartsWith("Provides")(GetText()));
     WriteLine(StartsWith("anything")(GetText()));
     WriteLine(EndsWith("objects")(GetText()));
     WriteLine(EndsWith("anything")(GetText()));
     WriteLine(IndexOf("objects")(GetText()));
     WriteLine(IndexOf("anything")(GetText()));
     WriteLine(Replace("Provides")("Xpto")(GetText()));
     WriteLine(Replace("anything")("Xpto")(GetText()));
 }
Exemple #2
0
 private int ComputeHashCode()
 {
     return(HashCode.Compute(
                StartsWith.GetHashCode(),
                Expression.GetHashCode(),
                EndsWith.GetHashCode()));
 }
        public override string visit(EndsWith endswith)
        {
            string sToSplit = base.visit(endswith);

            this.addtodic(sToSplit);
            return(sToSplit);
        }
Exemple #4
0
 public IEnumerator <ITask> EndsWithHandler(EndsWith endsWith)
 {
     endsWith.ResponsePort.Post(
         EndsWithResponse.FromRequest(endsWith.Body)
         );
     yield break;
 }
        private ComparisonOperator ComparisonOperator()
        {
            if (this.lexer.Token == null || !this.lexer.Token.Is(TokenType.Name))
            {
                this.SyntaxError("comparision operator");
            }

            ComparisonOperator comparisonOperator = null;

            switch (this.lexer.Token.Value)
            {
            case "pr":
                comparisonOperator = new Present();
                break;

            case "eq":
                comparisonOperator = new Equal();
                break;

            case "ne":
                comparisonOperator = new NotEqual();
                break;

            case "co":
                comparisonOperator = new Contains();
                break;

            case "sw":
                comparisonOperator = new StartsWith();
                break;

            case "ew":
                comparisonOperator = new EndsWith();
                break;

            case "gt":
                comparisonOperator = new GreaterThan();
                break;

            case "lt":
                comparisonOperator = new LessThan();
                break;

            case "ge":
                comparisonOperator = new GreaterThanOrEqual();
                break;

            case "le":
                comparisonOperator = new LessThanOrEqual();
                break;

            default:
                this.SyntaxError("comparision operator");
                break;
            }

            this.Match(this.lexer.Token.Name);
            return(comparisonOperator);
        }
Exemple #6
0
        public void ToString_TextArgument_ReturnsExpected()
        {
            var function = new EndsWith();

            function.AddArgument(new HypnoGreen.Types.Text("denmark"));
            function.AddArgument(new HypnoGreen.Types.Text("ark"));
            Assert.AreEqual("EndsWith(\"denmark\", \"ark\")", function.ToString());
        }
Exemple #7
0
        public void Evaluate_TextAndText_ReturnsFalse(string text, string substring)
        {
            var endsWith = new EndsWith();

            endsWith.AddArgument(new HypnoGreen.Types.Text(text));
            endsWith.AddArgument(new HypnoGreen.Types.Text(substring));
            Assert.False(endsWith.EvaluateWithData <bool>());
        }
Exemple #8
0
        public void Evaluate_NullAndText_ReturnsFalse()
        {
            var endsWith = new EndsWith();

            endsWith.AddArgument(Null.Instance);
            endsWith.AddArgument(new HypnoGreen.Types.Text("denmark"));
            Assert.Throws <InvalidOperationException>(() =>
            {
                endsWith.EvaluateWithData();
            });
        }
        public void SelectsEndsWith()
        {
            var spec = new EndsWith("value");

            Assert.That(spec.IsSatisfiedBy("value"), Is.True);
            Assert.That(spec.IsSatisfiedBy("ValuE"), Is.True);
            Assert.That(spec.IsSatisfiedBy("avalue"), Is.True);
            Assert.That(spec.IsSatisfiedBy("valuea"), Is.False);
            Assert.That(spec.IsSatisfiedBy("val"), Is.False);
            Assert.That(spec.IsSatisfiedBy(String.Empty), Is.False);
            //Assert.That(spec.IsSatisfiedBy(null), Is.False);
        }
Exemple #10
0
 public StringFilter ToUpper()
 {
     Equal         = Equal?.ToUpper();
     NotEqual      = NotEqual?.ToUpper();
     Contains      = Contains?.ToUpper();
     NotContains   = NotContains?.ToUpper();
     StartsWith    = StartsWith?.ToUpper();
     NotStartsWith = NotStartsWith?.ToUpper();
     EndsWith      = EndsWith?.ToUpper();
     NotEndsWith   = NotEndsWith?.ToUpper();
     return(this);
 }
Exemple #11
0
        public override string GetRegexPattern()
        {
            if (String.IsNullOrEmpty(EscapesWith))
            {
                if (EndsWith.CompareTo(@"\n") == 0)
                {
                    return(String.Format(@"{0}[^\n\r]*", Escape(BeginsWith)));
                }

                return(String.Format(@"{0}[\w\W\s\S]*?{1}", Escape(BeginsWith), Escape(EndsWith)));
            }

            return(String.Format("{0}(?>{1}.|[^{2}]|.)*?{3}", new object[] { Regex.Escape(BeginsWith), Regex.Escape(EscapesWith.Substring(0, 1)), Regex.Escape(EndsWith.Substring(0, 1)), Regex.Escape(EndsWith) }));
        }
        public void EndsWithCriteria()
        {
            var spec = new EndsWith("value", StringComparison.Ordinal);
            var criteria = spec.Criteria;

            Assert.That(criteria.Body, Is.AssignableTo<MethodCallExpression>());

            var call = (MethodCallExpression)criteria.Body;

            Assert.That(call.Arguments, Has.Count.EqualTo(2));
            Assert.That(call.Arguments[0], Is.TypeOf<ConstantExpression>());
            Assert.That(call.Arguments[1], Is.TypeOf<ConstantExpression>());
            Assert.That(call.Method, Is.EqualTo(typeof(String).GetMethod("EndsWith", new[] { typeof(string), typeof(StringComparison) })));
            Assert.That(call.Object, Is.AssignableTo<ParameterExpression>());

            var arg0 = (ConstantExpression)call.Arguments[0];
            Assert.That(arg0.Value, Is.EqualTo("value"));

            var arg1 = (ConstantExpression)call.Arguments[1];
            Assert.That(arg1.Value, Is.EqualTo(StringComparison.Ordinal));

            ExpressionWriter.Write(criteria);
        }
Exemple #13
0
 public StringFilter ToUpper()
 {
     if (Equal != null)
     {
         Equal = Equal.ToUpper();
     }
     if (NotEqual != null)
     {
         NotEqual = NotEqual.ToUpper();
     }
     if (Contains != null)
     {
         Contains = Contains.ToUpper();
     }
     if (NotContains != null)
     {
         NotContains = NotContains.ToUpper();
     }
     if (StartsWith != null)
     {
         StartsWith = StartsWith.ToUpper();
     }
     if (NotStartsWith != null)
     {
         NotStartsWith = NotStartsWith.ToUpper();
     }
     if (EndsWith != null)
     {
         EndsWith = EndsWith.ToUpper();
     }
     if (NotEndsWith != null)
     {
         NotEndsWith = NotEndsWith.ToUpper();
     }
     return(this);
 }
 public override string visit(EndsWith endswith)
 {
     string sToSplit = base.visit(endswith);
     this.addtodic(sToSplit);
     return sToSplit;
 }
 public void EndsWithCorrectlyConvertsToJson()
 {
     var ew = new EndsWith("0603");
     ew.ToString().ShouldEqual(EndsWithJson);
 }
        public void EndsWithCorrectlyConvertsToJson()
        {
            var ew = new EndsWith("0603");

            ew.ToString().ShouldEqual(EndsWithJson);
        }
Exemple #17
0
 public override string GetRegexPattern()
 => string.IsNullOrEmpty(EscapesWith)
     ? string.Equals(EndsWith, @"\n", StringComparison.Ordinal) ? $@"{Escape(BeginsWith)}[^\n\r]*" : $@"{Escape(BeginsWith)}[\w\W\s\S]*?{Escape(EndsWith)}"
     : $"{Regex.Escape(BeginsWith)}(?>{Regex.Escape(EscapesWith.Substring(0, 1))}.|[^{Regex.Escape(EndsWith.Substring(0, 1))}]|.)*?{Regex.Escape(EndsWith)}";
Exemple #18
0
        public Expression GetNode(ExpressionParser parser)
        {
            Lexem      lex   = parser.Collection.CurrentLexem();
            Expression ex    = null;
            bool       uniar = parser.waitValue;

            if (lex.LexemType == LexType.Arfimetic)
            {
                switch (lex.LexemText)
                {
                case "+":
                    if (uniar)
                    {
                        ex = new UniarPlus_BoolExpr();
                    }
                    else
                    {
                        ex = new Plus_Arifmetic();
                    }
                    break;

                case "-":
                    if (uniar)
                    {
                        ex = new UniarMinus_BoolExpr();
                    }
                    else
                    {
                        ex = new Minus_Arifmetic();
                    }
                    break;

                case "*":
                    if (uniar)
                    {
                        ex = new AllColumnExpr();
                    }
                    else
                    {
                        ex = new Multi_Arifmetic();
                    }
                    break;

                case "/":
                    ex = new Div_Arifmetic();
                    break;

                case "<":
                    ex = new Less_CompExpr();
                    break;

                case "<=":
                    ex = new LessOrEqual_CompExpr();
                    break;

                case ">=":
                    ex = new GreatOrEqual_CompExpr();
                    break;

                case ">":
                    ex = new Great_CompExpr();
                    break;

                case "=":
                    ex = new Equal_CompExpr();
                    break;

                case "<>":
                case "!=":
                    ex = new NotEqual_CompExpr();
                    break;
                }
            }
            if (lex.LexemType == LexType.Number)
            {
                ex = new ConstExpr();
                if (lex.LexemText.Contains('.'))
                {
                    (ex as ConstExpr).Init(lex.LexemText.ParseDouble(), SimpleTypes.Float);
                }
                else
                {
                    (ex as ConstExpr).Init(long.Parse(lex.LexemText), SimpleTypes.Integer);
                }
            }
            if (lex.LexemType == LexType.Text)
            {
                if (lex.LexemText.StartsWith("'"))
                {
                    ex = new ConstExpr();
                    (ex as ConstExpr).Init(ParserUtils.StandartDecodeEscape(lex.LexemText), SimpleTypes.String);
                }
            }
            Lexem n1;

            if (lex.LexemType == LexType.Command)
            {
                switch (lex.LexemText.ToLower())
                {
                case "not":
                    n1 = parser.Collection.GetNext();
                    if (n1 != null && n1.LexemType == LexType.Command && n1.LexemText.ToLower() == "in")
                    {
                        ex = new NotInExpr();
                        parser.Collection.GotoNext();
                        break;
                    }
                    ex = new Not_BoolExpr();
                    break;

                case "case":
                    ex = new CaseExpr();
                    break;

                case "contains":
                    ex = new Contains();
                    break;

                case "containsic":     //ic = ignore case
                case "containscase":
                    ex = new ContainsIgnoreCase();
                    break;

                case "startwith":
                case "startswith":
                    ex = new StartsWith();
                    break;

                case "endwith":
                case "endswith":
                    ex = new EndsWith();
                    break;
                }
                if (parser.Collection.GetNext() != null && parser.Collection.GetNext().IsSkobraOpen())
                {
                    switch (lex.LexemText.ToLower())
                    {
                    case "cast":
                        ex = new Cast();
                        break;

                    case "in":
                        ex = new InExpr();
                        break;

                    case "abs":
                        ex = new Abs();
                        break;

                    case "substring":
                        ex = new SubString();
                        break;

                    case "position":
                        ex = new Position();
                        break;

                    case "ltrim":
                        ex = new LTrim();
                        break;

                    case "rtrim":
                        ex = new RTrim();
                        break;

                    case "trim":
                        ex = new Trim();
                        break;

                    case "length":
                        ex = new Length();
                        break;

                    case "upper":
                        ex = new Upper_operation();
                        break;

                    case "lower":
                        ex = new Lower_operation();
                        break;

                    case "left":
                        ex = new Left();
                        break;

                    case "right":
                        ex = new Right();
                        break;

                    case "replace":
                        ex = new Replace();
                        break;

                    case "now":
                        ex = new Now();
                        break;

                    case "tostr":
                        ex = new ToString();
                        break;

                    case "strtotime":
                        ex = new StrToTime();
                        break;

                    case "strtodatetime":
                        ex = new StrToDateTime();
                        break;

                    case "addseconds":
                        ex = new AddSeconds();
                        break;

                    case "addminutes":
                        ex = new AddMinutes();
                        break;

                    case "addhours":
                        ex = new AddHours();
                        break;

                    case "adddays":
                        ex = new AddDays();
                        break;

                    case "day":
                        ex = new Day();
                        break;

                    case "month":
                        ex = new Month();
                        break;

                    case "year":
                        ex = new Year();
                        break;

                    case "round":
                        ex = new ParserCore.Expr.Extend.Math.Round();
                        break;

                    case "ceiling":
                        ex = new ParserCore.Expr.Extend.Math.Ceiling();
                        break;

                    case "floor":
                        ex = new ParserCore.Expr.Extend.Math.Floor();
                        break;

                    case "pi":
                        ex = new ParserCore.Expr.Extend.Math.Pi();
                        break;

                    case "tan":
                        ex = new ParserCore.Expr.Extend.Math.Tan();
                        break;

                    case "log":
                        ex = new ParserCore.Expr.Extend.Math.Log();
                        break;
                    }
                }
            }
            return(ex);
        }
        public static void CreateFilter(object sender, object selectedItem)
        {
            if (selectedItem is FilterCollectionViewModel filterCollectionViewModel)
            {
                CreateFilter(sender, filterCollectionViewModel.Parent);
                return;
            }

            var button = (Button)sender;

            var type = (string)button.CommandParameter;

            FilterBase entity;

            switch (type)
            {
            case nameof(ActiveOn):
                entity = ActiveOn.New("0001-01-01");
                break;

            case nameof(ActiveWithin):
                entity = ActiveWithin.New("0001-01-01,0001-01-01");
                break;

            case nameof(OfType):
                entity = OfType.New("TypeName");
                break;

            case nameof(NotOfType):
                entity = NotOfType.New("TypeName");
                break;

            case nameof(Contain):
                entity = Contain.New("Property", "Value");
                break;

            case nameof(NotContain):
                entity = NotContain.New("Property", "Value");
                break;

            case nameof(EqualTo):
                entity = EqualTo.New("Property", "Value");
                break;

            case nameof(NotEqualTo):
                entity = NotEqualTo.New("Property", "Value");
                break;

            case nameof(GreaterThan):
                entity = GreaterThan.New("Property", "Value");
                break;

            case nameof(LessThan):
                entity = LessThan.New("Property", "Value");
                break;

            case nameof(GreaterThanEqualTo):
                entity = GreaterThanEqualTo.New("Property", "Value");
                break;

            case nameof(LessThanEqualTo):
                entity = LessThanEqualTo.New("Property", "Value");
                break;

            case nameof(Between):
                entity = Between.New("Property", "0001-01-01", "0001-01-01");
                break;

            case nameof(WithinArray):
                entity = WithinArray.New("Property", "ValueA,ValueB,ValueC");
                break;

            case nameof(NotWithinArray):
                entity = NotWithinArray.New("Property", "ValueA,ValueB,ValueC");
                break;

            case nameof(IsNull):
                entity = IsNull.New("Property");
                break;

            case nameof(IsNotNull):
                entity = IsNotNull.New("Property");
                break;

            case nameof(IsNullOrGreaterThan):
                entity = IsNullOrGreaterThan.New("Property", "Value");
                break;

            case nameof(IsNullOrGreaterThanEqualTo):
                entity = IsNullOrGreaterThanEqualTo.New("Property", "Value");
                break;

            case nameof(IsNullOrLessThan):
                entity = IsNullOrLessThan.New("Property", "Value");
                break;

            case nameof(IsNullOrLessThanEqualTo):
                entity = IsNullOrLessThanEqualTo.New("Property", "Value");
                break;

            case nameof(StartsWith):
                entity = StartsWith.New("Property", "Value");
                break;

            case nameof(EndsWith):
                entity = EndsWith.New("Property", "Value");
                break;

            case nameof(TakeFirst):
                entity = TakeFirst.New(1);
                break;

            case nameof(OfDerivedType):
                entity = OfDerivedType.New("TypeName");
                break;

            case nameof(NotOfDerivedType):
                entity = NotOfDerivedType.New("TypeName");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            FilterViewModel           viewModel;
            FilterCollectionViewModel viewModelCollection;

            if (selectedItem is GroupViewModel entityGroupViewModel)
            {
                entityGroupViewModel.IsExpanded = true;

                entityGroupViewModel.Element.Filters.Add(entity);
                viewModelCollection = entityGroupViewModel.Children.OfType <FilterCollectionViewModel>().First();

                viewModel = new FilterViewModel(entity, viewModelCollection);
                viewModelCollection.Children.Add(viewModel);
            }
            else if (selectedItem is OutputViewModel outputViewModel)
            {
                if (!(outputViewModel.Element is AggregateOutputBase elementAsAggregate))
                {
                    return;
                }

                outputViewModel.IsExpanded = true;

                elementAsAggregate.Filters.Add(entity);
                viewModelCollection = outputViewModel.Children.OfType <FilterCollectionViewModel>().First();

                viewModel = new FilterViewModel(entity, viewModelCollection);
                viewModelCollection.Children.Add(viewModel);
            }
            else
            {
                return;
            }

            viewModelCollection.IsExpanded = true;
            viewModel.IsSelected           = true;
            viewModel.IsExpanded           = true;
        }