<commit_before>package.path = "..\\src\\lua\\?.lua;" .. package.path

pcall(require, "luacov")

local RedisStream    = require "lluv.redis.stream"
local RedisCommander = require "lluv.redis.commander"
local utils          = require "utils"
local TEST_CASE      = require "lunit".TEST_CASE

local pcall, error, type, table, ipairs, print = pcall, error, type, table, ipairs, print
local RUN = utils.RUN
local IT, CMD, PASS = utils.IT, utils.CMD, utils.PASS
local nreturn, is_equal = utils.nreturn, utils.is_equal

local C = function(t) return table.concat(t, '\r\n') .. '\r\n' end
local S = function(s) return C{"$" .. #s, s} end
local I = function(i) return C{":" .. tostring(i)} end
local A = function(a)
  local t = {"*" .. #a}
  for i, s in ipairs(a) do
    t[#t + 1] = "$" .. #s
    t[#t + 1] = s
  end
  return C(t)
end
local E = function(m) return C {"-" .. m} end

local ENABLE = true

local _ENV = TEST_CASE'redis command encoder/decoder' if ENABLE then

local it = IT(_ENV or _M)

local stream, command
local SELF = {}

function setup()
  stream  = assert(RedisStream.new(SELF))
  command = assert(RedisCommander.new(stream))
end

local test = {
  { "PING",
    function(cb) command:ping(cb) end;
    "PING\r\n",
    "+PONG\r\n",
    "PONG"
  };
  { "ECHO",
    function(cb) command:echo("HELLO", cb) end;
    A{"ECHO", "HELLO"},
    S"HELLO",
    "HELLO"
  };
  { "EXISTS true",
    function(cb) command:exists("key", cb) end;
    A{"EXISTS", "key"},
    C{":1"},
    true
  };
  { "EXISTS false",
    function(cb) command:exists("key", cb) end;
    C{"*2", "$6", "EXISTS", "$3", "key"},
    C{":0"},
    false
  };
  { "SET #1",
    function(cb) command:set("key", "value", cb) end;
    A{"SET", "key", "value"},
    C{"+OK"},
    "OK"
  };
  { "EVAL #1",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", "2", "key1", "key2", "first", "second", cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "2", "key1", "key2", "first", "second"
    },
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #2",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", "2", {"key1", "key2"}, {"first", "second"}, cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "2", "key1", "key2", "first", "second"
    },
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #4",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", {"key1", "key2"}, {"first", "second"}, cb) end;<commit_msg>Update test to eval/evalsha args<commit_after>package.path = "..\\src\\lua\\?.lua;" .. package.path

pcall(require, "luacov")

local RedisStream    = require "lluv.redis.stream"
local RedisCommander = require "lluv.redis.commander"
local utils          = require "utils"
local TEST_CASE      = require "lunit".TEST_CASE

local pcall, error, type, table, ipairs, print = pcall, error, type, table, ipairs, print
local RUN = utils.RUN
local IT, CMD, PASS = utils.IT, utils.CMD, utils.PASS
local nreturn, is_equal = utils.nreturn, utils.is_equal

local C = function(t) return table.concat(t, '\r\n') .. '\r\n' end
local S = function(s) return C{"$" .. #s, s} end
local I = function(i) return C{":" .. tostring(i)} end
local A = function(a)
  local t = {"*" .. #a}
  for i, s in ipairs(a) do
    t[#t + 1] = "$" .. #s
    t[#t + 1] = s
  end
  return C(t)
end
local E = function(m) return C {"-" .. m} end

local ENABLE = true

local _ENV = TEST_CASE'redis command encoder/decoder' if ENABLE then

local it = IT(_ENV or _M)

local stream, command
local SELF = {}

function setup()
  stream  = assert(RedisStream.new(SELF))
  command = assert(RedisCommander.new(stream))
end

local test = {
  { "PING",
    function(cb) command:ping(cb) end;
    "PING\r\n",
    "+PONG\r\n",
    "PONG"
  };
  { "ECHO",
    function(cb) command:echo("HELLO", cb) end;
    A{"ECHO", "HELLO"},
    S"HELLO",
    "HELLO"
  };
  { "EXISTS true",
    function(cb) command:exists("key", cb) end;
    A{"EXISTS", "key"},
    C{":1"},
    true
  };
  { "EXISTS false",
    function(cb) command:exists("key", cb) end;
    C{"*2", "$6", "EXISTS", "$3", "key"},
    C{":0"},
    false
  };
  { "SET #1",
    function(cb) command:set("key", "value", cb) end;
    A{"SET", "key", "value"},
    C{"+OK"},
    "OK"
  };
  { "EVAL #1",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", "2", "key1", "key2", "first", "second", cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "2", "key1", "key2", "first", "second"
    },
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #2",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", "2", {"key1", "key2"}, {"first", "second"}, cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "2", "key1", "key2", "first", "second"
    },
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #3.1",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", "0", {"first", "second"}, cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "0", "first", "second"
    },
    -- This is invalid response, but we test only request in this test case
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #3.2",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", {}, {"first", "second"}, cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "0", "first", "second"
    },
    -- This is invalid response, but we test only request in this test case
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #3.3",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", {"first", "second"}, cb) end;
    A{
      "EVAL",
      "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
      "2", "first", "second"
    },
    -- This is invalid response, but we test only request in this test case
    A{"key1", "key2", "first", "second"},
    {"key1", "key2", "first", "second", n=4}
  };
  { "EVAL #4",
    function(cb) command:eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", {"key1", "key2"}, {"first", "second"}, cb) end;
{'fraction_non_alphanumeric': 0.23632691112492232, 'fraction_numerical': 0.024704785581106278, 'mean_word_length': 3.3818924438393463, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2097293', 'n_tokens_mistral': 2659, 'n_tokens_neox': 2644, 'n_words': 624}