-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/30 feature test with jsonpath compliance test suite (#35)
- This project pulls the cts.json directly from the Compliance Test Suite - Improved handling of whitespace - Validation of non-singular queries and constants - Added support for I-Regexp format (RFC-9485). - Improved filter expression parsing - Switched to using an internal type system for comparing values - Memory and performance improvements --------- Co-authored-by: Brenton Farmer <[email protected]>
- Loading branch information
1 parent
4d192af
commit 6f56d32
Showing
80 changed files
with
25,858 additions
and
1,707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 14 additions & 11 deletions
25
src/Hyperbee.Json/Descriptors/Element/Functions/CountElementFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
|
||
using Hyperbee.Json.Filters.Parser; | ||
using Hyperbee.Json.Filters.Values; | ||
|
||
namespace Hyperbee.Json.Descriptors.Element.Functions; | ||
|
||
public class CountElementFunction() : FilterExtensionFunction( argumentCount: 1 ) | ||
public class CountElementFunction() : FilterExtensionFunction( CountMethodInfo, FilterExtensionInfo.MustCompare ) | ||
{ | ||
public const string Name = "count"; | ||
private static readonly Expression CountExpression = Expression.Constant( (Func<IEnumerable<JsonElement>, float>) Count ); | ||
|
||
protected override Expression GetExtensionExpression( Expression[] arguments ) | ||
{ | ||
return Expression.Invoke( CountExpression, arguments[0] ); | ||
} | ||
private static readonly MethodInfo CountMethodInfo = GetMethod<CountElementFunction>( nameof( Count ) ); | ||
|
||
public static float Count( IEnumerable<JsonElement> elements ) | ||
public static INodeType Count( INodeType input ) | ||
{ | ||
return elements.Count(); | ||
switch ( input ) | ||
{ | ||
case NodesType<JsonElement> nodes: | ||
if ( nodes.IsNormalized && !nodes.Any() ) | ||
return new ValueType<float>( 1F ); | ||
return new ValueType<float>( nodes.Count() ); | ||
default: | ||
return new ValueType<float>( 1F ); | ||
} | ||
} | ||
} |
Oops, something went wrong.