Exemple #1
0
        public async Task TestTextP()
        {
            var expected            = TextP.Containing("o");
            var writer              = CreateGraphBinaryWriter();
            var reader              = CreateGraphBinaryReader();
            var serializationStream = new MemoryStream();

            await writer.WriteAsync(expected, serializationStream);

            serializationStream.Position = 0;
            var actual = (TextP)await reader.ReadAsync(serializationStream);

            Assert.Equal(expected.OperatorName, actual.OperatorName);
            Assert.Equal(expected.Other, actual.Other);
            Assert.Equal(expected.Value, actual.Value);
        }
Exemple #2
0
            public P?TryGetP(ExpressionSemantics semantics, object?value, IGremlinQueryEnvironment environment)
            {
                switch (semantics)
                {
                case ContainsExpressionSemantics:
                {
                    return(new P("eq", value));
                }

                case IntersectsExpressionSemantics:
                {
                    return(P.Within(value));
                }

                case IsContainedInExpressionSemantics:
                {
                    return(P.Within(value));
                }

                case StringExpressionSemantics stringExpressionSemantics when value is string stringValue:
                {
                    if (stringValue.Length == 0 || stringExpressionSemantics.Comparison == StringComparison.Ordinal || environment.Options.GetValue(GremlinqOption.StringComparisonTranslationStrictness) == StringComparisonTranslationStrictness.Lenient)
                    {
                        switch (stringExpressionSemantics)
                        {
                        case StringEqualsExpressionSemantics:
                        {
                            return(new P("eq", stringValue));
                        }

                        case IsPrefixOfExpressionSemantics:
                        {
                            return(P.Within(SubStrings(stringValue)));
                        }

                        case HasInfixExpressionSemantics:
                        {
                            return(stringValue.Length > 0
                                        ? TextP.Containing(stringValue)
                                        : PNeqNull);
                        }

                        case StartsWithExpressionSemantics:
                        {
                            return(stringValue.Length > 0
                                        ? TextP.StartingWith(stringValue)
                                        : PNeqNull);
                        }

                        case EndsWithExpressionSemantics:
                        {
                            return(stringValue.Length > 0
                                        ? TextP.EndingWith(stringValue)
                                        : PNeqNull);
                        }
                        }
                    }

                    break;
                }

                case EqualsExpressionSemantics:
                {
                    return(new P("eq", value));
                }

                case NotEqualsExpressionSemantics:
                {
                    return(new P("neq", value));
                }

                case ObjectExpressionSemantics:
                {
                    switch (semantics)
                    {
                    case LowerThanExpressionSemantics:
                    {
                        return(new P("lt", value));
                    }

                    case GreaterThanExpressionSemantics:
                    {
                        return(new P("gt", value));
                    }

                    case GreaterThanOrEqualExpressionSemantics:
                    {
                        return(new P("gte", value));
                    }

                    case LowerThanOrEqualExpressionSemantics:
                    {
                        return(new P("lte", value));
                    }
                    }

                    break;
                }
                }

                throw new ExpressionNotSupportedException();
            }