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); }
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]); }
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]); }
public void IndexerOnly() { JPath path = new JPath("[111119990]"); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual(111119990, ((ArrayIndexFilter)path.Filters[0]).Index); }
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); }
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); }
public void FilterWithNegativeInteger() { JPath path = new JPath("[?(@.name>=-12)]"); BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression; Assert.AreEqual(-12, (int)expressions.Value); }
public DoubleCondition(String expr, JPath fld, ConditionType type, String rawValue) : base(expr, fld, type, rawValue) { testValue = Invariant.ToDouble(rawValue); }
public void SinglePropertyWithRootWithStartAndEndWhitespace() { JPath path = new JPath(" $.Blah "); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name); }
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); }
public KeyAndType(JPath k, CompareType t) { Key = k; Type = t; }
public Comparer1Base(KeyAndType keyAndType) { this.path = keyAndType.Key; this.reverse = (keyAndType.Type & CompareType.Descending) != 0; }
public KeySource_JsonExpr(String input, String expr) : base(input) { this.expr = new JPath(expr); }
public UndupCountAction(IPostProcessor processor, XmlNode node) { toField = new JPath(node.ReadStr("@tofield")); }
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]); }
public KeyAndType(String k, CompareType t) { Key = new JPath(k); Type = t; }
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); }
public KeyAndType(XmlNode node) { Key = new JPath(node.ReadStr("@expr")); Type = node.ReadEnum <CompareType>("@type"); }
public void SingleQuotedPropertyWithDots() { JPath path = new JPath("['Blah.Ha']"); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual("Blah.Ha", ((FieldFilter)path.Filters[0]).Name); }
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); }
public NullOrEmptyCondition(String expr, JPath fld, ConditionType type, String rawValue) : base(expr, fld, type, rawValue) { CheckOnlyEQ(); }
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; }
public void SingleScanWithRoot() { JPath path = new JPath("$..Blah"); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual("Blah", ((ScanFilter)path.Filters[0]).Name); }
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); }
public void WildcardScanWithRootWithWhitespace() { JPath path = new JPath("$..* "); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual(null, ((ScanFilter)path.Filters[0]).Name); }
public void SingleProperty() { JPath path = new JPath("Blah"); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual("Blah", ((FieldFilter)path.Filters[0]).Name); }
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); }
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); }
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); }
public void IndexerOnlyWithWhitespace() { JPath path = new JPath("[ 10 ]"); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual(10, ((ArrayIndexFilter)path.Filters[0]).Index); }
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); }
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]); }
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); }
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); }
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); }
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); }
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); }
public void SingleQuotedPropertyWithBrackets() { JPath path = new JPath("['[*]']"); Assert.AreEqual(1, path.Filters.Count); Assert.AreEqual("[*]", ((FieldFilter)path.Filters[0]).Name); }
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); }
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)); } }
public void FilterWithLessThan() { JPath path = new JPath("[?(@.name<null)]"); BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression; Assert.AreEqual(QueryOperator.LessThan, expressions.Operator); }
public SubStringCondition(String expr, JPath fld, ConditionType type, String rawValue) : base(expr, fld, type, rawValue) { }
public void FilterWithGreaterThanOrEquals() { JPath path = new JPath("[?(@.name>=null)]"); BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression; Assert.AreEqual(QueryOperator.GreaterThanOrEquals, expressions.Operator); }
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; }