Exemplo n.º 1
0
        public void ScanMultipleQuoted()
        {
            string json = @"{
    ""Node1"": {
        ""Child1"": {
            ""Name"": ""IsMe"",
            ""TargetNode"": {
                ""Prop1"": ""Val1"",
                ""Prop2"": ""Val2""
            }
        },
        ""My.Child.Node"": {
            ""TargetNode"": {
                ""Prop1"": ""Val3"",
                ""Prop2"": ""Val4""
            }
        }
    },
    ""Node2"": {
        ""TargetNode"": {
            ""Prop1"": ""Val5"",
            ""Prop2"": ""Val6""
        }
    }
}";

            var models = MiniJSON.jsonDecode(json);

            var results = new JPath("$..['My.Child.Node','Prop1','Prop2']").Evaluate(models, models, false).ToList();

            Assert.Contains(((dynamic)models)["Node1"]["My.Child.Node"], results);
            Assert.Contains("Val1", results);
            Assert.Contains("Val2", results);
            Assert.Contains("Val3", results);
            Assert.Contains("Val4", results);
            Assert.Contains("Val5", results);
            Assert.Contains("Val6", results);
        }
Exemplo n.º 2
0
        public void FilterTrue()
        {
            string json = @"{
  ""elements"": [
    {
      ""id"": ""A"",
      ""children"": [
        {
          ""id"": ""AA"",
          ""children"": [
            {
              ""id"": ""AAA""
            },
            {
              ""id"": ""AAB""
            }
          ]
        },
        {
          ""id"": ""AB""
        }
      ]
    },
    {
      ""id"": ""B"",
      ""children"": []
    }
  ]
}";

            var models = MiniJSON.jsonDecode(json);

            var results = new JPath("$.elements[?(true)]").Evaluate(models, models, false).ToList();

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual(results[0], ((dynamic)models)["elements"][0]);
            Assert.AreEqual(results[1], ((dynamic)models)["elements"][1]);
        }
Exemplo n.º 3
0
        public void ScanFilter()
        {
            string json = @"{
  ""elements"": [
    {
      ""id"": ""A"",
      ""children"": [
        {
          ""id"": ""AA"",
          ""children"": [
            {
              ""id"": ""AAA""
            },
            {
              ""id"": ""AAB""
            }
          ]
        },
        {
          ""id"": ""AB""
        }
      ]
    },
    {
      ""id"": ""B"",
      ""children"": []
    }
  ]
}";

            var models = MiniJSON.jsonDecode(json);

            var results = new JPath("$.elements..[?(@.id=='AAA')]").Evaluate(models, models, false).ToList();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(((dynamic)models)["elements"][0]["children"][0]["children"][0], results[0]);
        }
Exemplo n.º 4
0
 public void IndexerOnly()
 {
     JPath path = new JPath("[111119990]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(111119990, ((ArrayIndexFilter)path.Filters[0]).Index);
 }
Exemplo n.º 5
0
 public void FilterWithFloatExp()
 {
     JPath path = new JPath("[?(@.name>=5.56789e+0)]");
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression;
     Assert.AreEqual(5.56789e+0, (double)expressions.Value);
 }
Exemplo n.º 6
0
        public void FilterExistWithAndOr()
        {
            JPath path = new JPath("[?(@.name&&@.title||@.pie)]");
            CompositeExpression andExpression = (CompositeExpression)((QueryFilter)path.Filters[0]).Expression;
            Assert.AreEqual(QueryOperator.And, andExpression.Operator);
            Assert.AreEqual(2, andExpression.Expressions.Count);
            Assert.AreEqual("name", ((FieldFilter)((BooleanQueryExpression)andExpression.Expressions[0]).Path[0]).Name);
            Assert.AreEqual(QueryOperator.Exists, andExpression.Expressions[0].Operator);

            CompositeExpression orExpression = (CompositeExpression)andExpression.Expressions[1];
            Assert.AreEqual(2, orExpression.Expressions.Count);
            Assert.AreEqual("title", ((FieldFilter)((BooleanQueryExpression)orExpression.Expressions[0]).Path[0]).Name);
            Assert.AreEqual(QueryOperator.Exists, orExpression.Expressions[0].Operator);
            Assert.AreEqual("pie", ((FieldFilter)((BooleanQueryExpression)orExpression.Expressions[1]).Path[0]).Name);
            Assert.AreEqual(QueryOperator.Exists, orExpression.Expressions[1].Operator);
        }
Exemplo n.º 7
0
 public void FilterWithNegativeInteger()
 {
     JPath path = new JPath("[?(@.name>=-12)]");
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression;
     Assert.AreEqual(-12, (int)expressions.Value);
 }
Exemplo n.º 8
0
 public DoubleCondition(String expr, JPath fld, ConditionType type, String rawValue)
     : base(expr, fld, type, rawValue)
 {
     testValue = Invariant.ToDouble(rawValue);
 }
Exemplo n.º 9
0
 public void SinglePropertyWithRootWithStartAndEndWhitespace()
 {
     JPath path = new JPath(" $.Blah ");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
 }
Exemplo n.º 10
0
 public void SlicingIndexWhitespace()
 {
     JPath path = new JPath("[  -111119990  :  -3  :  -2  ]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(-111119990, ((ArraySliceFilter)path.Filters[0]).Start);
     Assert.AreEqual(-3, ((ArraySliceFilter)path.Filters[0]).End);
     Assert.AreEqual(-2, ((ArraySliceFilter)path.Filters[0]).Step);
 }
Exemplo n.º 11
0
 public KeyAndType(JPath k, CompareType t)
 {
     Key  = k;
     Type = t;
 }
Exemplo n.º 12
0
 public Comparer1Base(KeyAndType keyAndType)
 {
     this.path    = keyAndType.Key;
     this.reverse = (keyAndType.Type & CompareType.Descending) != 0;
 }
Exemplo n.º 13
0
 public KeySource_JsonExpr(String input, String expr)
     : base(input)
 {
     this.expr = new JPath(expr);
 }
Exemplo n.º 14
0
 public UndupCountAction(IPostProcessor processor, XmlNode node)
 {
     toField = new JPath(node.ReadStr("@tofield"));
 }
Exemplo n.º 15
0
 public void MultipleIndexesWithWhitespace()
 {
     JPath path = new JPath("[   111119990  ,   3   ]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(2, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes.Count);
     Assert.AreEqual(111119990, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[0]);
     Assert.AreEqual(3, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[1]);
 }
Exemplo n.º 16
0
 public KeyAndType(String k, CompareType t)
 {
     Key  = new JPath(k);
     Type = t;
 }
Exemplo n.º 17
0
 public void SlicingIndex()
 {
     JPath path = new JPath("[111119990:3]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(111119990, ((ArraySliceFilter)path.Filters[0]).Start);
     Assert.AreEqual(3, ((ArraySliceFilter)path.Filters[0]).End);
     Assert.AreEqual(null, ((ArraySliceFilter)path.Filters[0]).Step);
 }
Exemplo n.º 18
0
 public KeyAndType(XmlNode node)
 {
     Key  = new JPath(node.ReadStr("@expr"));
     Type = node.ReadEnum <CompareType>("@type");
 }
Exemplo n.º 19
0
 public void SingleQuotedPropertyWithDots()
 {
     JPath path = new JPath("['Blah.Ha']");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual("Blah.Ha", ((FieldFilter)path.Filters[0]).Name);
 }
Exemplo n.º 20
0
 public void WildcardArrayWithProperty()
 {
     JPath path = new JPath("[ * ].derp");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual(null, ((ArrayIndexFilter)path.Filters[0]).Index);
     Assert.AreEqual("derp", ((FieldFilter)path.Filters[1]).Name);
 }
Exemplo n.º 21
0
 public NullOrEmptyCondition(String expr, JPath fld, ConditionType type, String rawValue)
     : base(expr, fld, type, rawValue)
 {
     CheckOnlyEQ();
 }
Exemplo n.º 22
0
 public void QuotedWildcardPropertyWithRoot()
 {
     JPath path = new JPath("$.['*']");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual("*", ((FieldFilter)path.Filters[0]).Name);
 }
 public Difference(DifferenceKind kind, JPath path)
 {
     Kind = kind;
     Path = path;
 }
Exemplo n.º 24
0
 public void SingleScanWithRoot()
 {
     JPath path = new JPath("$..Blah");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual("Blah", ((ScanFilter)path.Filters[0]).Name);
 }
Exemplo n.º 25
0
 public void FilterExistWithAnd()
 {
     JPath path = new JPath("[?(@.name&&@.title)]");
     CompositeExpression expressions = (CompositeExpression)((QueryFilter)path.Filters[0]).Expression;
     Assert.AreEqual(QueryOperator.And, expressions.Operator);
     Assert.AreEqual(2, expressions.Expressions.Count);
     Assert.AreEqual("name", ((FieldFilter)((BooleanQueryExpression)expressions.Expressions[0]).Path[0]).Name);
     Assert.AreEqual(QueryOperator.Exists, expressions.Expressions[0].Operator);
     Assert.AreEqual("title", ((FieldFilter)((BooleanQueryExpression)expressions.Expressions[1]).Path[0]).Name);
     Assert.AreEqual(QueryOperator.Exists, expressions.Expressions[1].Operator);
 }
Exemplo n.º 26
0
 public void WildcardScanWithRootWithWhitespace()
 {
     JPath path = new JPath("$..* ");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(null, ((ScanFilter)path.Filters[0]).Name);
 }
Exemplo n.º 27
0
 public void SingleProperty()
 {
     JPath path = new JPath("Blah");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
 }
Exemplo n.º 28
0
 public void TwoProperties()
 {
     JPath path = new JPath("Blah.Two");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
     Assert.AreEqual("Two", ((FieldFilter)path.Filters[1]).Name);
 }
Exemplo n.º 29
0
 public void MultiplePropertiesAndIndexers()
 {
     JPath path = new JPath("Blah[0]..Two.Three[1].Four");
     Assert.AreEqual(6, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter) path.Filters[0]).Name);
     Assert.AreEqual(0, ((ArrayIndexFilter) path.Filters[1]).Index);
     Assert.AreEqual("Two", ((ScanFilter)path.Filters[2]).Name);
     Assert.AreEqual("Three", ((FieldFilter)path.Filters[3]).Name);
     Assert.AreEqual(1, ((ArrayIndexFilter)path.Filters[4]).Index);
     Assert.AreEqual("Four", ((FieldFilter)path.Filters[5]).Name);
 }
Exemplo n.º 30
0
 public void OnePropertyOneScan()
 {
     JPath path = new JPath("Blah..Two");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
     Assert.AreEqual("Two", ((ScanFilter)path.Filters[1]).Name);
 }
Exemplo n.º 31
0
 public void IndexerOnlyWithWhitespace()
 {
     JPath path = new JPath("[  10  ]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(10, ((ArrayIndexFilter)path.Filters[0]).Index);
 }
Exemplo n.º 32
0
 public void SinglePropertyAndIndexer()
 {
     JPath path = new JPath("Blah[0]");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
     Assert.AreEqual(0, ((ArrayIndexFilter)path.Filters[1]).Index);
 }
Exemplo n.º 33
0
 public void MultipleQuotedIndexesWithWhitespace()
 {
     JPath path = new JPath("[ '111119990' , '3' ]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(2, ((FieldMultipleFilter)path.Filters[0]).Names.Count);
     Assert.AreEqual("111119990", ((FieldMultipleFilter)path.Filters[0]).Names[0]);
     Assert.AreEqual("3", ((FieldMultipleFilter)path.Filters[0]).Names[1]);
 }
Exemplo n.º 34
0
 public void SinglePropertyAndExistsQuery()
 {
     JPath path = new JPath("Blah[ ?( @..name ) ]");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[1]).Expression;
     Assert.AreEqual(QueryOperator.Exists, expressions.Operator);
     Assert.AreEqual(1, expressions.Path.Count);
     Assert.AreEqual("name", ((ScanFilter)expressions.Path[0]).Name);
 }
Exemplo n.º 35
0
 public void SlicingIndexEmptyStart()
 {
     JPath path = new JPath("[ : 1 : ]");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual(null, ((ArraySliceFilter)path.Filters[0]).Start);
     Assert.AreEqual(1, ((ArraySliceFilter)path.Filters[0]).End);
     Assert.AreEqual(null, ((ArraySliceFilter)path.Filters[0]).Step);
 }
Exemplo n.º 36
0
 public void SinglePropertyAndFilterWithDoubleEscape()
 {
     JPath path = new JPath(@"Blah[ ?( @.name=='h\\i' ) ]");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[1]).Expression;
     Assert.AreEqual(QueryOperator.Equals, expressions.Operator);
     Assert.AreEqual("h\\i", (string)expressions.Value);
 }
Exemplo n.º 37
0
 public void AdjacentIndexers()
 {
     JPath path = new JPath("[1][0][0][" + int.MaxValue + "]");
     Assert.AreEqual(4, path.Filters.Count);
     Assert.AreEqual(1, ((ArrayIndexFilter)path.Filters[0]).Index);
     Assert.AreEqual(0, ((ArrayIndexFilter)path.Filters[1]).Index);
     Assert.AreEqual(0, ((ArrayIndexFilter)path.Filters[2]).Index);
     Assert.AreEqual(int.MaxValue, ((ArrayIndexFilter)path.Filters[3]).Index);
 }
Exemplo n.º 38
0
 public void SinglePropertyAndFilterWithNull()
 {
     JPath path = new JPath("Blah[ ?( @.name==null ) ]");
     Assert.AreEqual(2, path.Filters.Count);
     Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name);
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[1]).Expression;
     Assert.AreEqual(QueryOperator.Equals, expressions.Operator);
     Assert.AreEqual(null, expressions.Value.Value);
 }
Exemplo n.º 39
0
 public void SingleQuotedPropertyWithBrackets()
 {
     JPath path = new JPath("['[*]']");
     Assert.AreEqual(1, path.Filters.Count);
     Assert.AreEqual("[*]", ((FieldFilter)path.Filters[0]).Name);
 }
Exemplo n.º 40
0
 public void FilterWithScan()
 {
     JPath path = new JPath("[?(@..name<>null)]");
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression;
     Assert.AreEqual("name", ((ScanFilter)expressions.Path[0]).Name);
 }
Exemplo n.º 41
0
        public static Condition Create(String cond, XmlNode node = null)
        {
            String[]      arr      = cond.Split(',');//"field,eq|aaa,123" "eq,123"   "field, eq"
            String        fld      = null;
            String        rawValue = null;
            ConditionType type;

            switch (arr.Length)
            {
            case 1:  //only conditiontype
                type = Invariant.ToEnum <ConditionType>(arr[0]);
                break;

            case 2:  //field and condition
                fld  = String.IsNullOrEmpty(arr[0]) ? null : arr[0].Trim();
                type = Invariant.ToEnum <ConditionType>(arr[1]);
                break;

            case 3:  //field, condition and value
                fld      = String.IsNullOrEmpty(arr[0]) ? null : arr[0].Trim();
                type     = Invariant.ToEnum <ConditionType>(arr[1]);
                rawValue = arr[2];
                break;

            default:
                throw new BMNodeException(node, "Invalid condition [{0}]: must be formed like <field, cond, value>.", cond);
            }
            if ((type & Operators) == 0)
            {
                type |= ConditionType.EQ;
            }
            if ((type & Types) == 0)
            {
                type |= ConditionType.String;
            }

            JPath path = fld == null ? null : new JPath(fld);

            switch ((ConditionType)(type & (ConditionType.CaseSensitive - 1)))
            {
            default:
            case ConditionType.String:
                if (String.IsNullOrEmpty(rawValue))
                {
                    return(new NullOrEmptyCondition(cond, path, type, rawValue));
                }
                return(new StringCondition(cond, path, type, rawValue));

            case ConditionType.IsNull:
                return(new NullCondition(cond, path, type, rawValue));

            case ConditionType.IsNullOrEmpty:
                return(new NullOrEmptyCondition(cond, path, type, rawValue));

            case ConditionType.SubString:
                return(new SubStringCondition(cond, path, type, rawValue));

            case ConditionType.Regex:
                return(new RegexCondition(cond, path, type, rawValue));

            case ConditionType.Double:
                return(new DoubleCondition(cond, path, type, rawValue));

            case ConditionType.Int:
                return(new LongCondition(cond, path, type, rawValue));
            }
        }
Exemplo n.º 42
0
 public void FilterWithLessThan()
 {
     JPath path = new JPath("[?(@.name<null)]");
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression;
     Assert.AreEqual(QueryOperator.LessThan, expressions.Operator);
 }
Exemplo n.º 43
0
 public SubStringCondition(String expr, JPath fld, ConditionType type, String rawValue)
     : base(expr, fld, type, rawValue)
 {
 }
Exemplo n.º 44
0
 public void FilterWithGreaterThanOrEquals()
 {
     JPath path = new JPath("[?(@.name>=null)]");
     BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression;
     Assert.AreEqual(QueryOperator.GreaterThanOrEquals, expressions.Operator);
 }
Exemplo n.º 45
0
 public LongCondition(String expr, JPath fld, ConditionType type, String rawValue)
     : base(expr, fld, type, rawValue)
 {
     testValue = Invariant.ToInt64(rawValue);
 }
 public Difference(DifferenceKind kind, JPath path, object actual, object expected)
     : this(kind, path)
 {
     Actual   = actual;
     Expected = expected;
 }