| 1 | package Protocol::Redis::Test; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | require Exporter; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT = qw(protocol_redis_ok); | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | require Carp; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | sub protocol_redis_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
protocol_redis_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 15 | 3 | my ($redis_class, $api_version) = @_; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | subtest 'Protocol::Redis tests' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 18 | 3 | plan tests => 3; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use_ok $redis_class; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 3 | _test_unknown_version($redis_class); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | if ($api_version == 1 or $api_version == 2) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$api_version == 1 or $api_version == 2
MC/DC100%2/2
$api_version == 1 or $api_version == 2
$api_version == 1
$api_version == 2
Truth table100%3/3
A or B
A= $api_version == 1B= $api_version == 2
| |||||||||||||||||||||||||||||||||
| 25 | 2 | _apiv1_ok($redis_class); | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | elsif ($api_version == 3) { | ||||||||||||||||||||||||||||||||
| 28 | 1 | _apiv3_ok($redis_class); | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||||||
| 31 | 0 | Carp::croak(qq/Unknown Protocol::Redis API version $api_version/); | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | 3 | }; | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | sub _apiv1_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_apiv1_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 37 | 2 | my $redis_class = shift; | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | subtest 'Protocol::Redis APIv1 ok' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 40 | 2 | plan tests => 45; | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 2 | _test_version_1($redis_class); | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | 2 | } | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | sub _apiv3_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_apiv3_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 47 | 1 | my $redis_class = shift; | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | subtest 'Protocol::Redis APIv3 ok' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 50 | 1 | plan tests => 151; | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 1 | _test_version_3($redis_class); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | 1 | } | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | sub _test_version_1 { | ||||||||||||||||||||||||||||||
|
Subroutine
_test_version_1: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 57 | 2 | my $redis_class = shift; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 2 | my $redis = new_ok $redis_class, [api => 1]; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 2 | can_ok $redis, 'parse', 'api', 'on_message', 'encode'; | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 2 | is $redis->api, 1, '$redis->api'; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | # Parsing method tests | ||||||||||||||||||||||||||||||||
| 66 | 2 | $redis->on_message(undef); | |||||||||||||||||||||||||||||||
| 67 | 2 | _parse_string_ok($redis); | |||||||||||||||||||||||||||||||
| 68 | 2 | _parse_blob_ok($redis); | |||||||||||||||||||||||||||||||
| 69 | 2 | _parse_array_ok($redis); | |||||||||||||||||||||||||||||||
| 70 | 2 | _parse_null_bulk_ok($redis); | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | # on_message works | ||||||||||||||||||||||||||||||||
| 73 | 2 | _on_message_ok($redis); | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | # Encoding method tests | ||||||||||||||||||||||||||||||||
| 76 | 2 | _encode_ok($redis); | |||||||||||||||||||||||||||||||
| 77 | 2 | _encode_v1_ok($redis); | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub _test_version_3 { | ||||||||||||||||||||||||||||||
|
Subroutine
_test_version_3: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 81 | 1 | my $redis_class = shift; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 1 | my $redis = new_ok $redis_class, [api => 3]; | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 1 | can_ok $redis, 'parse', 'api', 'on_message', 'encode'; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 1 | is $redis->api, 3, '$redis->api'; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | # Parsing method tests | ||||||||||||||||||||||||||||||||
| 90 | 1 | $redis->on_message(undef); | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | # simple string, error string, number | ||||||||||||||||||||||||||||||||
| 93 | 1 | _parse_string_ok($redis); | |||||||||||||||||||||||||||||||
| 94 | 1 | _parse_null_ok($redis); | |||||||||||||||||||||||||||||||
| 95 | 1 | _parse_boolean_ok($redis); | |||||||||||||||||||||||||||||||
| 96 | 1 | _parse_double_ok($redis); | |||||||||||||||||||||||||||||||
| 97 | 1 | _parse_big_number_ok($redis); | |||||||||||||||||||||||||||||||
| 98 | 1 | _parse_blob_ok($redis, '$'); # blob string | |||||||||||||||||||||||||||||||
| 99 | 1 | _parse_blob_ok($redis, '!'); # blob error | |||||||||||||||||||||||||||||||
| 100 | 1 | _parse_verbatim_ok($redis); # verbatim string | |||||||||||||||||||||||||||||||
| 101 | 1 | _parse_array_ok($redis, '*'); # array | |||||||||||||||||||||||||||||||
| 102 | 1 | _parse_array_ok($redis, '~'); # set | |||||||||||||||||||||||||||||||
| 103 | 1 | _parse_array_ok($redis, '>'); # push | |||||||||||||||||||||||||||||||
| 104 | 1 | _parse_map_ok($redis); | |||||||||||||||||||||||||||||||
| 105 | 1 | _parse_attribute_ok($redis); | |||||||||||||||||||||||||||||||
| 106 | 1 | _parse_streamed_string_ok($redis); | |||||||||||||||||||||||||||||||
| 107 | 1 | _parse_streamed_aggregate_ok($redis); | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | # on_message works | ||||||||||||||||||||||||||||||||
| 110 | 1 | _on_message_ok($redis); | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | # Encoding method tests | ||||||||||||||||||||||||||||||||
| 113 | 1 | _encode_ok($redis); | |||||||||||||||||||||||||||||||
| 114 | 1 | _encode_v3_ok($redis); | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | sub _parse_string_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_string_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 118 | 3 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | # Simple test | ||||||||||||||||||||||||||||||||
| 121 | 3 | $redis->parse("+test\r\n"); | |||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 3 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 124 | {type => '+', data => 'test'}, | ||||||||||||||||||||||||||||||||
| 125 | 'simple message'; | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 3 | is_deeply $redis->get_message, undef, 'queue is empty'; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 3 | $redis->parse(":1\r\n"); | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 3 | is_deeply $redis->get_message, {type => ':', data => '1'}, | |||||||||||||||||||||||||||||||
| 132 | 'simple number'; | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | # Chunked message | ||||||||||||||||||||||||||||||||
| 135 | 3 | $redis->parse('-tes'); | |||||||||||||||||||||||||||||||
| 136 | 3 | $redis->parse("t2\r\n"); | |||||||||||||||||||||||||||||||
| 137 | 3 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 138 | {type => '-', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 139 | 'chunked string'; | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | # Two chunked messages together | ||||||||||||||||||||||||||||||||
| 142 | 3 | $redis->parse("+test"); | |||||||||||||||||||||||||||||||
| 143 | 3 | $redis->parse("1\r\n-test"); | |||||||||||||||||||||||||||||||
| 144 | 3 | $redis->parse("2\r\n"); | |||||||||||||||||||||||||||||||
| 145 | 3 | is_deeply | |||||||||||||||||||||||||||||||
| 146 | [$redis->get_message, $redis->get_message], | ||||||||||||||||||||||||||||||||
| 147 | [{type => '+', data => 'test1'}, {type => '-', data => 'test2'}], | ||||||||||||||||||||||||||||||||
| 148 | 'first stick message'; | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | # Pipelined | ||||||||||||||||||||||||||||||||
| 151 | 3 | $redis->parse("+OK\r\n-ERROR\r\n"); | |||||||||||||||||||||||||||||||
| 152 | 3 | is_deeply | |||||||||||||||||||||||||||||||
| 153 | [$redis->get_message, $redis->get_message], | ||||||||||||||||||||||||||||||||
| 154 | [{type => '+', data => 'OK'}, {type => '-', data => 'ERROR'}], | ||||||||||||||||||||||||||||||||
| 155 | 'pipelined status messages'; | ||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 4 | ▶ | sub _parse_blob_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_blob_ok: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 159 | 4 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | my $type = shift || '$'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || '$'
MC/DC100%1/1
shift() || '$'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | # Bulk message | ||||||||||||||||||||||||||||||||
| 163 | 4 | $redis->parse("${type}4\r\ntest\r\n"); | |||||||||||||||||||||||||||||||
| 164 | 4 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 165 | {type => $type, data => 'test'}, | ||||||||||||||||||||||||||||||||
| 166 | "simple $type blob message"; | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 4 | $redis->parse("${type}5\r\ntes"); | |||||||||||||||||||||||||||||||
| 169 | 4 | $redis->parse("t2\r\n"); | |||||||||||||||||||||||||||||||
| 170 | 4 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 171 | {type => $type, data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 172 | "chunked $type blob message"; | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | # Two chunked bulk messages | ||||||||||||||||||||||||||||||||
| 175 | 4 | $redis->parse(join("\r\n", "${type}4", 'test', '+OK')); | |||||||||||||||||||||||||||||||
| 176 | 4 | $redis->parse("\r\n"); | |||||||||||||||||||||||||||||||
| 177 | 4 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 178 | {type => $type, data => 'test'}, "two chunked $type blob messages"; | ||||||||||||||||||||||||||||||||
| 179 | 4 | is_deeply $redis->get_message, {type => '+', data => 'OK'}; | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | # Pipelined bulk message | ||||||||||||||||||||||||||||||||
| 182 | 4 | $redis->parse(join("\r\n", ("${type}3", 'ok1'), ("${type}3", 'ok2'), '')); | |||||||||||||||||||||||||||||||
| 183 | 4 | is_deeply [$redis->get_message, $redis->get_message], | |||||||||||||||||||||||||||||||
| 184 | [{type => $type, data => 'ok1'}, {type => $type, data => 'ok2'}], | ||||||||||||||||||||||||||||||||
| 185 | "pipelined $type blob message"; | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | # Binary test | ||||||||||||||||||||||||||||||||
| 188 | 4 | $redis->parse(join("\r\n", "${type}4", pack('C4', 0, 1, 2, 3), '')); | |||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 4 | is_deeply [unpack('C4', $redis->get_message->{data})], | |||||||||||||||||||||||||||||||
| 191 | [0, 1, 2, 3], | ||||||||||||||||||||||||||||||||
| 192 | 'binary data'; | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | # Blob message with newlines | ||||||||||||||||||||||||||||||||
| 195 | 4 | $redis->parse("${type}8\r\none\r\ntwo\r\n"); | |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 4 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 198 | {type => $type, data => "one\r\ntwo"}, | ||||||||||||||||||||||||||||||||
| 199 | "$type blob message with newlines"; | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | # Empty blob message | ||||||||||||||||||||||||||||||||
| 202 | 4 | $redis->parse("${type}0\r\n\r\n"); | |||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | 4 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 205 | {type => $type, data => ''}, | ||||||||||||||||||||||||||||||||
| 206 | "$type empty blob message"; | ||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | sub _parse_verbatim_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_verbatim_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 210 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | # Verbatim message | ||||||||||||||||||||||||||||||||
| 213 | 1 | $redis->parse("=8\r\ntxt:test\r\n"); | |||||||||||||||||||||||||||||||
| 214 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 215 | {type => '=', data => 'test', format => 'txt'}, | ||||||||||||||||||||||||||||||||
| 216 | "simple verbatim string message"; | ||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | 1 | $redis->parse("=9\r\ntxt:tes"); | |||||||||||||||||||||||||||||||
| 219 | 1 | $redis->parse("t2\r\n"); | |||||||||||||||||||||||||||||||
| 220 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 221 | {type => '=', data => 'test2', format => 'txt'}, | ||||||||||||||||||||||||||||||||
| 222 | "chunked verbatim string message"; | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | # Two chunked verbatim messages | ||||||||||||||||||||||||||||||||
| 225 | 1 | $redis->parse(join("\r\n", '=8', 'txt:test', '=6', 'mkd:OK')); | |||||||||||||||||||||||||||||||
| 226 | 1 | $redis->parse("\r\n"); | |||||||||||||||||||||||||||||||
| 227 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 228 | {type => '=', data => 'test', format => 'txt'}, | ||||||||||||||||||||||||||||||||
| 229 | "two chunked verbatim string messages"; | ||||||||||||||||||||||||||||||||
| 230 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 231 | {type => '=', data => 'OK', format => 'mkd'}; | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | # Pipelined verbatim message | ||||||||||||||||||||||||||||||||
| 234 | 1 | $redis->parse(join("\r\n", ('=7', 'txt:ok1'), ('=7', 'txt:ok2'), '')); | |||||||||||||||||||||||||||||||
| 235 | 1 | is_deeply [$redis->get_message, $redis->get_message], [ | |||||||||||||||||||||||||||||||
| 236 | {type => '=', data => 'ok1', format => 'txt'}, | ||||||||||||||||||||||||||||||||
| 237 | {type => '=', data => 'ok2', format => 'txt'} | ||||||||||||||||||||||||||||||||
| 238 | ], | ||||||||||||||||||||||||||||||||
| 239 | "pipelined verbatim string message"; | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | # Binary test | ||||||||||||||||||||||||||||||||
| 242 | 1 | $redis->parse(join("\r\n", '=8', 'txt:' . pack('C4', 0, 1, 2, 3), '')); | |||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 1 | is_deeply [unpack('C4', $redis->get_message->{data})], | |||||||||||||||||||||||||||||||
| 245 | [0, 1, 2, 3], | ||||||||||||||||||||||||||||||||
| 246 | 'binary data'; | ||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | # Blob message with newlines | ||||||||||||||||||||||||||||||||
| 249 | 1 | $redis->parse("=12\r\ntxt:one\r\ntwo\r\n"); | |||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 252 | {type => '=', data => "one\r\ntwo", format => 'txt'}, | ||||||||||||||||||||||||||||||||
| 253 | "verbatim string message with newlines"; | ||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | # Empty blob message | ||||||||||||||||||||||||||||||||
| 256 | 1 | $redis->parse("=4\r\ntxt:\r\n"); | |||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 259 | {type => '=', data => '', format => 'txt'}, | ||||||||||||||||||||||||||||||||
| 260 | "empty verbatim string message"; | ||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | 5 | ▶ | sub _parse_array_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_array_ok: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 264 | 5 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 265 | 5 | ▶ | my $type = shift || '*'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || '*'
MC/DC100%1/1
shift() || '*'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | # Array message | ||||||||||||||||||||||||||||||||
| 268 | 5 | $redis->parse("${type}1\r\n\$4\r\ntest\r\n"); | |||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 5 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 271 | {type => $type, data => [{type => '$', data => 'test'}]}, | ||||||||||||||||||||||||||||||||
| 272 | "simple $type array message"; | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | # Array message with multiple arguments | ||||||||||||||||||||||||||||||||
| 275 | 5 | $redis->parse("${type}3\r\n\$5\r\ntest1\r\n"); | |||||||||||||||||||||||||||||||
| 276 | 5 | $redis->parse("\$5\r\ntest2\r\n"); | |||||||||||||||||||||||||||||||
| 277 | 5 | $redis->parse("\$5\r\ntest3\r\n"); | |||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 280 | type => $type, | ||||||||||||||||||||||||||||||||
| 281 | data => [ | ||||||||||||||||||||||||||||||||
| 282 | {type => '$', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 283 | {type => '$', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 284 | {type => '$', data => 'test3'} | ||||||||||||||||||||||||||||||||
| 285 | ] | ||||||||||||||||||||||||||||||||
| 286 | }, | ||||||||||||||||||||||||||||||||
| 287 | "multi argument $type array message"; | ||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | # Nested array | ||||||||||||||||||||||||||||||||
| 290 | 5 | $redis->parse("${type}2\r\n${type}2\r\n+test1\r\n+test2\r\n+test3\r\n"); | |||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 293 | type => $type, | ||||||||||||||||||||||||||||||||
| 294 | data => [{ | ||||||||||||||||||||||||||||||||
| 295 | type => $type, | ||||||||||||||||||||||||||||||||
| 296 | data => [ | ||||||||||||||||||||||||||||||||
| 297 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 298 | {type => '+', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 299 | ] | ||||||||||||||||||||||||||||||||
| 300 | }, | ||||||||||||||||||||||||||||||||
| 301 | {type => '+', data => 'test3'}, | ||||||||||||||||||||||||||||||||
| 302 | ] | ||||||||||||||||||||||||||||||||
| 303 | }, | ||||||||||||||||||||||||||||||||
| 304 | "nested $type array message"; | ||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 5 | $redis->parse("${type}0\r\n"); | |||||||||||||||||||||||||||||||
| 307 | 5 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 308 | {type => $type, data => []}, | ||||||||||||||||||||||||||||||||
| 309 | "$type array empty result"; | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | # Does it work? | ||||||||||||||||||||||||||||||||
| 312 | 5 | $redis->parse("\$4\r\ntest\r\n"); | |||||||||||||||||||||||||||||||
| 313 | 5 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 314 | {type => '$', data => 'test'}, | ||||||||||||||||||||||||||||||||
| 315 | 'everything still works'; | ||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | # Array message with status items | ||||||||||||||||||||||||||||||||
| 318 | 5 | $redis->parse(join("\r\n", ("${type}2", '+OK', '$4', 'test'), '')); | |||||||||||||||||||||||||||||||
| 319 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 320 | type => $type, | ||||||||||||||||||||||||||||||||
| 321 | data => [{type => '+', data => 'OK'}, {type => '$', data => 'test'}] | ||||||||||||||||||||||||||||||||
| 322 | }; | ||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | # splitted array | ||||||||||||||||||||||||||||||||
| 325 | 5 | $redis->parse(join("\r\n", ("${type}1", '$4', 'test'), '+OK')); | |||||||||||||||||||||||||||||||
| 326 | 5 | $redis->parse("\r\n"); | |||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | 5 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 329 | {type => $type, data => [{type => '$', data => 'test'}]}; | ||||||||||||||||||||||||||||||||
| 330 | 5 | is_deeply $redis->get_message, {type => '+', data => 'OK'}; | |||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||
| 332 | # Another splitted array message | ||||||||||||||||||||||||||||||||
| 333 | 5 | $redis->parse("${type}4\r\n\$0\r\n\r\n\$0\r\n"); | |||||||||||||||||||||||||||||||
| 334 | 5 | $redis->parse("\r\n\$5\r\ntest2\r\n"); | |||||||||||||||||||||||||||||||
| 335 | 5 | $redis->parse("\$5\r\ntest3\r"); | |||||||||||||||||||||||||||||||
| 336 | 5 | $redis->parse("\n"); | |||||||||||||||||||||||||||||||
| 337 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 338 | type => $type, | ||||||||||||||||||||||||||||||||
| 339 | data => [ | ||||||||||||||||||||||||||||||||
| 340 | {type => '$', data => ''}, | ||||||||||||||||||||||||||||||||
| 341 | {type => '$', data => ''}, | ||||||||||||||||||||||||||||||||
| 342 | {type => '$', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 343 | {type => '$', data => 'test3'} | ||||||||||||||||||||||||||||||||
| 344 | ] | ||||||||||||||||||||||||||||||||
| 345 | }; | ||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | # Complex string | ||||||||||||||||||||||||||||||||
| 348 | 5 | $redis->parse("${type}4\r\n"); | |||||||||||||||||||||||||||||||
| 349 | 5 | $redis->parse("\$5\r\ntest1\r\n\$0\r\n\r\n:42\r\n+test3\r\n\$5\r\n123"); | |||||||||||||||||||||||||||||||
| 350 | 5 | $redis->parse("45\r\n"); | |||||||||||||||||||||||||||||||
| 351 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 352 | type => $type, | ||||||||||||||||||||||||||||||||
| 353 | data => [ | ||||||||||||||||||||||||||||||||
| 354 | {type => '$', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 355 | {type => '$', data => ''}, | ||||||||||||||||||||||||||||||||
| 356 | {type => ':', data => 42}, | ||||||||||||||||||||||||||||||||
| 357 | {type => '+', data => 'test3'} | ||||||||||||||||||||||||||||||||
| 358 | ] | ||||||||||||||||||||||||||||||||
| 359 | }; | ||||||||||||||||||||||||||||||||
| 360 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 361 | type => '$', | ||||||||||||||||||||||||||||||||
| 362 | data => '12345', | ||||||||||||||||||||||||||||||||
| 363 | }; | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | # pipelined array | ||||||||||||||||||||||||||||||||
| 366 | 5 | $redis->parse( | |||||||||||||||||||||||||||||||
| 367 | join("\r\n", | ||||||||||||||||||||||||||||||||
| 368 | ("${type}2", '$3', 'ok1', '$3', 'ok2'), | ||||||||||||||||||||||||||||||||
| 369 | ("${type}1", '$3', 'ok3'), | ||||||||||||||||||||||||||||||||
| 370 | '') | ||||||||||||||||||||||||||||||||
| 371 | ); | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | 5 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 374 | type => $type, | ||||||||||||||||||||||||||||||||
| 375 | data => [{type => '$', data => 'ok1'}, {type => '$', data => 'ok2'}] | ||||||||||||||||||||||||||||||||
| 376 | }; | ||||||||||||||||||||||||||||||||
| 377 | 5 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 378 | {type => $type, data => [{type => '$', data => 'ok3'}]}; | ||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | 2 | ▶ | sub _parse_null_bulk_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_null_bulk_ok: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||
| 382 | 2 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||
| 384 | # Nil bulk message | ||||||||||||||||||||||||||||||||
| 385 | 2 | $redis->parse("\$-1\r\n"); | |||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | 2 | my $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 388 | 2 | ▶ | ok defined($message) && !defined($message->{data}), 'nil bulk message'; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $message && !defined($message->{'data'})
MC/DC0%0/2
defined $message && !defined($message->{'data'})
defined $message
!defined($message->{'data'})
Truth table33%1/3
A && not(B)
A= defined $messageB= !defined($message->{'data'})
| |||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | 2 | $redis->parse("*-1\r\n"); | |||||||||||||||||||||||||||||||
| 391 | 2 | $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 392 | 2 | ▶ | ok defined($message) && !defined($message->{data}), | ||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $message && !defined($message->{'data'})
MC/DC0%0/2
defined $message && !defined($message->{'data'})
defined $message
!defined($message->{'data'})
Truth table33%1/3
A && not(B)
A= defined $messageB= !defined($message->{'data'})
| |||||||||||||||||||||||||||||||||
| 393 | 'multi-bulk nil result'; | ||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 1 | ▶ | sub _parse_null_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_null_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 397 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | # Null message | ||||||||||||||||||||||||||||||||
| 400 | 1 | $redis->parse("_\r\n"); | |||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 403 | {type => '_', data => undef}, | ||||||||||||||||||||||||||||||||
| 404 | 'null message'; | ||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | sub _parse_boolean_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_boolean_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 408 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | # Boolean true message | ||||||||||||||||||||||||||||||||
| 411 | 1 | $redis->parse("#t\r\n"); | |||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 414 | {type => '#', data => !!1}, | ||||||||||||||||||||||||||||||||
| 415 | 'boolean true message'; | ||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||
| 417 | # Boolean false message | ||||||||||||||||||||||||||||||||
| 418 | 1 | $redis->parse("#f\r\n"); | |||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 421 | {type => '#', data => !!0}, | ||||||||||||||||||||||||||||||||
| 422 | 'boolean false message'; | ||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | 1 | ▶ | sub _parse_double_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_double_ok: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 426 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | # Double message | ||||||||||||||||||||||||||||||||
| 429 | 1 | $redis->parse(",1.23\r\n"); | |||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 432 | {type => ',', data => '1.23'}, | ||||||||||||||||||||||||||||||||
| 433 | 'double message'; | ||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||
| 435 | # Integer double message | ||||||||||||||||||||||||||||||||
| 436 | 1 | $redis->parse(",42\r\n"); | |||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||
| 438 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 439 | {type => ',', data => '42'}, | ||||||||||||||||||||||||||||||||
| 440 | 'integer double message'; | ||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||
| 442 | # Exponent double messages | ||||||||||||||||||||||||||||||||
| 443 | 1 | foreach my $double (qw(1e3 1.23e4 -4.2E-20 0.01e+7)) { | |||||||||||||||||||||||||||||||
| 444 | 4 | $redis->parse(",$double\r\n"); | |||||||||||||||||||||||||||||||
| 445 | 4 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 446 | {type => ',', data => $double}, | ||||||||||||||||||||||||||||||||
| 447 | "received $double as double with exponent"; | ||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||
| 450 | # Infinity message | ||||||||||||||||||||||||||||||||
| 451 | 1 | $redis->parse(",inf\r\n"); | |||||||||||||||||||||||||||||||
| 452 | 1 | my $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 453 | 1 | is $message->{type}, ',', 'double message type'; | |||||||||||||||||||||||||||||||
| 454 | 1 | cmp_ok $message->{data}, '==', $message->{data} + 1, 'received infinity'; | |||||||||||||||||||||||||||||||
| 455 | 1 | cmp_ok $message->{data}, '>', 0, 'received positive infinity'; | |||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | # Negative infinity message | ||||||||||||||||||||||||||||||||
| 458 | 1 | $redis->parse(",-inf\r\n"); | |||||||||||||||||||||||||||||||
| 459 | 1 | $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 460 | 1 | is $message->{type}, ',', 'double message type'; | |||||||||||||||||||||||||||||||
| 461 | 1 | cmp_ok $message->{data}, '==', $message->{data} - 1, 'received infinity'; | |||||||||||||||||||||||||||||||
| 462 | 1 | cmp_ok $message->{data}, '<', 0, 'received negative infinity'; | |||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | # NaN message | ||||||||||||||||||||||||||||||||
| 465 | 1 | $redis->parse(",nan\r\n"); | |||||||||||||||||||||||||||||||
| 466 | 1 | $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 467 | 1 | is $message->{type}, ',', 'double message type'; | |||||||||||||||||||||||||||||||
| 468 | 1 | cmp_ok $message->{data}, '!=', $message->{data}, 'received NaN'; | |||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||
| 470 | # libc NaN compatibility | ||||||||||||||||||||||||||||||||
| 471 | 1 | foreach my $nan (qw(-nan NaN NAN nan(chars))) { | |||||||||||||||||||||||||||||||
| 472 | 4 | $redis->parse(",$nan\r\n"); | |||||||||||||||||||||||||||||||
| 473 | 4 | my $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 474 | 4 | is $message->{type}, ',', 'double message type'; | |||||||||||||||||||||||||||||||
| 475 | cmp_ok $message->{data}, '!=', $message->{data}, | ||||||||||||||||||||||||||||||||
| 476 | 4 | "interpreted $nan as NaN double"; | |||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | sub _parse_big_number_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_big_number_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 481 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | # Big number message | ||||||||||||||||||||||||||||||||
| 484 | 1 | $redis->parse("(3492890328409238509324850943850943825024385\r\n"); | |||||||||||||||||||||||||||||||
| 485 | 1 | my $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 486 | 1 | is $message->{type}, '(', 'big number message type'; | |||||||||||||||||||||||||||||||
| 487 | 1 | is $message->{data}, '3492890328409238509324850943850943825024385', | |||||||||||||||||||||||||||||||
| 488 | 'big number data'; | ||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||
| 490 | # Negative big number message | ||||||||||||||||||||||||||||||||
| 491 | 1 | $redis->parse("(-3492890328409238509324850943850943825024385\r\n"); | |||||||||||||||||||||||||||||||
| 492 | 1 | $message = $redis->get_message; | |||||||||||||||||||||||||||||||
| 493 | 1 | is $message->{type}, '(', 'big number message type'; | |||||||||||||||||||||||||||||||
| 494 | 1 | is $message->{data}, '-3492890328409238509324850943850943825024385', | |||||||||||||||||||||||||||||||
| 495 | 'negative big number data'; | ||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||
| 497 | # Simple big number message | ||||||||||||||||||||||||||||||||
| 498 | 1 | $redis->parse("(0\r\n"); | |||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||
| 500 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 501 | {type => '(', data => '0'}, | ||||||||||||||||||||||||||||||||
| 502 | 'simple big number'; | ||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | 1 | ▶ | sub _parse_map_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_map_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 506 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||
| 508 | # Map message | ||||||||||||||||||||||||||||||||
| 509 | 1 | $redis->parse("%1\r\n+one\r\n+two\r\n"); | |||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||
| 511 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 512 | {type => '%', data => {one => {type => '+', data => 'two'}}}, | ||||||||||||||||||||||||||||||||
| 513 | 'simple map message'; | ||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||
| 515 | # Empty map message | ||||||||||||||||||||||||||||||||
| 516 | 1 | $redis->parse("%0\r\n"); | |||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 519 | {type => '%', data => {}}, | ||||||||||||||||||||||||||||||||
| 520 | 'empty map message'; | ||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||
| 522 | # Complex map message | ||||||||||||||||||||||||||||||||
| 523 | 1 | $redis->parse("%3\r\n\$5\r\ntest1\r\n"); | |||||||||||||||||||||||||||||||
| 524 | 1 | $redis->parse(":1\r\n+test2\r\n,0.01\r\n:3\r\n_\r\n"); | |||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||
| 526 | 1 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 527 | type => '%', | ||||||||||||||||||||||||||||||||
| 528 | data => { | ||||||||||||||||||||||||||||||||
| 529 | test1 => {type => ':', data => '1'}, | ||||||||||||||||||||||||||||||||
| 530 | test2 => {type => ',', data => '0.01'}, | ||||||||||||||||||||||||||||||||
| 531 | '3' => {type => '_', data => undef}, | ||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||
| 533 | }, | ||||||||||||||||||||||||||||||||
| 534 | 'complex map message'; | ||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | sub _parse_set_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_set_ok: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 538 | 0 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||
| 540 | # Set message | ||||||||||||||||||||||||||||||||
| 541 | 0 | $redis->parse("~5\r\n+test1\r\n\$5\r\ntest2\r\n:42\r\n#t\r\n_\r\n"); | |||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||
| 543 | 0 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 544 | type => '~', | ||||||||||||||||||||||||||||||||
| 545 | data => [ | ||||||||||||||||||||||||||||||||
| 546 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 547 | {type => '$', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 548 | {type => ':', data => '42'}, | ||||||||||||||||||||||||||||||||
| 549 | {type => '#', data => !!1}, | ||||||||||||||||||||||||||||||||
| 550 | {type => '_', data => undef}, | ||||||||||||||||||||||||||||||||
| 551 | ] | ||||||||||||||||||||||||||||||||
| 552 | }, | ||||||||||||||||||||||||||||||||
| 553 | 'set message'; | ||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||
| 555 | # Empty set message | ||||||||||||||||||||||||||||||||
| 556 | 0 | $redis->parse("~0\r\n"); | |||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | 0 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 559 | {type => '~', data => []}, | ||||||||||||||||||||||||||||||||
| 560 | 'empty set message'; | ||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||
| 562 | # Set message with duplicates | ||||||||||||||||||||||||||||||||
| 563 | 0 | $redis->parse("~3\r\n+test1\r\n+test2\r\n+test1\r\n"); | |||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||
| 565 | 0 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 566 | type => '~', | ||||||||||||||||||||||||||||||||
| 567 | data => [ | ||||||||||||||||||||||||||||||||
| 568 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 569 | {type => '+', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 570 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 571 | ] | ||||||||||||||||||||||||||||||||
| 572 | }, | ||||||||||||||||||||||||||||||||
| 573 | 'set message with duplicates'; | ||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||
| 575 | # Set message with non-duplicate but equal strings | ||||||||||||||||||||||||||||||||
| 576 | 0 | $redis->parse("~8\r\n+test1\r\n\$5\r\ntest1\r\n"); | |||||||||||||||||||||||||||||||
| 577 | 0 | $redis->parse(":1\r\n,1\r\n#t\r\n"); | |||||||||||||||||||||||||||||||
| 578 | 0 | $redis->parse("_\r\n+\r\n\$0\r\n\r\n"); | |||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||
| 580 | 0 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 581 | type => '~', | ||||||||||||||||||||||||||||||||
| 582 | data => [ | ||||||||||||||||||||||||||||||||
| 583 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 584 | {type => '$', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 585 | {type => ':', data => '1'}, | ||||||||||||||||||||||||||||||||
| 586 | {type => ',', data => '1'}, | ||||||||||||||||||||||||||||||||
| 587 | {type => '#', data => !!1}, | ||||||||||||||||||||||||||||||||
| 588 | {type => '_', data => undef}, | ||||||||||||||||||||||||||||||||
| 589 | {type => '+', data => ''}, | ||||||||||||||||||||||||||||||||
| 590 | {type => '$', data => ''}, | ||||||||||||||||||||||||||||||||
| 591 | ] | ||||||||||||||||||||||||||||||||
| 592 | }, | ||||||||||||||||||||||||||||||||
| 593 | 'set message with non-duplicate but equal strings'; | ||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||
| 596 | 1 | ▶ | sub _parse_attribute_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_attribute_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 597 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||
| 599 | # Message with attributes | ||||||||||||||||||||||||||||||||
| 600 | 1 | $redis->parse("|1\r\n+total\r\n:5\r\n*2\r\n"); | |||||||||||||||||||||||||||||||
| 601 | 1 | $redis->parse("\$5\r\ntest1\r\n\$5\r\ntest2\r\n"); | |||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||
| 603 | 1 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 604 | type => '*', | ||||||||||||||||||||||||||||||||
| 605 | data => | ||||||||||||||||||||||||||||||||
| 606 | [{type => '$', data => 'test1'}, {type => '$', data => 'test2'},], | ||||||||||||||||||||||||||||||||
| 607 | attributes => { | ||||||||||||||||||||||||||||||||
| 608 | total => {type => ':', data => '5'}, | ||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||
| 610 | }, | ||||||||||||||||||||||||||||||||
| 611 | 'message with attributes'; | ||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||
| 613 | # Multiple attributes | ||||||||||||||||||||||||||||||||
| 614 | 1 | $redis->parse("|3\r\n+x\r\n,0.5\r\n+y\r\n,-3.4\r\n+z\r\n:42\r\n+OK\r\n"); | |||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||
| 616 | 1 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 617 | type => '+', | ||||||||||||||||||||||||||||||||
| 618 | data => 'OK', | ||||||||||||||||||||||||||||||||
| 619 | attributes => { | ||||||||||||||||||||||||||||||||
| 620 | x => {type => ',', data => '0.5'}, | ||||||||||||||||||||||||||||||||
| 621 | y => {type => ',', data => '-3.4'}, | ||||||||||||||||||||||||||||||||
| 622 | z => {type => ':', data => '42'}, | ||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||
| 624 | }, | ||||||||||||||||||||||||||||||||
| 625 | 'message with multiple attributes'; | ||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||
| 627 | # Empty attributes | ||||||||||||||||||||||||||||||||
| 628 | 1 | $redis->parse("|0\r\n-ERR no response\r\n"); | |||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||
| 630 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 631 | {type => '-', data => 'ERR no response', attributes => {}}, | ||||||||||||||||||||||||||||||||
| 632 | 'message with empty attributes'; | ||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||
| 634 | # Embedded attributes | ||||||||||||||||||||||||||||||||
| 635 | 1 | $redis->parse("*2\r\n|2\r\n+min\r\n:0\r\n+max\r\n:10\r\n:5\r\n"); | |||||||||||||||||||||||||||||||
| 636 | 1 | $redis->parse("|2\r\n+min\r\n:4\r\n+max\r\n:8\r\n:7\r\n"); | |||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||
| 638 | 1 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 639 | type => '*', | ||||||||||||||||||||||||||||||||
| 640 | data => [{ | ||||||||||||||||||||||||||||||||
| 641 | type => ':', | ||||||||||||||||||||||||||||||||
| 642 | data => '5', | ||||||||||||||||||||||||||||||||
| 643 | attributes => { | ||||||||||||||||||||||||||||||||
| 644 | min => {type => ':', data => '0'}, | ||||||||||||||||||||||||||||||||
| 645 | max => {type => ':', data => '10'}, | ||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||
| 647 | }, { | ||||||||||||||||||||||||||||||||
| 648 | type => ':', | ||||||||||||||||||||||||||||||||
| 649 | data => '7', | ||||||||||||||||||||||||||||||||
| 650 | attributes => { | ||||||||||||||||||||||||||||||||
| 651 | min => {type => ':', data => '4'}, | ||||||||||||||||||||||||||||||||
| 652 | max => {type => ':', data => '8'}, | ||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||
| 654 | }, | ||||||||||||||||||||||||||||||||
| 655 | ] | ||||||||||||||||||||||||||||||||
| 656 | }, | ||||||||||||||||||||||||||||||||
| 657 | 'message with embedded attributes'; | ||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||
| 659 | # Aggregate attributes | ||||||||||||||||||||||||||||||||
| 660 | 1 | $redis->parse("|1\r\n+array\r\n*2\r\n+test1\r\n+test2\r\n+test\r\n"); | |||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||
| 662 | 1 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 663 | type => '+', | ||||||||||||||||||||||||||||||||
| 664 | data => 'test', | ||||||||||||||||||||||||||||||||
| 665 | attributes => { | ||||||||||||||||||||||||||||||||
| 666 | array => { | ||||||||||||||||||||||||||||||||
| 667 | type => '*', | ||||||||||||||||||||||||||||||||
| 668 | data => [ | ||||||||||||||||||||||||||||||||
| 669 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 670 | {type => '+', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 671 | ] | ||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||
| 674 | }, | ||||||||||||||||||||||||||||||||
| 675 | 'message with aggregate attribute values'; | ||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | sub _parse_push_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_push_ok: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 679 | 0 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||
| 681 | # Simple push message | ||||||||||||||||||||||||||||||||
| 682 | 0 | $redis->parse(">2\r\n\$5\r\ntest1\r\n:42\r\n"); | |||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||
| 684 | 0 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 685 | type => '>', | ||||||||||||||||||||||||||||||||
| 686 | data => [{type => '$', data => 'test1'}, {type => ':', data => '42'},] | ||||||||||||||||||||||||||||||||
| 687 | }, | ||||||||||||||||||||||||||||||||
| 688 | 'simple push message'; | ||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||
| 690 | # Empty push message | ||||||||||||||||||||||||||||||||
| 691 | 0 | $redis->parse(">0\r\n"); | |||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||
| 693 | 0 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 694 | {type => '>', data => []}, | ||||||||||||||||||||||||||||||||
| 695 | 'empty push message'; | ||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||
| 698 | 1 | ▶ | sub _parse_streamed_string_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_streamed_string_ok: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 699 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||
| 701 | # Simple streamed string | ||||||||||||||||||||||||||||||||
| 702 | 1 | $redis->parse("\$?\r\n;4\r\ntest\r\n;2\r\nxy\r\n;0\r\n"); | |||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||
| 704 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 705 | {type => '$', data => 'testxy'}, | ||||||||||||||||||||||||||||||||
| 706 | 'simple streamed string'; | ||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||
| 708 | # Empty streamed string | ||||||||||||||||||||||||||||||||
| 709 | 1 | $redis->parse("\$?\r\n;0\r\n"); | |||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||
| 711 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 712 | {type => '$', data => ''}, | ||||||||||||||||||||||||||||||||
| 713 | 'empty streamed string'; | ||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||
| 715 | # Charwise streamed string | ||||||||||||||||||||||||||||||||
| 716 | 1 | $redis->parse("\$?\r\n"); | |||||||||||||||||||||||||||||||
| 717 | 1 | $redis->parse(";1\r\n$_\r\n") for 'a' .. 'z'; | |||||||||||||||||||||||||||||||
| 718 | 1 | $redis->parse(";0\r\n"); | |||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||
| 720 | 1 | is_deeply $redis->get_message, | |||||||||||||||||||||||||||||||
| 721 | {type => '$', data => join('', 'a' .. 'z')}, | ||||||||||||||||||||||||||||||||
| 722 | 'string streamed by character'; | ||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||
| 725 | 1 | ▶ | sub _parse_streamed_aggregate_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_streamed_aggregate_ok: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||
| 726 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 727 | 1 | ▶ | my $type = shift || '*'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || '*'
MC/DC0%0/1
shift() || '*'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||
| 729 | # Simple streamed aggregate | ||||||||||||||||||||||||||||||||
| 730 | 1 | $redis->parse("${type}?\r\n+test1\r\n+test2\r\n.\r\n"); | |||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||
| 732 | 1 | ▶ | if ($type eq '%') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 733 | 0 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 734 | type => $type, | ||||||||||||||||||||||||||||||||
| 735 | data => { | ||||||||||||||||||||||||||||||||
| 736 | test1 => {type => '+', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||
| 738 | }, | ||||||||||||||||||||||||||||||||
| 739 | "simple $type streamed aggregate message"; | ||||||||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||||||
| 741 | else { | ||||||||||||||||||||||||||||||||
| 742 | 1 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 743 | type => $type, | ||||||||||||||||||||||||||||||||
| 744 | data => [ | ||||||||||||||||||||||||||||||||
| 745 | {type => '+', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 746 | {type => '+', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 747 | ] | ||||||||||||||||||||||||||||||||
| 748 | }, | ||||||||||||||||||||||||||||||||
| 749 | "simple $type streamed aggregate message"; | ||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||
| 752 | # Empty streamed aggregate | ||||||||||||||||||||||||||||||||
| 753 | 1 | $redis->parse("${type}?\r\n.\r\n"); | |||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||
| 755 | 1 | ▶ | is_deeply $redis->get_message, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 756 | {type => $type, data => ($type eq '%' ? {} : [])}, | ||||||||||||||||||||||||||||||||
| 757 | "empty $type streamed aggregate message"; | ||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||
| 759 | # Complex streamed aggregate | ||||||||||||||||||||||||||||||||
| 760 | 1 | $redis->parse("${type}?\r\n"); | |||||||||||||||||||||||||||||||
| 761 | 1 | $redis->parse("\$?\r\n;4\r\ntest\r\n;1\r\n1\r\n;0\r\n"); | |||||||||||||||||||||||||||||||
| 762 | 1 | $redis->parse("\$5\r\ntest$_\r\n") for 2 .. 9; | |||||||||||||||||||||||||||||||
| 763 | 1 | $redis->parse("*?\r\n:10\r\n,11\r\n.\r\n"); | |||||||||||||||||||||||||||||||
| 764 | 1 | $redis->parse(".\r\n"); | |||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||
| 766 | 1 | ▶ | if ($type eq '%') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 767 | 0 | is_deeply $redis->get_message, { | |||||||||||||||||||||||||||||||
| 768 | type => $type, | ||||||||||||||||||||||||||||||||
| 769 | data => { | ||||||||||||||||||||||||||||||||
| 770 | test1 => {type => '$', data => 'test2'}, | ||||||||||||||||||||||||||||||||
| 771 | test3 => {type => '$', data => 'test4'}, | ||||||||||||||||||||||||||||||||
| 772 | test5 => {type => '$', data => 'test6'}, | ||||||||||||||||||||||||||||||||
| 773 | test7 => {type => '$', data => 'test8'}, | ||||||||||||||||||||||||||||||||
| 774 | test9 => { | ||||||||||||||||||||||||||||||||
| 775 | type => '*', | ||||||||||||||||||||||||||||||||
| 776 | data => [ | ||||||||||||||||||||||||||||||||
| 777 | {type => ':', data => '10'}, | ||||||||||||||||||||||||||||||||
| 778 | {type => ',', data => '11'}, | ||||||||||||||||||||||||||||||||
| 779 | ] | ||||||||||||||||||||||||||||||||
| 780 | }, | ||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||
| 782 | }, | ||||||||||||||||||||||||||||||||
| 783 | "complex $type streamed aggregate message"; | ||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||
| 785 | else { | ||||||||||||||||||||||||||||||||
| 786 | is_deeply $redis->get_message, { | ||||||||||||||||||||||||||||||||
| 787 | type => $type, | ||||||||||||||||||||||||||||||||
| 788 | data => [ | ||||||||||||||||||||||||||||||||
| 789 | {type => '$', data => 'test1'}, | ||||||||||||||||||||||||||||||||
| 790 | 1 | (map { +{type => '$', data => "test$_"} } 2 .. 9), { | |||||||||||||||||||||||||||||||
| 791 | type => '*', | ||||||||||||||||||||||||||||||||
| 792 | data => [ | ||||||||||||||||||||||||||||||||
| 793 | {type => ':', data => '10'}, | ||||||||||||||||||||||||||||||||
| 794 | {type => ',', data => '11'}, | ||||||||||||||||||||||||||||||||
| 795 | ] | ||||||||||||||||||||||||||||||||
| 796 | }, | ||||||||||||||||||||||||||||||||
| 797 | ] | ||||||||||||||||||||||||||||||||
| 798 | }, | ||||||||||||||||||||||||||||||||
| 799 | "complex $type streamed aggregate message"; | ||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||
| 803 | 3 | ▶ | sub _on_message_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_on_message_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 804 | 3 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||
| 806 | # Parsing with cb | ||||||||||||||||||||||||||||||||
| 807 | 3 | my $r = []; | |||||||||||||||||||||||||||||||
| 808 | $redis->on_message( | ||||||||||||||||||||||||||||||||
| 809 | 12 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 810 | 12 | my ($redis, $message) = @_; | |||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||
| 812 | 12 | push @$r, $message; | |||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||
| 814 | 3 | ); | |||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||
| 816 | 3 | $redis->parse("+foo\r\n"); | |||||||||||||||||||||||||||||||
| 817 | 3 | $redis->parse("\$3\r\nbar\r\n"); | |||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||
| 819 | 3 | is_deeply $r, | |||||||||||||||||||||||||||||||
| 820 | [{type => '+', data => 'foo'}, {type => '$', data => 'bar'}], | ||||||||||||||||||||||||||||||||
| 821 | 'parsing with callback'; | ||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||
| 823 | 3 | $r = []; | |||||||||||||||||||||||||||||||
| 824 | 3 | $redis->parse(join("\r\n", ('+foo'), ('$3', 'bar'), '')); | |||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||
| 826 | 3 | is_deeply $r, | |||||||||||||||||||||||||||||||
| 827 | [{type => '+', data => 'foo'}, {type => '$', data => 'bar'}], | ||||||||||||||||||||||||||||||||
| 828 | 'pipelined parsing with callback'; | ||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||
| 830 | 3 | $redis->on_message(undef); | |||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||
| 833 | 3 | ▶ | sub _encode_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 834 | 3 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||
| 836 | # Encode message | ||||||||||||||||||||||||||||||||
| 837 | 3 | is $redis->encode({type => '+', data => 'OK'}), "+OK\r\n", | |||||||||||||||||||||||||||||||
| 838 | 'encode status'; | ||||||||||||||||||||||||||||||||
| 839 | 3 | is $redis->encode({type => '-', data => 'ERROR'}), "-ERROR\r\n", | |||||||||||||||||||||||||||||||
| 840 | 'encode error'; | ||||||||||||||||||||||||||||||||
| 841 | 3 | is $redis->encode({type => ':', data => '5'}), ":5\r\n", 'encode integer'; | |||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||
| 843 | # Encode bulk message | ||||||||||||||||||||||||||||||||
| 844 | 3 | is $redis->encode({type => '$', data => 'test'}), "\$4\r\ntest\r\n", | |||||||||||||||||||||||||||||||
| 845 | 'encode bulk'; | ||||||||||||||||||||||||||||||||
| 846 | 3 | is $redis->encode({type => '$', data => "\0\r\n"}), "\$3\r\n\0\r\n\r\n", | |||||||||||||||||||||||||||||||
| 847 | 'encode binary bulk'; | ||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||
| 849 | # Encode multi-bulk | ||||||||||||||||||||||||||||||||
| 850 | 3 | is $redis->encode({type => '*', data => [{type => '$', data => 'test'}]}), | |||||||||||||||||||||||||||||||
| 851 | join("\r\n", ('*1', '$4', 'test'), ''), | ||||||||||||||||||||||||||||||||
| 852 | 'encode multi-bulk'; | ||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||
| 854 | 3 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 855 | type => '*', | ||||||||||||||||||||||||||||||||
| 856 | data => [ | ||||||||||||||||||||||||||||||||
| 857 | {type => '$', data => 'test1'}, {type => '$', data => 'test2'} | ||||||||||||||||||||||||||||||||
| 858 | ] | ||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||
| 860 | ), | ||||||||||||||||||||||||||||||||
| 861 | join("\r\n", ('*2', '$5', 'test1', '$5', 'test2'), ''), | ||||||||||||||||||||||||||||||||
| 862 | 'encode multi-bulk'; | ||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||
| 864 | 3 | is $redis->encode({type => '*', data => []}), "\*0\r\n", | |||||||||||||||||||||||||||||||
| 865 | 'encode empty multi-bulk'; | ||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||
| 868 | 2 | ▶ | sub _encode_v1_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_v1_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 869 | 2 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||
| 871 | 2 | is $redis->encode({type => '$', data => undef}), "\$-1\r\n", | |||||||||||||||||||||||||||||||
| 872 | 'encode nil bulk'; | ||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||
| 874 | 2 | is $redis->encode({type => '*', data => undef}), "\*-1\r\n", | |||||||||||||||||||||||||||||||
| 875 | 'encode nil multi-bulk'; | ||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||
| 877 | 2 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 878 | type => '*', | ||||||||||||||||||||||||||||||||
| 879 | data => [ | ||||||||||||||||||||||||||||||||
| 880 | {type => '$', data => 'foo'}, | ||||||||||||||||||||||||||||||||
| 881 | {type => '$', data => undef}, | ||||||||||||||||||||||||||||||||
| 882 | {type => '$', data => 'bar'} | ||||||||||||||||||||||||||||||||
| 883 | ] | ||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||
| 885 | ), | ||||||||||||||||||||||||||||||||
| 886 | join("\r\n", ('*3', '$3', 'foo', '$-1', '$3', 'bar'), ''), | ||||||||||||||||||||||||||||||||
| 887 | 'encode multi-bulk with nil element'; | ||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||
| 890 | 1 | ▶ | sub _encode_v3_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_v3_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 891 | 1 | my $redis = shift; | |||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||
| 893 | # Encode simple RESP3 types | ||||||||||||||||||||||||||||||||
| 894 | 1 | is $redis->encode({type => '_', data => undef}), "_\r\n", 'encode null'; | |||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||
| 896 | 1 | is $redis->encode({type => '#', data => 1}), "#t\r\n", | |||||||||||||||||||||||||||||||
| 897 | 'encode boolean true'; | ||||||||||||||||||||||||||||||||
| 898 | 1 | is $redis->encode({type => '#', data => 0}), "#f\r\n", | |||||||||||||||||||||||||||||||
| 899 | 'encode boolean false'; | ||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||
| 901 | 1 | is $redis->encode({type => ',', data => '1.3'}), ",1.3\r\n", | |||||||||||||||||||||||||||||||
| 902 | 'encode double'; | ||||||||||||||||||||||||||||||||
| 903 | 1 | is $redis->encode({type => ',', data => '-1.2e-5'}), ",-1.2e-5\r\n", | |||||||||||||||||||||||||||||||
| 904 | 'encode negative double with exponent'; | ||||||||||||||||||||||||||||||||
| 905 | 1 | is $redis->encode({type => ',', data => '10'}), ",10\r\n", | |||||||||||||||||||||||||||||||
| 906 | 'encode integer as double'; | ||||||||||||||||||||||||||||||||
| 907 | 1 | is $redis->encode({type => ',', data => '0'}), ",0\r\n", | |||||||||||||||||||||||||||||||
| 908 | 'encode zero as double'; | ||||||||||||||||||||||||||||||||
| 909 | 1 | is $redis->encode({type => ',', data => 9**9**9}), ",inf\r\n", | |||||||||||||||||||||||||||||||
| 910 | 'encode inf'; | ||||||||||||||||||||||||||||||||
| 911 | 1 | is $redis->encode({type => ',', data => -9**9**9}), ",-inf\r\n", | |||||||||||||||||||||||||||||||
| 912 | 'encode negative inf'; | ||||||||||||||||||||||||||||||||
| 913 | 1 | is $redis->encode({type => ',', data => -sin 9**9**9}), ",nan\r\n", | |||||||||||||||||||||||||||||||
| 914 | 'encode nan'; | ||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||
| 916 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 917 | type => '(', | ||||||||||||||||||||||||||||||||
| 918 | data => '3492890328409238509324850943850943825024385' | ||||||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||||||
| 920 | ), | ||||||||||||||||||||||||||||||||
| 921 | "(3492890328409238509324850943850943825024385\r\n", | ||||||||||||||||||||||||||||||||
| 922 | 'encode big number'; | ||||||||||||||||||||||||||||||||
| 923 | 1 | require Math::BigInt; | |||||||||||||||||||||||||||||||
| 924 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 925 | type => '(', | ||||||||||||||||||||||||||||||||
| 926 | data => Math::BigInt->new( | ||||||||||||||||||||||||||||||||
| 927 | '-3492890328409238509324850943850943825024385') | ||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||
| 929 | ), | ||||||||||||||||||||||||||||||||
| 930 | "(-3492890328409238509324850943850943825024385\r\n", | ||||||||||||||||||||||||||||||||
| 931 | 'encode bigint as big number'; | ||||||||||||||||||||||||||||||||
| 932 | 1 | is $redis->encode({type => '(', data => '0'}), "(0\r\n", | |||||||||||||||||||||||||||||||
| 933 | 'encode zero as big number'; | ||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||
| 935 | # Encode blob RESP3 types | ||||||||||||||||||||||||||||||||
| 936 | 1 | is $redis->encode({type => '!', data => 'SYNTAX'}), | |||||||||||||||||||||||||||||||
| 937 | "!6\r\nSYNTAX\r\n", 'encode blob error'; | ||||||||||||||||||||||||||||||||
| 938 | 1 | is $redis->encode({type => '!', data => "\0\r\n"}), | |||||||||||||||||||||||||||||||
| 939 | "!3\r\n\0\r\n\r\n", 'encode binary blob error'; | ||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||
| 941 | 1 | is $redis->encode({type => '=', data => '"foo"'}), | |||||||||||||||||||||||||||||||
| 942 | "=9\r\ntxt:\"foo\"\r\n", 'encode verbatim string'; | ||||||||||||||||||||||||||||||||
| 943 | 1 | is $redis->encode({type => '=', data => '"bar"', format => 'mkd'}), | |||||||||||||||||||||||||||||||
| 944 | "=9\r\nmkd:\"bar\"\r\n", 'encode verbatim string with custom format'; | ||||||||||||||||||||||||||||||||
| 945 | 1 | is $redis->encode({type => '=', data => "\0\r\n"}), | |||||||||||||||||||||||||||||||
| 946 | "=7\r\ntxt:\0\r\n\r\n", 'encode binary verbatim string'; | ||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||
| 948 | # Encode aggregate RESP3 types | ||||||||||||||||||||||||||||||||
| 949 | 1 | is $redis->encode( | |||||||||||||||||||||||||||||||
| 950 | {type => '%', data => {foo => {type => '+', data => 'bar'}}}), | ||||||||||||||||||||||||||||||||
| 951 | join("\r\n", '%1', '$3', 'foo', '+bar', ''), | ||||||||||||||||||||||||||||||||
| 952 | 'encode map'; | ||||||||||||||||||||||||||||||||
| 953 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 954 | type => '~', | ||||||||||||||||||||||||||||||||
| 955 | data => [{type => ':', data => 5}, {type => '+', data => 'test'}] | ||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||
| 957 | ), | ||||||||||||||||||||||||||||||||
| 958 | join("\r\n", '~2', ':5', '+test', ''), | ||||||||||||||||||||||||||||||||
| 959 | 'encode set'; | ||||||||||||||||||||||||||||||||
| 960 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 961 | type => '>', | ||||||||||||||||||||||||||||||||
| 962 | data => | ||||||||||||||||||||||||||||||||
| 963 | [{type => '+', data => 'test'}, {type => ',', data => '4.2'}] | ||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||
| 965 | ), | ||||||||||||||||||||||||||||||||
| 966 | join("\r\n", '>2', '+test', ',4.2', ''), | ||||||||||||||||||||||||||||||||
| 967 | 'encode push'; | ||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||
| 969 | # Encode attributes | ||||||||||||||||||||||||||||||||
| 970 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 971 | type => '+', | ||||||||||||||||||||||||||||||||
| 972 | data => 'test', | ||||||||||||||||||||||||||||||||
| 973 | attributes => {foo => {type => '+', data => 'bar'}} | ||||||||||||||||||||||||||||||||
| 974 | } | ||||||||||||||||||||||||||||||||
| 975 | ), | ||||||||||||||||||||||||||||||||
| 976 | join("\r\n", '|1', '$3', 'foo', '+bar', '+test', ''), | ||||||||||||||||||||||||||||||||
| 977 | 'encode simple string with attributes'; | ||||||||||||||||||||||||||||||||
| 978 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 979 | type => '*', | ||||||||||||||||||||||||||||||||
| 980 | data => [{type => '_', data => undef}], | ||||||||||||||||||||||||||||||||
| 981 | attributes => {test => {type => '#', data => 1}} | ||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||
| 983 | ), | ||||||||||||||||||||||||||||||||
| 984 | join("\r\n", '|1', '$4', 'test', '#t', '*1', '_', ''), | ||||||||||||||||||||||||||||||||
| 985 | 'encode array with attributes'; | ||||||||||||||||||||||||||||||||
| 986 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 987 | type => '~', | ||||||||||||||||||||||||||||||||
| 988 | data => [{ | ||||||||||||||||||||||||||||||||
| 989 | type => ',', | ||||||||||||||||||||||||||||||||
| 990 | data => '-5.5', | ||||||||||||||||||||||||||||||||
| 991 | attributes => {precision => {type => ':', data => 1}} | ||||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||
| 993 | ] | ||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||
| 995 | ), | ||||||||||||||||||||||||||||||||
| 996 | join("\r\n", '~1', '|1', '$9', 'precision', ':1', ',-5.5', ''), | ||||||||||||||||||||||||||||||||
| 997 | 'encode set with embedded attributes'; | ||||||||||||||||||||||||||||||||
| 998 | 1 | is $redis->encode({ | |||||||||||||||||||||||||||||||
| 999 | type => '+', | ||||||||||||||||||||||||||||||||
| 1000 | data => 'test', | ||||||||||||||||||||||||||||||||
| 1001 | attributes => { | ||||||||||||||||||||||||||||||||
| 1002 | array => { | ||||||||||||||||||||||||||||||||
| 1003 | type => '*', | ||||||||||||||||||||||||||||||||
| 1004 | data => | ||||||||||||||||||||||||||||||||
| 1005 | [{type => ':', data => 1}, {type => ':', data => 2}] | ||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||
| 1009 | ), | ||||||||||||||||||||||||||||||||
| 1010 | join("\r\n", '|1', '$5', 'array', '*2', ':1', ':2', '+test', ''), | ||||||||||||||||||||||||||||||||
| 1011 | 'encode array attributes'; | ||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||
| 1014 | 3 | ▶ | sub _test_unknown_version { | ||||||||||||||||||||||||||||||
|
Subroutine
_test_unknown_version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 1015 | 3 | my $redis_class = shift; | |||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||
| 1017 | 3 | eval { $redis_class->new(api => 0); }; | |||||||||||||||||||||||||||||||
| 1018 | 3 | ok($@, 'unknown version raises an exception'); | |||||||||||||||||||||||||||||||
| 1019 | } | ||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||
| 1021 | 1 | 1; | |||||||||||||||||||||||||||||||
| 1022 | __END__ | ||||||||||||||||||||||||||||||||