home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / MacPerl 4.1.3 / Perl / t / op / dbm.t < prev    next >
Encoding:
Text File  |  1993-10-23  |  2.2 KB  |  80 lines  |  [TEXT/MPS ]

  1. $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
  2. $h{'a'} = 'A';
  3. $h{'b'} = 'B';
  4. $h{'c'} = 'C';
  5. $h{'d'} = 'D';
  6. $h{'e'} = 'E';
  7. $h{'f'} = 'F';
  8. $h{'g'} = 'G';
  9. $h{'h'} = 'H';
  10. $h{'i'} = 'I';
  11.  
  12. $h{'goner2'} = 'snork';
  13. delete $h{'goner2'};
  14.  
  15. dbmclose(h);
  16. print (dbmopen(h,'Op.dbmx',0640) ? "ok 4\n" : "not ok 4\n");
  17.  
  18. $h{'j'} = 'J';
  19. $h{'k'} = 'K';
  20. $h{'l'} = 'L';
  21. $h{'m'} = 'M';
  22. $h{'n'} = 'N';
  23. $h{'o'} = 'O';
  24. $h{'p'} = 'P';
  25. $h{'q'} = 'Q';
  26. $h{'r'} = 'R';
  27. $h{'s'} = 'S';
  28. $h{'t'} = 'T';
  29. $h{'u'} = 'U';
  30. $h{'v'} = 'V';
  31. $h{'w'} = 'W';
  32. $h{'x'} = 'X';
  33. $h{'y'} = 'Y';
  34. $h{'z'} = 'Z';
  35.  
  36. $h{'goner3'} = 'snork';
  37.  
  38. delete $h{'goner1'};
  39. delete $h{'goner3'};
  40.  
  41. @keys = keys(%h);
  42. @values = values(%h);
  43.  
  44. if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
  45.  
  46. while (($key,$value) = each(h)) {
  47.     if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) {
  48.     $key =~ y/a-z/A-Z/;
  49.     $i++ if $key eq $value;
  50.     }
  51. }
  52.  
  53. if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
  54.  
  55. @keys = ('blurfl', keys(h), 'dyick');
  56. if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
  57.  
  58. $h{'foo'} = '';
  59. $h{''} = 'bar';
  60.  
  61. # check cache overflow and numeric keys and contents
  62. $ok = 1;
  63. for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
  64. for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
  65. print ($ok ? "ok 8\n" : "not ok 8\n");
  66.  
  67. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  68.    $blksize,$blocks) = stat('Op.dbmx');
  69.  
  70. print ($size > 0 ? "ok 9\n" : "not ok 9\n");
  71.  
  72. @h{0..200} = 200..400;
  73. @foo = @h{0..200};
  74. print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
  75.  
  76. print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
  77. print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
  78.  
  79. unlink 'Op.dbmx';
  80.