Closed pn closed 5 years ago
When using custom operations integers are cast to double (does not happen for longs). Is this expected behavior? I expected Int.
Here's a test in kotlin:
@Test fun operationParamType() { jsonLogic.addOperation("withLong") { assert(it[0] is Long) } jsonLogic.addOperation("withDouble") { assert(it[0] is Double) } jsonLogic.addOperation("withFloat") { assert(it[0] is Float) } jsonLogic.addOperation("withInt") { assert(it[0] is Int) // this fails because argument is Double } jsonLogic.apply("""{"withLong": [{"var": "a"}]}""", mapOf("a" to 1L)) jsonLogic.apply("""{"withDouble": [{"var": "a"}]}""", mapOf("a" to 1.0)) jsonLogic.apply("""{"withFloat": [{"var": "a"}]}""", mapOf("a" to 1.0f)) jsonLogic.apply("""{"withInt": [{"var": "a"}]}""", mapOf("a" to 1)) // fails }
Good question - there are two answers:
withDouble
@pn I'll leave that PR up for a few days for your review.
PR #13 LGTM
When using custom operations integers are cast to double (does not happen for longs). Is this expected behavior? I expected Int.
Here's a test in kotlin: