1#!perl -T 2use strict; 3use Test::More tests => 1+6*26*3+26; 4use Data::Dumper; 5 6BEGIN { 7 use_ok( 'Hash::WithDefaults' ); 8} 9 10diag( "Testing Hash::WithDefaults $Hash::WithDefaults::VERSION, Perl $], $^X" ); 11 12{ # lower (ARRAYREF) 13 my %h; 14 ok( 15 tie( %h, 'Hash::WithDefaults', 'lower', [low => 'value', Mix => 'other', HI => 'Some']), 16 "Tied with case=lower" 17 ); 18 19 is( ref(tied %h), 'Hash::WithDefaults::lower', "Tied to the right class"); 20 21 is( $h{low}, 'value', '$h{low}'); 22 is( $h{Low}, 'value', '$h{Low}'); 23 is( $h{LOW}, 'value', '$h{LOW}'); 24 25 is( $h{mix}, 'other', '$h{mix}'); 26 is( $h{Mix}, 'other', '$h{Mix}'); 27 is( $h{MIX}, 'other', '$h{MIX}'); 28 29 is( $h{hi}, 'Some', '$h{hi}'); 30 is( $h{Hi}, 'Some', '$h{Hi}'); 31 is( $h{HI}, 'Some', '$h{HI}'); 32 33 my @got = sort keys %h; 34 my @good = qw(hi low mix); 35 36 is_deeply(\@got, \@good, "List of keys"); 37 38 @got = (); 39 while (my ($key, $val) = each %h) { 40 push @got, "$key=$val"; 41 } 42 @got = sort @got; 43 @good = ('hi=Some', 'low=value', 'mix=other'); 44 is_deeply(\@got, \@good, "each() returns both keys and values"); 45 46 is( scalar( keys %h), 3, "Number of keys"); 47 48 delete $h{Low}; 49 is( scalar( keys %h), 2, "Number of keys after delete"); 50 is( $h{low}, undef, '$h{low}'); 51 is( $h{Low}, undef, '$h{Low}'); 52 is( $h{LOW}, undef, '$h{LOW}'); 53 54 delete $h{Mix}; 55 is( scalar( keys %h), 1, "Number of keys after delete"); 56 is( $h{mix}, undef, '$h{mix}'); 57 is( $h{Mix}, undef, '$h{Mix}'); 58 is( $h{MIX}, undef, '$h{MIX}'); 59 60 %h = (); 61 is( scalar( keys %h), 0, "Number of keys after clear"); 62 is_deeply( [keys %h], [], "There are no keys"); 63 64 $h{a} = 1; $h{B} = 2; 65 is( scalar( keys %h), 2, "Number of keys after refil"); 66 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 67 68} 69 70{ # lower (HASHREF) 71 my %h; 72 ok( 73 tie( %h, 'Hash::WithDefaults', 'lower', {low => 'value', Mix => 'other', HI => 'Some'}), 74 "Tied with case=lower" 75 ); 76 77 is( ref(tied %h), 'Hash::WithDefaults::lower', "Tied to the right class"); 78 79 is( $h{low}, 'value', '$h{low}'); 80 is( $h{Low}, 'value', '$h{Low}'); 81 is( $h{LOW}, 'value', '$h{LOW}'); 82 83 is( $h{mix}, 'other', '$h{mix}'); 84 is( $h{Mix}, 'other', '$h{Mix}'); 85 is( $h{MIX}, 'other', '$h{MIX}'); 86 87 is( $h{hi}, 'Some', '$h{hi}'); 88 is( $h{Hi}, 'Some', '$h{Hi}'); 89 is( $h{HI}, 'Some', '$h{HI}'); 90 91 my @got = sort keys %h; 92 my @good = qw(hi low mix); 93 94 is_deeply(\@got, \@good, "List of keys"); 95 96 @got = (); 97 while (my ($key, $val) = each %h) { 98 push @got, "$key=$val"; 99 } 100 @got = sort @got; 101 @good = ('hi=Some', 'low=value', 'mix=other'); 102 is_deeply(\@got, \@good, "each() returns both keys and values"); 103 104 is( scalar( keys %h), 3, "Number of keys"); 105 106 delete $h{Low}; 107 is( scalar( keys %h), 2, "Number of keys after delete"); 108 is( $h{low}, undef, '$h{low}'); 109 is( $h{Low}, undef, '$h{Low}'); 110 is( $h{LOW}, undef, '$h{LOW}'); 111 112 delete $h{Mix}; 113 is( scalar( keys %h), 1, "Number of keys after delete"); 114 is( $h{mix}, undef, '$h{mix}'); 115 is( $h{Mix}, undef, '$h{Mix}'); 116 is( $h{MIX}, undef, '$h{MIX}'); 117 118 %h = (); 119 is( scalar( keys %h), 0, "Number of keys after clear"); 120 is_deeply( [keys %h], [], "There are no keys"); 121 122 $h{a} = 1; $h{B} = 2; 123 is( scalar( keys %h), 2, "Number of keys after refil"); 124 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 125 126} 127 128{ # lower (LIST) 129 my %h; 130 ok( 131 tie( %h, 'Hash::WithDefaults', 'lower', low => 'value', Mix => 'other', HI => 'Some'), 132 "Tied with case=lower" 133 ); 134 135 is( ref(tied %h), 'Hash::WithDefaults::lower', "Tied to the right class"); 136 137 is( $h{low}, 'value', '$h{low}'); 138 is( $h{Low}, 'value', '$h{Low}'); 139 is( $h{LOW}, 'value', '$h{LOW}'); 140 141 is( $h{mix}, 'other', '$h{mix}'); 142 is( $h{Mix}, 'other', '$h{Mix}'); 143 is( $h{MIX}, 'other', '$h{MIX}'); 144 145 is( $h{hi}, 'Some', '$h{hi}'); 146 is( $h{Hi}, 'Some', '$h{Hi}'); 147 is( $h{HI}, 'Some', '$h{HI}'); 148 149 my @got = sort keys %h; 150 my @good = qw(hi low mix); 151 152 is_deeply(\@got, \@good, "List of keys"); 153 154 @got = (); 155 while (my ($key, $val) = each %h) { 156 push @got, "$key=$val"; 157 } 158 @got = sort @got; 159 @good = ('hi=Some', 'low=value', 'mix=other'); 160 is_deeply(\@got, \@good, "each() returns both keys and values"); 161 162 is( scalar( keys %h), 3, "Number of keys"); 163 164 delete $h{Low}; 165 is( scalar( keys %h), 2, "Number of keys after delete"); 166 is( $h{low}, undef, '$h{low}'); 167 is( $h{Low}, undef, '$h{Low}'); 168 is( $h{LOW}, undef, '$h{LOW}'); 169 170 delete $h{Mix}; 171 is( scalar( keys %h), 1, "Number of keys after delete"); 172 is( $h{mix}, undef, '$h{mix}'); 173 is( $h{Mix}, undef, '$h{Mix}'); 174 is( $h{MIX}, undef, '$h{MIX}'); 175 176 %h = (); 177 is( scalar( keys %h), 0, "Number of keys after clear"); 178 is_deeply( [keys %h], [], "There are no keys"); 179 180 $h{a} = 1; $h{B} = 2; 181 is( scalar( keys %h), 2, "Number of keys after refil"); 182 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 183 184} 185 186{ # lower (LIST), direct 187 my %h; 188 ok( 189 tie( %h, 'Hash::WithDefaults::lower', low => 'value', Mix => 'other', HI => 'Some'), 190 "Tied with case=lower" 191 ); 192 193 is( ref(tied %h), 'Hash::WithDefaults::lower', "Tied to the right class"); 194 195 is( $h{low}, 'value', '$h{low}'); 196 is( $h{Low}, 'value', '$h{Low}'); 197 is( $h{LOW}, 'value', '$h{LOW}'); 198 199 is( $h{mix}, 'other', '$h{mix}'); 200 is( $h{Mix}, 'other', '$h{Mix}'); 201 is( $h{MIX}, 'other', '$h{MIX}'); 202 203 is( $h{hi}, 'Some', '$h{hi}'); 204 is( $h{Hi}, 'Some', '$h{Hi}'); 205 is( $h{HI}, 'Some', '$h{HI}'); 206 207 my @got = sort keys %h; 208 my @good = qw(hi low mix); 209 210 is_deeply(\@got, \@good, "List of keys"); 211 212 @got = (); 213 while (my ($key, $val) = each %h) { 214 push @got, "$key=$val"; 215 } 216 @got = sort @got; 217 @good = ('hi=Some', 'low=value', 'mix=other'); 218 is_deeply(\@got, \@good, "each() returns both keys and values"); 219 220 is( scalar( keys %h), 3, "Number of keys"); 221 222 delete $h{Low}; 223 is( scalar( keys %h), 2, "Number of keys after delete"); 224 is( $h{low}, undef, '$h{low}'); 225 is( $h{Low}, undef, '$h{Low}'); 226 is( $h{LOW}, undef, '$h{LOW}'); 227 228 delete $h{Mix}; 229 is( scalar( keys %h), 1, "Number of keys after delete"); 230 is( $h{mix}, undef, '$h{mix}'); 231 is( $h{Mix}, undef, '$h{Mix}'); 232 is( $h{MIX}, undef, '$h{MIX}'); 233 234 %h = (); 235 is( scalar( keys %h), 0, "Number of keys after clear"); 236 is_deeply( [keys %h], [], "There are no keys"); 237 238 $h{a} = 1; $h{B} = 2; 239 is( scalar( keys %h), 2, "Number of keys after refil"); 240 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 241 242} 243 244{ # upper (ARRAYREF) 245 my %h; 246 ok( 247 tie( %h, 'Hash::WithDefaults', 'upper', [low => 'value', Mix => 'other', HI => 'Some']), 248 "Tied with case=upper" 249 ); 250 251 is( ref(tied %h), 'Hash::WithDefaults::upper', "Tied to the right class"); 252 253 is( $h{low}, 'value', '$h{low}'); 254 is( $h{Low}, 'value', '$h{Low}'); 255 is( $h{LOW}, 'value', '$h{LOW}'); 256 257 is( $h{mix}, 'other', '$h{mix}'); 258 is( $h{Mix}, 'other', '$h{Mix}'); 259 is( $h{MIX}, 'other', '$h{MIX}'); 260 261 is( $h{hi}, 'Some', '$h{hi}'); 262 is( $h{Hi}, 'Some', '$h{Hi}'); 263 is( $h{HI}, 'Some', '$h{HI}'); 264 265 my @got = sort keys %h; 266 my @good = qw(HI LOW MIX); 267 268 is_deeply(\@got, \@good, "List of keys"); 269 270 @got = (); 271 while (my ($key, $val) = each %h) { 272 push @got, "$key=$val"; 273 } 274 @got = sort @got; 275 @good = ('HI=Some', 'LOW=value', 'MIX=other'); 276 is_deeply(\@got, \@good, "each() returns both keys and values"); 277 278 is( scalar( keys %h), 3, "Number of keys"); 279 280 delete $h{Low}; 281 is( scalar( keys %h), 2, "Number of keys after delete"); 282 is( $h{low}, undef, '$h{low}'); 283 is( $h{Low}, undef, '$h{Low}'); 284 is( $h{LOW}, undef, '$h{LOW}'); 285 286 delete $h{Mix}; 287 is( scalar( keys %h), 1, "Number of keys after delete"); 288 is( $h{mix}, undef, '$h{mix}'); 289 is( $h{Mix}, undef, '$h{Mix}'); 290 is( $h{MIX}, undef, '$h{MIX}'); 291 292 %h = (); 293 is( scalar( keys %h), 0, "Number of keys after clear"); 294 is_deeply( [keys %h], [], "There are no keys"); 295 296 $h{a} = 1; $h{B} = 2; 297 is( scalar( keys %h), 2, "Number of keys after refil"); 298 is_deeply( [sort keys %h], [qw(A B)], "There are two keys"); 299 300} 301 302{ # upper (HASHREF) 303 my %h; 304 ok( 305 tie( %h, 'Hash::WithDefaults', 'upper', {low => 'value', Mix => 'other', HI => 'Some'}), 306 "Tied with case=upper" 307 ); 308 309 is( ref(tied %h), 'Hash::WithDefaults::upper', "Tied to the right class"); 310 311 is( $h{low}, 'value', '$h{low}'); 312 is( $h{Low}, 'value', '$h{Low}'); 313 is( $h{LOW}, 'value', '$h{LOW}'); 314 315 is( $h{mix}, 'other', '$h{mix}'); 316 is( $h{Mix}, 'other', '$h{Mix}'); 317 is( $h{MIX}, 'other', '$h{MIX}'); 318 319 is( $h{hi}, 'Some', '$h{hi}'); 320 is( $h{Hi}, 'Some', '$h{Hi}'); 321 is( $h{HI}, 'Some', '$h{HI}'); 322 323 my @got = sort keys %h; 324 my @good = qw(HI LOW MIX); 325 326 is_deeply(\@got, \@good, "List of keys"); 327 328 @got = (); 329 while (my ($key, $val) = each %h) { 330 push @got, "$key=$val"; 331 } 332 @got = sort @got; 333 @good = ('HI=Some', 'LOW=value', 'MIX=other'); 334 is_deeply(\@got, \@good, "each() returns both keys and values"); 335 336 is( scalar( keys %h), 3, "Number of keys"); 337 338 delete $h{Low}; 339 is( scalar( keys %h), 2, "Number of keys after delete"); 340 is( $h{low}, undef, '$h{low}'); 341 is( $h{Low}, undef, '$h{Low}'); 342 is( $h{LOW}, undef, '$h{LOW}'); 343 344 delete $h{Mix}; 345 is( scalar( keys %h), 1, "Number of keys after delete"); 346 is( $h{mix}, undef, '$h{mix}'); 347 is( $h{Mix}, undef, '$h{Mix}'); 348 is( $h{MIX}, undef, '$h{MIX}'); 349 350 %h = (); 351 is( scalar( keys %h), 0, "Number of keys after clear"); 352 is_deeply( [keys %h], [], "There are no keys"); 353 354 $h{a} = 1; $h{B} = 2; 355 is( scalar( keys %h), 2, "Number of keys after refil"); 356 is_deeply( [sort keys %h], [qw(A B)], "There are two keys"); 357 358} 359 360{ # upper (LIST) 361 my %h; 362 ok( 363 tie( %h, 'Hash::WithDefaults', 'upper', low => 'value', Mix => 'other', HI => 'Some'), 364 "Tied with case=upper" 365 ); 366 367 is( ref(tied %h), 'Hash::WithDefaults::upper', "Tied to the right class"); 368 369 is( $h{low}, 'value', '$h{low}'); 370 is( $h{Low}, 'value', '$h{Low}'); 371 is( $h{LOW}, 'value', '$h{LOW}'); 372 373 is( $h{mix}, 'other', '$h{mix}'); 374 is( $h{Mix}, 'other', '$h{Mix}'); 375 is( $h{MIX}, 'other', '$h{MIX}'); 376 377 is( $h{hi}, 'Some', '$h{hi}'); 378 is( $h{Hi}, 'Some', '$h{Hi}'); 379 is( $h{HI}, 'Some', '$h{HI}'); 380 381 my @got = sort keys %h; 382 my @good = qw(HI LOW MIX); 383 384 is_deeply(\@got, \@good, "List of keys"); 385 386 @got = (); 387 while (my ($key, $val) = each %h) { 388 push @got, "$key=$val"; 389 } 390 @got = sort @got; 391 @good = ('HI=Some', 'LOW=value', 'MIX=other'); 392 is_deeply(\@got, \@good, "each() returns both keys and values"); 393 394 is( scalar( keys %h), 3, "Number of keys"); 395 396 delete $h{Low}; 397 is( scalar( keys %h), 2, "Number of keys after delete"); 398 is( $h{low}, undef, '$h{low}'); 399 is( $h{Low}, undef, '$h{Low}'); 400 is( $h{LOW}, undef, '$h{LOW}'); 401 402 delete $h{Mix}; 403 is( scalar( keys %h), 1, "Number of keys after delete"); 404 is( $h{mix}, undef, '$h{mix}'); 405 is( $h{Mix}, undef, '$h{Mix}'); 406 is( $h{MIX}, undef, '$h{MIX}'); 407 408 %h = (); 409 is( scalar( keys %h), 0, "Number of keys after clear"); 410 is_deeply( [keys %h], [], "There are no keys"); 411 412 $h{a} = 1; $h{B} = 2; 413 is( scalar( keys %h), 2, "Number of keys after refil"); 414 is_deeply( [sort keys %h], [qw(A B)], "There are two keys"); 415 416} 417 418 419{ # preserve (ARRAYREF) 420 my %h; 421 ok( 422 tie( %h, 'Hash::WithDefaults', 'preserve', [low => 'value', Mix => 'other', HI => 'Some']), 423 "Tied with case=preserve" 424 ); 425 426 is( ref(tied %h), 'Hash::WithDefaults::preserve', "Tied to the right class"); 427 428 is( $h{low}, 'value', '$h{low}'); 429 is( $h{Low}, 'value', '$h{Low}'); 430 is( $h{LOW}, 'value', '$h{LOW}'); 431 432 is( $h{mix}, 'other', '$h{mix}'); 433 is( $h{Mix}, 'other', '$h{Mix}'); 434 is( $h{MIX}, 'other', '$h{MIX}'); 435 436 is( $h{hi}, 'Some', '$h{hi}'); 437 is( $h{Hi}, 'Some', '$h{Hi}'); 438 is( $h{HI}, 'Some', '$h{HI}'); 439 440 my @got = sort keys %h; 441 my @good = qw(HI Mix low); 442 443 is_deeply(\@got, \@good, "List of keys"); 444 445 @got = (); 446 while (my ($key, $val) = each %h) { 447 push @got, "$key=$val"; 448 } 449 @got = sort @got; 450 @good = ('HI=Some', 'Mix=other', 'low=value'); 451 is_deeply(\@got, \@good, "each() returns both keys and values"); 452 453 is( scalar( keys %h), 3, "Number of keys"); 454 455 delete $h{Low}; 456 is( scalar( keys %h), 2, "Number of keys after delete"); 457 is( $h{low}, undef, '$h{low}'); 458 is( $h{Low}, undef, '$h{Low}'); 459 is( $h{LOW}, undef, '$h{LOW}'); 460 461 delete $h{Mix}; 462 is( scalar( keys %h), 1, "Number of keys after delete"); 463 is( $h{mix}, undef, '$h{mix}'); 464 is( $h{Mix}, undef, '$h{Mix}'); 465 is( $h{MIX}, undef, '$h{MIX}'); 466 467 %h = (); 468 is( scalar( keys %h), 0, "Number of keys after clear"); 469 is_deeply( [keys %h], [], "There are no keys"); 470 471 $h{a} = 1; $h{B} = 2; 472 is( scalar( keys %h), 2, "Number of keys after refil"); 473 is_deeply( [sort keys %h], [qw(B a)], "There are two keys"); 474 475} 476 477{ # preserve (HASHREF) 478 my %h; 479 ok( 480 tie( %h, 'Hash::WithDefaults', 'preserve', {low => 'value', Mix => 'other', HI => 'Some'}), 481 "Tied with case=preserve" 482 ); 483 484 is( ref(tied %h), 'Hash::WithDefaults::preserve', "Tied to the right class"); 485 486 is( $h{low}, 'value', '$h{low}'); 487 is( $h{Low}, 'value', '$h{Low}'); 488 is( $h{LOW}, 'value', '$h{LOW}'); 489 490 is( $h{mix}, 'other', '$h{mix}'); 491 is( $h{Mix}, 'other', '$h{Mix}'); 492 is( $h{MIX}, 'other', '$h{MIX}'); 493 494 is( $h{hi}, 'Some', '$h{hi}'); 495 is( $h{Hi}, 'Some', '$h{Hi}'); 496 is( $h{HI}, 'Some', '$h{HI}'); 497 498 my @got = sort keys %h; 499 my @good = qw(HI Mix low); 500 501 is_deeply(\@got, \@good, "List of keys"); 502 503 @got = (); 504 while (my ($key, $val) = each %h) { 505 push @got, "$key=$val"; 506 } 507 @got = sort @got; 508 @good = ('HI=Some', 'Mix=other', 'low=value'); 509 is_deeply(\@got, \@good, "each() returns both keys and values"); 510 511 is( scalar( keys %h), 3, "Number of keys"); 512 513 delete $h{Low}; 514 is( scalar( keys %h), 2, "Number of keys after delete"); 515 is( $h{low}, undef, '$h{low}'); 516 is( $h{Low}, undef, '$h{Low}'); 517 is( $h{LOW}, undef, '$h{LOW}'); 518 519 delete $h{Mix}; 520 is( scalar( keys %h), 1, "Number of keys after delete"); 521 is( $h{mix}, undef, '$h{mix}'); 522 is( $h{Mix}, undef, '$h{Mix}'); 523 is( $h{MIX}, undef, '$h{MIX}'); 524 525 %h = (); 526 is( scalar( keys %h), 0, "Number of keys after clear"); 527 is_deeply( [keys %h], [], "There are no keys"); 528 529 $h{a} = 1; $h{B} = 2; 530 is( scalar( keys %h), 2, "Number of keys after refil"); 531 is_deeply( [sort keys %h], [qw(B a)], "There are two keys"); 532 533} 534 535{ # preserve (LIST) 536 my %h; 537 ok( 538 tie( %h, 'Hash::WithDefaults', 'preserve', low => 'value', Mix => 'other', HI => 'Some'), 539 "Tied with case=preserve" 540 ); 541 542 is( ref(tied %h), 'Hash::WithDefaults::preserve', "Tied to the right class"); 543 544 is( $h{low}, 'value', '$h{low}'); 545 is( $h{Low}, 'value', '$h{Low}'); 546 is( $h{LOW}, 'value', '$h{LOW}'); 547 548 is( $h{mix}, 'other', '$h{mix}'); 549 is( $h{Mix}, 'other', '$h{Mix}'); 550 is( $h{MIX}, 'other', '$h{MIX}'); 551 552 is( $h{hi}, 'Some', '$h{hi}'); 553 is( $h{Hi}, 'Some', '$h{Hi}'); 554 is( $h{HI}, 'Some', '$h{HI}'); 555 556 my @got = sort keys %h; 557 my @good = qw(HI Mix low); 558 559 is_deeply(\@got, \@good, "List of keys"); 560 561 @got = (); 562 while (my ($key, $val) = each %h) { 563 push @got, "$key=$val"; 564 } 565 @got = sort @got; 566 @good = ('HI=Some', 'Mix=other', 'low=value'); 567 is_deeply(\@got, \@good, "each() returns both keys and values"); 568 569 is( scalar( keys %h), 3, "Number of keys"); 570 571 delete $h{Low}; 572 is( scalar( keys %h), 2, "Number of keys after delete"); 573 is( $h{low}, undef, '$h{low}'); 574 is( $h{Low}, undef, '$h{Low}'); 575 is( $h{LOW}, undef, '$h{LOW}'); 576 577 delete $h{Mix}; 578 is( scalar( keys %h), 1, "Number of keys after delete"); 579 is( $h{mix}, undef, '$h{mix}'); 580 is( $h{Mix}, undef, '$h{Mix}'); 581 is( $h{MIX}, undef, '$h{MIX}'); 582 583 %h = (); 584 is( scalar( keys %h), 0, "Number of keys after clear"); 585 is_deeply( [keys %h], [], "There are no keys"); 586 587 $h{a} = 1; $h{B} = 2; 588 is( scalar( keys %h), 2, "Number of keys after refil"); 589 is_deeply( [sort keys %h], [qw(B a)], "There are two keys"); 590 591} 592 593 594{ # tolower (ARRAYREF) 595 my %h; 596 ok( 597 tie( %h, 'Hash::WithDefaults', 'tolower', [low => 'value', Mix => 'other', HI => 'Some']), 598 "Tied with case=tolower" 599 ); 600 601 is( ref(tied %h), 'Hash::WithDefaults::tolower', "Tied to the right class"); 602 603 is( $h{low}, 'value', '$h{low}'); 604 is( $h{Low}, undef, '$h{Low}'); 605 is( $h{LOW}, undef, '$h{LOW}'); 606 607 is( $h{mix}, 'other', '$h{mix}'); 608 is( $h{Mix}, undef, '$h{Mix}'); 609 is( $h{MIX}, undef, '$h{MIX}'); 610 611 is( $h{hi}, 'Some', '$h{hi}'); 612 is( $h{Hi}, undef, '$h{Hi}'); 613 is( $h{HI}, undef, '$h{HI}'); 614 615 my @got = sort keys %h; 616 my @good = qw(hi low mix); 617 618 is_deeply(\@got, \@good, "List of keys"); 619 620 @got = (); 621 while (my ($key, $val) = each %h) { 622 push @got, "$key=$val"; 623 } 624 @got = sort @got; 625 @good = ('hi=Some', 'low=value', 'mix=other'); 626 is_deeply(\@got, \@good, "each() returns both keys and values"); 627 628 is( scalar( keys %h), 3, "Number of keys"); 629 630 delete $h{low}; 631 is( scalar( keys %h), 2, "Number of keys after delete"); 632 is( $h{low}, undef, '$h{low}'); 633 is( $h{Low}, undef, '$h{Low}'); 634 is( $h{LOW}, undef, '$h{LOW}'); 635 636 delete $h{Mix}; 637 is( scalar( keys %h), 2, "Number of keys after delete"); 638 is( $h{mix}, 'other', '$h{mix}'); 639 is( $h{Mix}, undef, '$h{Mix}'); 640 is( $h{MIX}, undef, '$h{MIX}'); 641 642 %h = (); 643 is( scalar( keys %h), 0, "Number of keys after clear"); 644 is_deeply( [keys %h], [], "There are no keys"); 645 646 $h{a} = 1; $h{B} = 2; 647 is( scalar( keys %h), 2, "Number of keys after refil"); 648 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 649 650} 651 652{ # tolower (HASHREF) 653 my %h; 654 ok( 655 tie( %h, 'Hash::WithDefaults', 'tolower', {low => 'value', Mix => 'other', HI => 'Some'}), 656 "Tied with case=tolower" 657 ); 658 659 is( ref(tied %h), 'Hash::WithDefaults::tolower', "Tied to the right class"); 660 661 is( $h{low}, 'value', '$h{low}'); 662 is( $h{Low}, undef, '$h{Low}'); 663 is( $h{LOW}, undef, '$h{LOW}'); 664 665 is( $h{mix}, 'other', '$h{mix}'); 666 is( $h{Mix}, undef, '$h{Mix}'); 667 is( $h{MIX}, undef, '$h{MIX}'); 668 669 is( $h{hi}, 'Some', '$h{hi}'); 670 is( $h{Hi}, undef, '$h{Hi}'); 671 is( $h{HI}, undef, '$h{HI}'); 672 673 my @got = sort keys %h; 674 my @good = qw(hi low mix); 675 676 is_deeply(\@got, \@good, "List of keys"); 677 678 @got = (); 679 while (my ($key, $val) = each %h) { 680 push @got, "$key=$val"; 681 } 682 @got = sort @got; 683 @good = ('hi=Some', 'low=value', 'mix=other'); 684 is_deeply(\@got, \@good, "each() returns both keys and values"); 685 686 is( scalar( keys %h), 3, "Number of keys"); 687 688 delete $h{low}; 689 is( scalar( keys %h), 2, "Number of keys after delete"); 690 is( $h{low}, undef, '$h{low}'); 691 is( $h{Low}, undef, '$h{Low}'); 692 is( $h{LOW}, undef, '$h{LOW}'); 693 694 delete $h{Mix}; 695 is( scalar( keys %h), 2, "Number of keys after delete"); 696 is( $h{mix}, 'other', '$h{mix}'); 697 is( $h{Mix}, undef, '$h{Mix}'); 698 is( $h{MIX}, undef, '$h{MIX}'); 699 700 %h = (); 701 is( scalar( keys %h), 0, "Number of keys after clear"); 702 is_deeply( [keys %h], [], "There are no keys"); 703 704 $h{a} = 1; $h{B} = 2; 705 is( scalar( keys %h), 2, "Number of keys after refil"); 706 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 707 708} 709 710{ # tolower (LIST) 711 my %h; 712 ok( 713 tie( %h, 'Hash::WithDefaults', 'tolower', low => 'value', Mix => 'other', HI => 'Some'), 714 "Tied with case=tolower" 715 ); 716 717 is( ref(tied %h), 'Hash::WithDefaults::tolower', "Tied to the right class"); 718 719 is( $h{low}, 'value', '$h{low}'); 720 is( $h{Low}, undef, '$h{Low}'); 721 is( $h{LOW}, undef, '$h{LOW}'); 722 723 is( $h{mix}, 'other', '$h{mix}'); 724 is( $h{Mix}, undef, '$h{Mix}'); 725 is( $h{MIX}, undef, '$h{MIX}'); 726 727 is( $h{hi}, 'Some', '$h{hi}'); 728 is( $h{Hi}, undef, '$h{Hi}'); 729 is( $h{HI}, undef, '$h{HI}'); 730 731 my @got = sort keys %h; 732 my @good = qw(hi low mix); 733 734 is_deeply(\@got, \@good, "List of keys"); 735 736 @got = (); 737 while (my ($key, $val) = each %h) { 738 push @got, "$key=$val"; 739 } 740 @got = sort @got; 741 @good = ('hi=Some', 'low=value', 'mix=other'); 742 is_deeply(\@got, \@good, "each() returns both keys and values"); 743 744 is( scalar( keys %h), 3, "Number of keys"); 745 746 delete $h{low}; 747 is( scalar( keys %h), 2, "Number of keys after delete"); 748 is( $h{low}, undef, '$h{low}'); 749 is( $h{Low}, undef, '$h{Low}'); 750 is( $h{LOW}, undef, '$h{LOW}'); 751 752 delete $h{Mix}; 753 is( scalar( keys %h), 2, "Number of keys after delete"); 754 is( $h{mix}, 'other', '$h{mix}'); 755 is( $h{Mix}, undef, '$h{Mix}'); 756 is( $h{MIX}, undef, '$h{MIX}'); 757 758 %h = (); 759 is( scalar( keys %h), 0, "Number of keys after clear"); 760 is_deeply( [keys %h], [], "There are no keys"); 761 762 $h{a} = 1; $h{B} = 2; 763 is( scalar( keys %h), 2, "Number of keys after refil"); 764 is_deeply( [sort keys %h], [qw(a b)], "There are two keys"); 765 766} 767 768 769{ # toupper (ARRAYREF) 770 my %h; 771 ok( 772 tie( %h, 'Hash::WithDefaults', 'toupper', [low => 'value', Mix => 'other', HI => 'Some']), 773 "Tied with case=toupper" 774 ); 775 776 is( ref(tied %h), 'Hash::WithDefaults::toupper', "Tied to the right class"); 777 778 is( $h{low}, undef, '$h{low}'); 779 is( $h{Low}, undef, '$h{Low}'); 780 is( $h{LOW}, 'value', '$h{LOW}'); 781 782 is( $h{mix}, undef, '$h{mix}'); 783 is( $h{Mix}, undef, '$h{Mix}'); 784 is( $h{MIX}, 'other', '$h{MIX}'); 785 786 is( $h{hi}, undef, '$h{hi}'); 787 is( $h{Hi}, undef, '$h{Hi}'); 788 is( $h{HI}, 'Some', '$h{HI}'); 789 790 my @got = sort keys %h; 791 my @good = qw(HI LOW MIX); 792 793 is_deeply(\@got, \@good, "List of keys"); 794 795 @got = (); 796 while (my ($key, $val) = each %h) { 797 push @got, "$key=$val"; 798 } 799 @got = sort @got; 800 @good = ('HI=Some', 'LOW=value', 'MIX=other'); 801 is_deeply(\@got, \@good, "each() returns both keys and values"); 802 803 is( scalar( keys %h), 3, "Number of keys"); 804 805 delete $h{LOW}; 806 is( scalar( keys %h), 2, "Number of keys after delete"); 807 is( $h{low}, undef, '$h{low}'); 808 is( $h{Low}, undef, '$h{Low}'); 809 is( $h{LOW}, undef, '$h{LOW}'); 810 811 delete $h{Mix}; 812 is( scalar( keys %h), 2, "Number of keys after delete"); 813 is( $h{mix}, undef, '$h{mix}'); 814 is( $h{Mix}, undef, '$h{Mix}'); 815 is( $h{MIX}, 'other', '$h{MIX}'); 816 817 %h = (); 818 is( scalar( keys %h), 0, "Number of keys after clear"); 819 is_deeply( [keys %h], [], "There are no keys"); 820 821 $h{a} = 1; $h{B} = 2; 822 is( scalar( keys %h), 2, "Number of keys after refil"); 823 is_deeply( [sort keys %h], [qw(A B)], "There are two keys"); 824 825} 826 827{ # toupper (HASHREF) 828 my %h; 829 ok( 830 tie( %h, 'Hash::WithDefaults', 'toupper', {low => 'value', Mix => 'other', HI => 'Some'}), 831 "Tied with case=toupper" 832 ); 833 834 is( ref(tied %h), 'Hash::WithDefaults::toupper', "Tied to the right class"); 835 836 is( $h{low}, undef, '$h{low}'); 837 is( $h{Low}, undef, '$h{Low}'); 838 is( $h{LOW}, 'value', '$h{LOW}'); 839 840 is( $h{mix}, undef, '$h{mix}'); 841 is( $h{Mix}, undef, '$h{Mix}'); 842 is( $h{MIX}, 'other', '$h{MIX}'); 843 844 is( $h{hi}, undef, '$h{hi}'); 845 is( $h{Hi}, undef, '$h{Hi}'); 846 is( $h{HI}, 'Some', '$h{HI}'); 847 848 my @got = sort keys %h; 849 my @good = qw(HI LOW MIX); 850 851 is_deeply(\@got, \@good, "List of keys"); 852 853 @got = (); 854 while (my ($key, $val) = each %h) { 855 push @got, "$key=$val"; 856 } 857 @got = sort @got; 858 @good = ('HI=Some', 'LOW=value', 'MIX=other'); 859 is_deeply(\@got, \@good, "each() returns both keys and values"); 860 861 is( scalar( keys %h), 3, "Number of keys"); 862 863 delete $h{LOW}; 864 is( scalar( keys %h), 2, "Number of keys after delete"); 865 is( $h{low}, undef, '$h{low}'); 866 is( $h{Low}, undef, '$h{Low}'); 867 is( $h{LOW}, undef, '$h{LOW}'); 868 869 delete $h{Mix}; 870 is( scalar( keys %h), 2, "Number of keys after delete"); 871 is( $h{mix}, undef, '$h{mix}'); 872 is( $h{Mix}, undef, '$h{Mix}'); 873 is( $h{MIX}, 'other', '$h{MIX}'); 874 875 %h = (); 876 is( scalar( keys %h), 0, "Number of keys after clear"); 877 is_deeply( [keys %h], [], "There are no keys"); 878 879 $h{a} = 1; $h{B} = 2; 880 is( scalar( keys %h), 2, "Number of keys after refil"); 881 is_deeply( [sort keys %h], [qw(A B)], "There are two keys"); 882 883} 884 885{ # toupper (LIST) 886 my %h; 887 ok( 888 tie( %h, 'Hash::WithDefaults', 'toupper', low => 'value', Mix => 'other', HI => 'Some'), 889 "Tied with case=toupper" 890 ); 891 892 is( ref(tied %h), 'Hash::WithDefaults::toupper', "Tied to the right class"); 893 894 is( $h{low}, undef, '$h{low}'); 895 is( $h{Low}, undef, '$h{Low}'); 896 is( $h{LOW}, 'value', '$h{LOW}'); 897 898 is( $h{mix}, undef, '$h{mix}'); 899 is( $h{Mix}, undef, '$h{Mix}'); 900 is( $h{MIX}, 'other', '$h{MIX}'); 901 902 is( $h{hi}, undef, '$h{hi}'); 903 is( $h{Hi}, undef, '$h{Hi}'); 904 is( $h{HI}, 'Some', '$h{HI}'); 905 906 my @got = sort keys %h; 907 my @good = qw(HI LOW MIX); 908 909 is_deeply(\@got, \@good, "List of keys"); 910 911 @got = (); 912 while (my ($key, $val) = each %h) { 913 push @got, "$key=$val"; 914 } 915 @got = sort @got; 916 @good = ('HI=Some', 'LOW=value', 'MIX=other'); 917 is_deeply(\@got, \@good, "each() returns both keys and values"); 918 919 is( scalar( keys %h), 3, "Number of keys"); 920 921 delete $h{LOW}; 922 is( scalar( keys %h), 2, "Number of keys after delete"); 923 is( $h{low}, undef, '$h{low}'); 924 is( $h{Low}, undef, '$h{Low}'); 925 is( $h{LOW}, undef, '$h{LOW}'); 926 927 delete $h{Mix}; 928 is( scalar( keys %h), 2, "Number of keys after delete"); 929 is( $h{mix}, undef, '$h{mix}'); 930 is( $h{Mix}, undef, '$h{Mix}'); 931 is( $h{MIX}, 'other', '$h{MIX}'); 932 933 %h = (); 934 is( scalar( keys %h), 0, "Number of keys after clear"); 935 is_deeply( [keys %h], [], "There are no keys"); 936 937 $h{a} = 1; $h{B} = 2; 938 is( scalar( keys %h), 2, "Number of keys after refil"); 939 is_deeply( [sort keys %h], [qw(A B)], "There are two keys"); 940 941} 942 943 944{ # sensitive (ARRAYREF) 945 my %h; 946 ok( 947 tie( %h, 'Hash::WithDefaults', 'sensitive', [low => 'value', Mix => 'other', HI => 'Some']), 948 "Tied with case=sensitive" 949 ); 950 951 is( ref(tied %h), 'Hash::WithDefaults::sensitive', "Tied to the right class"); 952 953 is( $h{low}, 'value', '$h{low}'); 954 is( $h{Low}, undef, '$h{Low}'); 955 is( $h{LOW}, undef, '$h{LOW}'); 956 957 is( $h{mix}, undef, '$h{mix}'); 958 is( $h{Mix}, 'other', '$h{Mix}'); 959 is( $h{MIX}, undef, '$h{MIX}'); 960 961 is( $h{hi}, undef, '$h{hi}'); 962 is( $h{Hi}, undef, '$h{Hi}'); 963 is( $h{HI}, 'Some', '$h{HI}'); 964 965 my @got = sort keys %h; 966 my @good = qw(HI Mix low); 967 968 is_deeply(\@got, \@good, "List of keys"); 969 970 @got = (); 971 while (my ($key, $val) = each %h) { 972 push @got, "$key=$val"; 973 } 974 @got = sort @got; 975 @good = ('HI=Some', 'Mix=other', 'low=value'); 976 is_deeply(\@got, \@good, "each() returns both keys and values"); 977 978 is( scalar( keys %h), 3, "Number of keys"); 979 980 delete $h{low}; 981 is( scalar( keys %h), 2, "Number of keys after delete"); 982 is( $h{low}, undef, '$h{low}'); 983 is( $h{Low}, undef, '$h{Low}'); 984 is( $h{LOW}, undef, '$h{LOW}'); 985 986 delete $h{MIX}; 987 is( scalar( keys %h), 2, "Number of keys after delete"); 988 is( $h{mix}, undef, '$h{mix}'); 989 is( $h{Mix}, 'other', '$h{Mix}'); 990 is( $h{MIX}, undef, '$h{MIX}'); 991 992 %h = (); 993 is( scalar( keys %h), 0, "Number of keys after clear"); 994 is_deeply( [keys %h], [], "There are no keys"); 995 996 $h{a} = 1; $h{B} = 2; 997 is( scalar( keys %h), 2, "Number of keys after refil"); 998 is_deeply( [sort keys %h], [qw(B a)], "There are two keys"); 999 1000} 1001 1002{ # sensitive (HASHREF) 1003 my %h; 1004 ok( 1005 tie( %h, 'Hash::WithDefaults', 'sensitive', {low => 'value', Mix => 'other', HI => 'Some'}), 1006 "Tied with case=sensitive" 1007 ); 1008 1009 is( ref(tied %h), 'Hash::WithDefaults::sensitive', "Tied to the right class"); 1010 1011 is( $h{low}, 'value', '$h{low}'); 1012 is( $h{Low}, undef, '$h{Low}'); 1013 is( $h{LOW}, undef, '$h{LOW}'); 1014 1015 is( $h{mix}, undef, '$h{mix}'); 1016 is( $h{Mix}, 'other', '$h{Mix}'); 1017 is( $h{MIX}, undef, '$h{MIX}'); 1018 1019 is( $h{hi}, undef, '$h{hi}'); 1020 is( $h{Hi}, undef, '$h{Hi}'); 1021 is( $h{HI}, 'Some', '$h{HI}'); 1022 1023 my @got = sort keys %h; 1024 my @good = qw(HI Mix low); 1025 1026 is_deeply(\@got, \@good, "List of keys"); 1027 1028 @got = (); 1029 while (my ($key, $val) = each %h) { 1030 push @got, "$key=$val"; 1031 } 1032 @got = sort @got; 1033 @good = ('HI=Some', 'Mix=other', 'low=value'); 1034 is_deeply(\@got, \@good, "each() returns both keys and values"); 1035 1036 is( scalar( keys %h), 3, "Number of keys"); 1037 1038 delete $h{low}; 1039 is( scalar( keys %h), 2, "Number of keys after delete"); 1040 is( $h{low}, undef, '$h{low}'); 1041 is( $h{Low}, undef, '$h{Low}'); 1042 is( $h{LOW}, undef, '$h{LOW}'); 1043 1044 delete $h{MIX}; 1045 is( scalar( keys %h), 2, "Number of keys after delete"); 1046 is( $h{mix}, undef, '$h{mix}'); 1047 is( $h{Mix}, 'other', '$h{Mix}'); 1048 is( $h{MIX}, undef, '$h{MIX}'); 1049 1050 %h = (); 1051 is( scalar( keys %h), 0, "Number of keys after clear"); 1052 is_deeply( [keys %h], [], "There are no keys"); 1053 1054 $h{a} = 1; $h{B} = 2; 1055 is( scalar( keys %h), 2, "Number of keys after refil"); 1056 is_deeply( [sort keys %h], [qw(B a)], "There are two keys"); 1057 1058} 1059 1060{ # sensitive (LIST) 1061 my %h; 1062 ok( 1063 tie( %h, 'Hash::WithDefaults', 'sensitive', low => 'value', Mix => 'other', HI => 'Some'), 1064 "Tied with case=sensitive" 1065 ); 1066 1067 is( ref(tied %h), 'Hash::WithDefaults::sensitive', "Tied to the right class"); 1068 1069 is( $h{low}, 'value', '$h{low}'); 1070 is( $h{Low}, undef, '$h{Low}'); 1071 is( $h{LOW}, undef, '$h{LOW}'); 1072 1073 is( $h{mix}, undef, '$h{mix}'); 1074 is( $h{Mix}, 'other', '$h{Mix}'); 1075 is( $h{MIX}, undef, '$h{MIX}'); 1076 1077 is( $h{hi}, undef, '$h{hi}'); 1078 is( $h{Hi}, undef, '$h{Hi}'); 1079 is( $h{HI}, 'Some', '$h{HI}'); 1080 1081 my @got = sort keys %h; 1082 my @good = qw(HI Mix low); 1083 1084 is_deeply(\@got, \@good, "List of keys"); 1085 1086 @got = (); 1087 while (my ($key, $val) = each %h) { 1088 push @got, "$key=$val"; 1089 } 1090 @got = sort @got; 1091 @good = ('HI=Some', 'Mix=other', 'low=value'); 1092 is_deeply(\@got, \@good, "each() returns both keys and values"); 1093 1094 is( scalar( keys %h), 3, "Number of keys"); 1095 1096 delete $h{low}; 1097 is( scalar( keys %h), 2, "Number of keys after delete"); 1098 is( $h{low}, undef, '$h{low}'); 1099 is( $h{Low}, undef, '$h{Low}'); 1100 is( $h{LOW}, undef, '$h{LOW}'); 1101 1102 delete $h{MIX}; 1103 is( scalar( keys %h), 2, "Number of keys after delete"); 1104 is( $h{mix}, undef, '$h{mix}'); 1105 is( $h{Mix}, 'other', '$h{Mix}'); 1106 is( $h{MIX}, undef, '$h{MIX}'); 1107 1108 %h = (); 1109 is( scalar( keys %h), 0, "Number of keys after clear"); 1110 is_deeply( [keys %h], [], "There are no keys"); 1111 1112 $h{a} = 1; $h{B} = 2; 1113 is( scalar( keys %h), 2, "Number of keys after refil"); 1114 is_deeply( [sort keys %h], [qw(B a)], "There are two keys"); 1115 1116} 1117