Add test to cover NAN reply using a module (#11482)
Adding a test to cover the already existing behavior of NAN replies, to accompany the PR that adds them to the RESP3 spec: https://github.com/redis/redis-specifications/pull/10 This PR also covers Inf replies that are already in the spec, as well as RESP2 coverage.
This commit is contained in:
parent
4c54528f0f
commit
78dc292178
@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
#include "redismodule.h"
|
||||
#include <math.h>
|
||||
|
||||
int rw_string(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
if (argc != 2) return RedisModule_WrongArity(ctx);
|
||||
@ -27,12 +28,22 @@ int rw_int(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
return RedisModule_ReplyWithLongLong(ctx, integer);
|
||||
}
|
||||
|
||||
/* When one argument is given, it is returned as a double,
|
||||
* when two arguments are given, it returns a/b. */
|
||||
int rw_double(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
if (argc != 2) return RedisModule_WrongArity(ctx);
|
||||
if (argc==1)
|
||||
return RedisModule_ReplyWithDouble(ctx, NAN);
|
||||
|
||||
double dbl;
|
||||
if (argc != 2 && argc != 3) return RedisModule_WrongArity(ctx);
|
||||
|
||||
double dbl, dbl2;
|
||||
if (RedisModule_StringToDouble(argv[1], &dbl) != REDISMODULE_OK)
|
||||
return RedisModule_ReplyWithError(ctx, "Arg cannot be parsed as a double");
|
||||
if (argc == 3) {
|
||||
if (RedisModule_StringToDouble(argv[2], &dbl2) != REDISMODULE_OK)
|
||||
return RedisModule_ReplyWithError(ctx, "Arg cannot be parsed as a double");
|
||||
dbl /= dbl2;
|
||||
}
|
||||
|
||||
return RedisModule_ReplyWithDouble(ctx, dbl);
|
||||
}
|
||||
|
@ -28,6 +28,29 @@ start_server {tags {"modules"}} {
|
||||
assert_equal 3.141 [r rw.double 3.141]
|
||||
}
|
||||
|
||||
test "RESP$proto: RM_ReplyWithDouble: inf" {
|
||||
if {$proto == 2} {
|
||||
assert_equal "inf" [r rw.double inf]
|
||||
assert_equal "-inf" [r rw.double -inf]
|
||||
} else {
|
||||
assert_equal Inf [r rw.double inf]
|
||||
assert_equal -Inf [r rw.double -inf]
|
||||
}
|
||||
}
|
||||
|
||||
test "RESP$proto: RM_ReplyWithDouble: NaN" {
|
||||
if {$proto == 2} {
|
||||
assert_equal "-nan" [r rw.double 0 0]
|
||||
assert_equal "nan" [r rw.double]
|
||||
} else {
|
||||
# TCL won't convert nan into a double, use readraw to verify the protocol
|
||||
r readraw 1
|
||||
assert_equal ",-nan" [r rw.double 0 0]
|
||||
assert_equal ",nan" [r rw.double]
|
||||
r readraw 0
|
||||
}
|
||||
}
|
||||
|
||||
set ld 0.00000000000000001
|
||||
test "RESP$proto: RM_ReplyWithLongDouble: a float reply" {
|
||||
if {$proto == 2} {
|
||||
|
Loading…
x
Reference in New Issue
Block a user