2
0

reply.tcl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. set testmodule [file normalize tests/modules/reply.so]
  2. start_server {tags {"modules"}} {
  3. r module load $testmodule
  4. # test all with hello 2/3
  5. for {set proto 2} {$proto <= 3} {incr proto} {
  6. r hello $proto
  7. test "RESP$proto: RM_ReplyWithString: an string reply" {
  8. # RedisString
  9. set string [r rw.string "Redis"]
  10. assert_equal "Redis" $string
  11. # C string
  12. set string [r rw.cstring]
  13. assert_equal "A simple string" $string
  14. }
  15. test "RESP$proto: RM_ReplyWithBigNumber: an string reply" {
  16. assert_equal "123456778901234567890" [r rw.bignumber "123456778901234567890"]
  17. }
  18. test "RESP$proto: RM_ReplyWithInt: an integer reply" {
  19. assert_equal 42 [r rw.int 42]
  20. }
  21. test "RESP$proto: RM_ReplyWithDouble: a float reply" {
  22. assert_equal 3.141 [r rw.double 3.141]
  23. }
  24. set ld 0.00000000000000001
  25. test "RESP$proto: RM_ReplyWithLongDouble: a float reply" {
  26. if {$proto == 2} {
  27. # here the response gets to TCL as a string
  28. assert_equal $ld [r rw.longdouble $ld]
  29. } else {
  30. # TCL doesn't support long double and the test infra converts it to a
  31. # normal double which causes precision loss. so we use readraw instead
  32. r readraw 1
  33. assert_equal ",$ld" [r rw.longdouble $ld]
  34. r readraw 0
  35. }
  36. }
  37. test "RESP$proto: RM_ReplyWithVerbatimString: a string reply" {
  38. assert_equal "bla\nbla\nbla" [r rw.verbatim "bla\nbla\nbla"]
  39. }
  40. test "RESP$proto: RM_ReplyWithArray: an array reply" {
  41. assert_equal {0 1 2 3 4} [r rw.array 5]
  42. }
  43. test "RESP$proto: RM_ReplyWithMap: an map reply" {
  44. set res [r rw.map 3]
  45. if {$proto == 2} {
  46. assert_equal {0 0 1 1.5 2 3} $res
  47. } else {
  48. assert_equal [dict create 0 0.0 1 1.5 2 3.0] $res
  49. }
  50. }
  51. test "RESP$proto: RM_ReplyWithSet: an set reply" {
  52. assert_equal {0 1 2} [r rw.set 3]
  53. }
  54. test "RESP$proto: RM_ReplyWithAttribute: an set reply" {
  55. if {$proto == 2} {
  56. catch {[r rw.attribute 3]} e
  57. assert_match "Attributes aren't supported by RESP 2" $e
  58. } else {
  59. r readraw 1
  60. set res [r rw.attribute 3]
  61. assert_equal [r read] {:0}
  62. assert_equal [r read] {,0}
  63. assert_equal [r read] {:1}
  64. assert_equal [r read] {,1.5}
  65. assert_equal [r read] {:2}
  66. assert_equal [r read] {,3}
  67. assert_equal [r read] {+OK}
  68. r readraw 0
  69. }
  70. }
  71. test "RESP$proto: RM_ReplyWithBool: a boolean reply" {
  72. assert_equal {0 1} [r rw.bool]
  73. }
  74. test "RESP$proto: RM_ReplyWithNull: a NULL reply" {
  75. assert_equal {} [r rw.null]
  76. }
  77. test "RESP$proto: RM_ReplyWithError: an error reply" {
  78. catch {r rw.error} e
  79. assert_match "An error" $e
  80. }
  81. }
  82. }