Previously a CPPredicate created with format `value == nil` was converted back to `value == <CPNull @ xxxx>`
This patch ensures `predicateFormat` returns `value == nil`
Test added in CPPredicateTest.j
Also added methods and documentation for the new methods:
-trueExpression, -falseExpression and -expressionBlock.
Completed documentation for -predicate and -arguments.
Conditional Expression : an expression using different expressions for
evaluation, depending of a predicate result.
Support for predicate parsing: ```TERNARY(predicate, trueExpression,
falseExpression)```
With init, equal, evaluation, parsing tests.
When the predicate part of a subquery expression was containing
variables, the substitution was ignored.
Now, the subpredicate can contain variables that will be substituted
when calling evaluateWithObject:substitutionVariables:.
Added expression test and predicate parsing test.
When parsing a predicate format that contains a constant boolean expression
(e.g., 'key = YES') the value of the returned constant value expression has
the wrong type. Instead of using native types as values, the parser uses
[CPNumber +numberWithBool:].
This commit changes the format parser (CPPredicateScanner) to use native
booleans for constant value expression.
There's a test case that checks the parse result and an additional test
that ensures boolean expressions evaluate as expected with different kinds
of objects. The latter test passed before the fix but was added to ensure
compliance with Cocoa.
Commit df2be92 breaks CPComparisonPredicate if one side of the comparison is a property which returns a BOOL.
CPPredicateParser parses literal BOOLs (YES/NO) into 0/1 using CPNumber>>numberWithBool:. CPComparisonPredicate however does not cast a BOOL from a property using numberWithBool:. E.g.
[[YES,NO] filteredArrayUsingPredicate:[CPPredicate predicateWithFormat:'self = YES']]
used to return [true], now it returns [].
This fix addresses the issue by "typecasting" the lhs/rhs values to numbers using CPNumber>>numberWithBool: if they are of type boolean.
Fixes#2028
- Moved common CPArray/CPSet collection KVC operators to _CPCollectionKVCOperators.
- Implemented KVC operator dispatch using Objective-J.
- Fixed infinite loop with empty collection in @min, @max and @sum operators.
- Correctly return valueForUndefinedKey when necessary.
- valueForUndefinedKey reason uses raw description for consistency, class' overridden description may not helpful at all.
- Don't create a forwarder for @ operators with property paths.
- Fixed CPSet -valueForKeyPath to correctly deal with nil/undefined/empty values.
- Added tests for collection KVC operators.
- enumerator -nextObject should always compare against nil for clarity, correctness, and consistency.
- It turns out doxygen would not generate documentation for the first method in a file (or sometimes any methods at all) if there was no ivar block or an empty ivar block. Now a dummy __doxygen__ ivar is inserted in empty blocks to force correct behavior.
- Added a missing @endverbatim to CPExpression.j.
- Tweaked class documentation for CPPredicate.j.
Added a missing CPDate.j import in CPExpression_function that was causing an 'unknown variable CPDate' error in deploy builds.
Added documentation for +expressionForSubquery:...
Added licence headers with credits.
"($)path.($)variable"
"SUBQUERY(collection, $x,$x = 2)"
"sum:(arg1, ...)"
"FUNCTION(target, selector, arg1, ...)
"object[expression]"
"set UNION|INTERSECT|MINUS otherset"
Fixed a bug where CPExpression_set was evaluating to an expression instead of a set.
Replaced parsing exceptions with a generic function indicating where it failed.
Added missing getters in CPExpression.
Added a type: argument to FunctionExpression initializer used by subclasses to init super with their own type.
Fixed evaluation with bindings dictionary in CPExpression_variable. Allow values in bindings to be a constant or an expression (per cocoa).
Tests: added tests for subqueryExpressions, for variableExpression evaluation where the value in the bindings dictionary can be either a constant or another expression.
Parsing a simple variable expression works (e.g. '$x = 12'), parsing a variable in a combined path (e.g.
'$x.path = 12' won't yet.