X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/02a3e582582c381f14bc23aa9bed4b4645a2f118..5513397de7526f0e5e01c1d29a37813008703d6d:/tests/unit/basic.tcl diff --git a/tests/unit/basic.tcl b/tests/unit/basic.tcl index 86645e95..86498d1f 100644 --- a/tests/unit/basic.tcl +++ b/tests/unit/basic.tcl @@ -120,7 +120,19 @@ start_server {tags {"basic"}} { r incrby novar 17179869184 } {34359738368} - test {INCR fails against key with spaces (no integer encoded)} { + test {INCR fails against key with spaces (left)} { + r set novar " 11" + catch {r incr novar} err + format $err + } {ERR*} + + test {INCR fails against key with spaces (right)} { + r set novar "11 " + catch {r incr novar} err + format $err + } {ERR*} + + test {INCR fails against key with spaces (both)} { r set novar " 11 " catch {r incr novar} err format $err @@ -131,13 +143,81 @@ start_server {tags {"basic"}} { catch {r incr mylist} err r rpop mylist format $err - } {ERR*} + } {WRONGTYPE*} test {DECRBY over 32bit value with over 32bit increment, negative res} { r set novar 17179869184 r decrby novar 17179869185 } {-1} + test {INCRBYFLOAT against non existing key} { + r del novar + list [roundFloat [r incrbyfloat novar 1]] \ + [roundFloat [r get novar]] \ + [roundFloat [r incrbyfloat novar 0.25]] \ + [roundFloat [r get novar]] + } {1 1 1.25 1.25} + + test {INCRBYFLOAT against key originally set with SET} { + r set novar 1.5 + roundFloat [r incrbyfloat novar 1.5] + } {3} + + test {INCRBYFLOAT over 32bit value} { + r set novar 17179869184 + r incrbyfloat novar 1.5 + } {17179869185.5} + + test {INCRBYFLOAT over 32bit value with over 32bit increment} { + r set novar 17179869184 + r incrbyfloat novar 17179869184 + } {34359738368} + + test {INCRBYFLOAT fails against key with spaces (left)} { + set err {} + r set novar " 11" + catch {r incrbyfloat novar 1.0} err + format $err + } {ERR*valid*} + + test {INCRBYFLOAT fails against key with spaces (right)} { + set err {} + r set novar "11 " + catch {r incrbyfloat novar 1.0} err + format $err + } {ERR*valid*} + + test {INCRBYFLOAT fails against key with spaces (both)} { + set err {} + r set novar " 11 " + catch {r incrbyfloat novar 1.0} err + format $err + } {ERR*valid*} + + test {INCRBYFLOAT fails against a key holding a list} { + r del mylist + set err {} + r rpush mylist 1 + catch {r incrbyfloat mylist 1.0} err + r del mylist + format $err + } {WRONGTYPE*} + + test {INCRBYFLOAT does not allow NaN or Infinity} { + r set foo 0 + set err {} + catch {r incrbyfloat foo +inf} err + set err + # p.s. no way I can force NaN to test it from the API because + # there is no way to increment / decrement by infinity nor to + # perform divisions. + } {ERR*would produce*} + + test {INCRBYFLOAT decrement} { + r set foo 1 + roundFloat [r incrbyfloat foo -1.1] + } {-0.1} + test "SETNX target key missing" { r del novar assert_equal 1 [r setnx novar foobared] @@ -451,7 +531,7 @@ start_server {tags {"basic"}} { test "SETBIT against key with wrong type" { r del mykey r lpush mykey "foo" - assert_error "*wrong kind*" {r setbit mykey 0 1} + assert_error "WRONGTYPE*" {r setbit mykey 0 1} } test "SETBIT with out of range bit offset" { @@ -585,7 +665,7 @@ start_server {tags {"basic"}} { test "SETRANGE against key with wrong type" { r del mykey r lpush mykey "foo" - assert_error "*wrong kind*" {r setrange mykey 0 bar} + assert_error "WRONGTYPE*" {r setrange mykey 0 bar} } test "SETRANGE with out of range offset" {