diff options
Diffstat (limited to 't/lib')
-rwxr-xr-x | t/lib/anydbm.t | 114 | ||||
-rwxr-xr-x | t/lib/db-btree.t | 351 | ||||
-rwxr-xr-x | t/lib/db-hash.t | 253 | ||||
-rwxr-xr-x | t/lib/db-recno.t | 142 | ||||
-rwxr-xr-x | t/lib/english.t | 4 | ||||
-rwxr-xr-x | t/lib/gdbm.t | 117 | ||||
-rwxr-xr-x | t/lib/ndbm.t | 7 | ||||
-rwxr-xr-x | t/lib/odbm.t | 120 | ||||
-rwxr-xr-x | t/lib/posix.t | 74 | ||||
-rwxr-xr-x | t/lib/sdbm.t | 9 | ||||
-rwxr-xr-x | t/lib/soundex.t | 143 |
11 files changed, 1327 insertions, 7 deletions
diff --git a/t/lib/anydbm.t b/t/lib/anydbm.t new file mode 100755 index 0000000000..11ac103a64 --- /dev/null +++ b/t/lib/anydbm.t @@ -0,0 +1,114 @@ +#!./perl + +# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $ + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} +require AnyDBM_File; +#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT +use Fcntl; + +print "1..12\n"; + +unlink <Op.dbmx*>; + +umask(0); +print (tie(%h,AnyDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n"); + +$Dfile = "Op.dbmx.pag"; +if (! -e $Dfile) { + ($Dfile) = <Op.dbmx*>; +} +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n"); +while (($key,$value) = each(%h)) { + $i++; +} +print (!$i ? "ok 3\n" : "not ok 3\n"); + +$h{'goner1'} = 'snork'; + +$h{'abc'} = 'ABC'; +$h{'def'} = 'DEF'; +$h{'jkl','mno'} = "JKL\034MNO"; +$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); +$h{'a'} = 'A'; +$h{'b'} = 'B'; +$h{'c'} = 'C'; +$h{'d'} = 'D'; +$h{'e'} = 'E'; +$h{'f'} = 'F'; +$h{'g'} = 'G'; +$h{'h'} = 'H'; +$h{'i'} = 'I'; + +$h{'goner2'} = 'snork'; +delete $h{'goner2'}; + +untie(%h); +print (tie(%h,AnyDBM_File,'Op.dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n"); + +$h{'j'} = 'J'; +$h{'k'} = 'K'; +$h{'l'} = 'L'; +$h{'m'} = 'M'; +$h{'n'} = 'N'; +$h{'o'} = 'O'; +$h{'p'} = 'P'; +$h{'q'} = 'Q'; +$h{'r'} = 'R'; +$h{'s'} = 'S'; +$h{'t'} = 'T'; +$h{'u'} = 'U'; +$h{'v'} = 'V'; +$h{'w'} = 'W'; +$h{'x'} = 'X'; +$h{'y'} = 'Y'; +$h{'z'} = 'Z'; + +$h{'goner3'} = 'snork'; + +delete $h{'goner1'}; +delete $h{'goner3'}; + +@keys = keys(%h); +@values = values(%h); + +if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";} + +while (($key,$value) = each(h)) { + if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) { + $key =~ y/a-z/A-Z/; + $i++ if $key eq $value; + } +} + +if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";} + +@keys = ('blurfl', keys(h), 'dyick'); +if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";} + +$h{'foo'} = ''; +$h{''} = 'bar'; + +# check cache overflow and numeric keys and contents +$ok = 1; +for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } +for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } +print ($ok ? "ok 8\n" : "not ok 8\n"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print ($size > 0 ? "ok 9\n" : "not ok 9\n"); + +@h{0..200} = 200..400; +@foo = @h{0..200}; +print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n"; + +print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n"); +print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n"); + +unlink 'Op.dbmx.dir', $Dfile; diff --git a/t/lib/db-btree.t b/t/lib/db-btree.t new file mode 100755 index 0000000000..308b8f489a --- /dev/null +++ b/t/lib/db-btree.t @@ -0,0 +1,351 @@ +#!./perl + +BEGIN { + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bDB_File\b/) { + print "1..0\n"; + exit 0; + } +} + +use DB_File; +use Fcntl; + +print "1..73\n"; + +$Dfile = "Op.db-btree"; +unlink $Dfile; + +umask(0); + +# Check the interface to BTREEINFO + +$dbh = TIEHASH DB_File::BTREEINFO ; +print (($dbh->{flags} == undef) ? "ok 1\n" : "not ok 1\n") ; +print (($dbh->{cachesize} == undef) ? "ok 2\n" : "not ok 2\n") ; +print (($dbh->{psize} == undef) ? "ok 3\n" : "not ok 3\n") ; +print (($dbh->{lorder} == undef) ? "ok 4\n" : "not ok 4\n") ; +print (($dbh->{minkeypage} == undef) ? "ok 5\n" : "not ok 5\n") ; +print (($dbh->{maxkeypage} == undef) ? "ok 6\n" : "not ok 6\n") ; +print (($dbh->{compare} == undef) ? "ok 7\n" : "not ok 7\n") ; +print (($dbh->{prefix} == undef) ? "ok 8\n" : "not ok 8\n") ; + +$dbh->{flags} = 3000 ; +print ($dbh->{flags} == 3000 ? "ok 9\n" : "not ok 9\n") ; + +$dbh->{cachesize} = 9000 ; +print ($dbh->{cachesize} == 9000 ? "ok 10\n" : "not ok 10\n") ; +# +$dbh->{psize} = 400 ; +print (($dbh->{psize} == 400) ? "ok 11\n" : "not ok 11\n") ; + +$dbh->{lorder} = 65 ; +print (($dbh->{lorder} == 65) ? "ok 12\n" : "not ok 12\n") ; + +$dbh->{minkeypage} = 123 ; +print (($dbh->{minkeypage} == 123) ? "ok 13\n" : "not ok 13\n") ; + +$dbh->{maxkeypage} = 1234 ; +print ($dbh->{maxkeypage} == 1234 ? "ok 14\n" : "not ok 14\n") ; + +$dbh->{compare} = 1234 ; +print ($dbh->{compare} == 1234 ? "ok 15\n" : "not ok 15\n") ; + +$dbh->{prefix} = 1234 ; +print ($dbh->{prefix} == 1234 ? "ok 16\n" : "not ok 16\n") ; + +# Check that an invalid entry is caught both for store & fetch +eval '$dbh->{fred} = 1234' ; +print ($@ eq '' ? "ok 17\n" : "not ok 17\n") ; +eval '$q = $dbh->{fred}' ; +print ($@ eq '' ? "ok 18\n" : "not ok 18\n") ; + +# Now check the interface to BTREE + +print (($X = tie(%h, DB_File,$Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ? "ok 19\n" : "not ok 19"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print (($mode & 0777) == 0640 ? "ok 20\n" : "not ok 20\n"); + +while (($key,$value) = each(%h)) { + $i++; +} +print (!$i ? "ok 21\n" : "not ok 21\n"); + +$h{'goner1'} = 'snork'; + +$h{'abc'} = 'ABC'; +print ($h{'abc'} == 'ABC' ? "ok 22\n" : "not ok 22\n") ; +print (defined $h{'jimmy'} ? "not ok 23\n" : "ok 23\n"); + +$h{'def'} = 'DEF'; +$h{'jkl','mno'} = "JKL\034MNO"; +$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); +$h{'a'} = 'A'; + +#$h{'b'} = 'B'; +$X->STORE('b', 'B') ; + +$h{'c'} = 'C'; + +#$h{'d'} = 'D'; +$X->put('d', 'D') ; + +$h{'e'} = 'E'; +$h{'f'} = 'F'; +$h{'g'} = 'X'; +$h{'h'} = 'H'; +$h{'i'} = 'I'; + +$h{'goner2'} = 'snork'; +delete $h{'goner2'}; + + +# IMPORTANT - $X must be undefined before the untie otherwise the +# underlying DB close routine will not get called. +undef $X ; +untie(%h); + + +# tie to the same file again +print (($X = tie(%h,DB_File,$Dfile, O_RDWR, 0640, $DB_BTREE)) ? "ok 24\n" : "not ok 24\n"); + +# Modify an entry from the previous tie +$h{'g'} = 'G'; + +$h{'j'} = 'J'; +$h{'k'} = 'K'; +$h{'l'} = 'L'; +$h{'m'} = 'M'; +$h{'n'} = 'N'; +$h{'o'} = 'O'; +$h{'p'} = 'P'; +$h{'q'} = 'Q'; +$h{'r'} = 'R'; +$h{'s'} = 'S'; +$h{'t'} = 'T'; +$h{'u'} = 'U'; +$h{'v'} = 'V'; +$h{'w'} = 'W'; +$h{'x'} = 'X'; +$h{'y'} = 'Y'; +$h{'z'} = 'Z'; + +$h{'goner3'} = 'snork'; + +delete $h{'goner1'}; +$X->DELETE('goner3'); + +@keys = keys(%h); +@values = values(%h); + +if ($#keys == 29 && $#values == 29) {print "ok 25\n";} else {print "not ok 25\n";} + +while (($key,$value) = each(%h)) { + if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) { + $key =~ y/a-z/A-Z/; + $i++ if $key eq $value; + } +} + +if ($i == 30) {print "ok 26\n";} else {print "not ok 26\n";} + +@keys = ('blurfl', keys(h), 'dyick'); +if ($#keys == 31) {print "ok 27\n";} else {print "not ok 27\n";} + +#Check that the keys can be retrieved in order +$ok = 1 ; +foreach (keys %h) +{ + ($ok = 0), last if defined $previous && $previous gt $_ ; + $previous = $_ ; +} +print ($ok ? "ok 28\n" : "not ok 28\n") ; + +$h{'foo'} = ''; +print ($h{'foo'} eq '' ? "ok 29\n" : "not ok 29\n") ; + +$h{''} = 'bar'; +print ($h{''} eq 'bar' ? "ok 30\n" : "not ok 30\n") ; + +# check cache overflow and numeric keys and contents +$ok = 1; +for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } +for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } +print ($ok ? "ok 31\n" : "not ok 31\n"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print ($size > 0 ? "ok 32\n" : "not ok 32\n"); + +@h{0..200} = 200..400; +@foo = @h{0..200}; +print join(':',200..400) eq join(':',@foo) ? "ok 33\n" : "not ok 33\n"; + +# Now check all the non-tie specific stuff + + +# Check R_NOOVERWRITE flag will make put fail when attempting to overwrite +# an existing record. + +$status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ; +print ($status == 1 ? "ok 34\n" : "not ok 34\n") ; + +# check that the value of the key 'x' has not been changed by the +# previous test +print ($h{'x'} eq 'X' ? "ok 35\n" : "not ok 35\n") ; + +# standard put +$status = $X->put('key', 'value') ; +print ($status == 0 ? "ok 36\n" : "not ok 36\n") ; + +#check that previous put can be retrieved +$status = $X->get('key', $value) ; +print ($status == 0 ? "ok 37\n" : "not ok 37\n") ; +print ($value eq 'value' ? "ok 38\n" : "not ok 38\n") ; + +# Attempting to delete an existing key should work + +$status = $X->del('q') ; +print ($status == 0 ? "ok 39\n" : "not ok 39\n") ; +$status = $X->del('') ; +print ($status == 0 ? "ok 40\n" : "not ok 40\n") ; + +# Make sure that the key deleted, cannot be retrieved +print (($h{'q'} eq undef) ? "ok 41\n" : "not ok 41\n") ; +print (($h{''} eq undef) ? "ok 42\n" : "not ok 42\n") ; + +undef $X ; +untie %h ; + +print (($X = tie(%h, DB_File,$Dfile, O_RDWR, 0640, $DB_BTREE )) ? "ok 43\n" : "not ok 43"); + +# Attempting to delete a non-existant key should fail + +$status = $X->del('joe') ; +print ($status == 1 ? "ok 44\n" : "not ok 44\n") ; + +# Check the get interface + +# First a non-existing key +$status = $X->get('aaaa', $value) ; +print ($status == 1 ? "ok 45\n" : "not ok 45\n") ; + +# Next an existing key +$status = $X->get('a', $value) ; +print ($status == 0 ? "ok 46\n" : "not ok 46\n") ; +print ($value eq 'A' ? "ok 47\n" : "not ok 47\n") ; + +# seq +# ### + +# use seq to find an approximate match +$key = 'ke' ; +$value = '' ; +$status = $X->seq($key, $value, R_CURSOR) ; +print ($status == 0 ? "ok 48\n" : "not ok 48\n") ; +print ($key eq 'key' ? "ok 49\n" : "not ok 49\n") ; +print ($value eq 'value' ? "ok 50\n" : "not ok 50\n") ; + +# seq when the key does not match +$key = 'zzz' ; +$value = '' ; +$status = $X->seq($key, $value, R_CURSOR) ; +print ($status == 1 ? "ok 51\n" : "not ok 51\n") ; + + +# use seq to set the cursor, then delete the record @ the cursor. + +$key = 'x' ; +$value = '' ; +$status = $X->seq($key, $value, R_CURSOR) ; +print ($status == 0 ? "ok 52\n" : "not ok 52\n") ; +print ($key eq 'x' ? "ok 53\n" : "not ok 53\n") ; +print ($value eq 'X' ? "ok 54\n" : "not ok 54\n") ; +$status = $X->del(0, R_CURSOR) ; +print ($status == 0 ? "ok 55\n" : "not ok 55\n") ; +$status = $X->get('x', $value) ; +print ($status == 1 ? "ok 56\n" : "not ok 56\n") ; + +# ditto, but use put to replace the key/value pair. +$key = 'y' ; +$value = '' ; +$status = $X->seq($key, $value, R_CURSOR) ; +print ($status == 0 ? "ok 57\n" : "not ok 57\n") ; +print ($key eq 'y' ? "ok 58\n" : "not ok 58\n") ; +print ($value eq 'Y' ? "ok 59\n" : "not ok 59\n") ; + +$key = "replace key" ; +$value = "replace value" ; +$status = $X->put($key, $value, R_CURSOR) ; +print ($status == 0 ? "ok 60\n" : "not ok 60\n") ; +print ($key eq 'replace key' ? "ok 61\n" : "not ok 61\n") ; +print ($value eq 'replace value' ? "ok 62\n" : "not ok 62\n") ; +$status = $X->get('y', $value) ; +print ($status == 1 ? "ok 63\n" : "not ok 63\n") ; + +# use seq to walk forwards through a file + +$status = $X->seq($key, $value, R_FIRST) ; +print ($status == 0 ? "ok 64\n" : "not ok 64\n") ; +$previous = $key ; + +$ok = 1 ; +while (($status = $X->seq($key, $value, R_NEXT)) == 0) +{ + ($ok = 0), last if ($previous cmp $key) == 1 ; +} + +print ($status == 1 ? "ok 65\n" : "not ok 65\n") ; +print ($ok == 1 ? "ok 66\n" : "not ok 66\n") ; + +# use seq to walk backwards through a file +$status = $X->seq($key, $value, R_LAST) ; +print ($status == 0 ? "ok 67\n" : "not ok 67\n") ; +$previous = $key ; + +$ok = 1 ; +while (($status = $X->seq($key, $value, R_PREV)) == 0) +{ + ($ok = 0), last if ($previous cmp $key) == -1 ; + #print "key = [$key] value = [$value]\n" ; +} + +print ($status == 1 ? "ok 68\n" : "not ok 68\n") ; +print ($ok == 1 ? "ok 69\n" : "not ok 69\n") ; + + +# check seq FIRST/LAST + +# sync +# #### + +$status = $X->sync ; +print ($status == 0 ? "ok 70\n" : "not ok 70\n") ; + + +# fd +# ## + +$status = $X->fd ; +print ($status != 0 ? "ok 71\n" : "not ok 71\n") ; + + +undef $X ; +untie %h ; + +unlink $Dfile; + +# Now try an in memory file +print (($Y = tie(%h, DB_File,undef, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ? "ok 72\n" : "not ok 72"); + +# fd with an in memory file should return failure +$status = $Y->fd ; +print ($status == -1 ? "ok 73\n" : "not ok 73\n") ; + +undef $Y ; +untie %h ; + +exit ; diff --git a/t/lib/db-hash.t b/t/lib/db-hash.t new file mode 100755 index 0000000000..6c3ef55200 --- /dev/null +++ b/t/lib/db-hash.t @@ -0,0 +1,253 @@ +#!./perl + +BEGIN { + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bDB_File\b/) { + print "1..0\n"; + exit 0; + } +} + +use DB_File; +use Fcntl; + +print "1..43\n"; + +$Dfile = "Op.db-hash"; +unlink $Dfile; + +umask(0); + +# Check the interface to HASHINFO + +$dbh = TIEHASH DB_File::HASHINFO ; +print (($dbh->{bsize} == undef) ? "ok 1\n" : "not ok 1\n") ; +print (($dbh->{ffactor} == undef) ? "ok 2\n" : "not ok 2\n") ; +print (($dbh->{nelem} == undef) ? "ok 3\n" : "not ok 3\n") ; +print (($dbh->{cachesize} == undef) ? "ok 4\n" : "not ok 4\n") ; +print (($dbh->{hash} == undef) ? "ok 5\n" : "not ok 5\n") ; +print (($dbh->{lorder} == undef) ? "ok 6\n" : "not ok 6\n") ; + +$dbh->{bsize} = 3000 ; +print ($dbh->{bsize} == 3000 ? "ok 7\n" : "not ok 7\n") ; + +$dbh->{ffactor} = 9000 ; +print ($dbh->{ffactor} == 9000 ? "ok 8\n" : "not ok 8\n") ; +# +$dbh->{nelem} = 400 ; +print (($dbh->{nelem} == 400) ? "ok 9\n" : "not ok 9\n") ; + +$dbh->{cachesize} = 65 ; +print (($dbh->{cachesize} == 65) ? "ok 10\n" : "not ok 10\n") ; + +$dbh->{hash} = "abc" ; +print (($dbh->{hash} eq "abc") ? "ok 11\n" : "not ok 11\n") ; + +$dbh->{lorder} = 1234 ; +print ($dbh->{lorder} == 1234 ? "ok 12\n" : "not ok 12\n") ; + +# Check that an invalid entry is caught both for store & fetch +eval '$dbh->{fred} = 1234' ; +print ($@ eq '' ? "ok 13\n" : "not ok 13\n") ; +eval '$q = $dbh->{fred}' ; +print ($@ eq '' ? "ok 14\n" : "not ok 14\n") ; + +# Now check the interface to HASH + +print (($X = tie(%h, DB_File,$Dfile, O_RDWR|O_CREAT, 0640, $DB_HASH )) ? "ok 15\n" : "not ok 15"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print (($mode & 0777) == 0640 ? "ok 16\n" : "not ok 16\n"); + +while (($key,$value) = each(%h)) { + $i++; +} +print (!$i ? "ok 17\n" : "not ok 17\n"); + +$h{'goner1'} = 'snork'; + +$h{'abc'} = 'ABC'; +print ($h{'abc'} == 'ABC' ? "ok 18\n" : "not ok 18\n") ; +print (defined $h{'jimmy'} ? "not ok 19\n" : "ok 19\n"); + +$h{'def'} = 'DEF'; +$h{'jkl','mno'} = "JKL\034MNO"; +$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); +$h{'a'} = 'A'; + +#$h{'b'} = 'B'; +$X->STORE('b', 'B') ; + +$h{'c'} = 'C'; + +#$h{'d'} = 'D'; +$X->put('d', 'D') ; + +$h{'e'} = 'E'; +$h{'f'} = 'F'; +$h{'g'} = 'X'; +$h{'h'} = 'H'; +$h{'i'} = 'I'; + +$h{'goner2'} = 'snork'; +delete $h{'goner2'}; + + +# IMPORTANT - $X must be undefined before the untie otherwise the +# underlying DB close routine will not get called. +undef $X ; +untie(%h); + + +# tie to the same file again, do not supply a type - should default to HASH +print (($X = tie(%h,DB_File,$Dfile, O_RDWR, 0640)) ? "ok 20\n" : "not ok 20: $!\n"); + +# Modify an entry from the previous tie +$h{'g'} = 'G'; + +$h{'j'} = 'J'; +$h{'k'} = 'K'; +$h{'l'} = 'L'; +$h{'m'} = 'M'; +$h{'n'} = 'N'; +$h{'o'} = 'O'; +$h{'p'} = 'P'; +$h{'q'} = 'Q'; +$h{'r'} = 'R'; +$h{'s'} = 'S'; +$h{'t'} = 'T'; +$h{'u'} = 'U'; +$h{'v'} = 'V'; +$h{'w'} = 'W'; +$h{'x'} = 'X'; +$h{'y'} = 'Y'; +$h{'z'} = 'Z'; + +$h{'goner3'} = 'snork'; + +delete $h{'goner1'}; +$X->DELETE('goner3'); + +@keys = keys(%h); +@values = values(%h); + +if ($#keys == 29 && $#values == 29) {print "ok 21\n";} else {print "not ok 21\n";} + +while (($key,$value) = each(h)) { + if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) { + $key =~ y/a-z/A-Z/; + $i++ if $key eq $value; + } +} + +if ($i == 30) {print "ok 22\n";} else {print "not ok 22\n";} + +@keys = ('blurfl', keys(h), 'dyick'); +if ($#keys == 31) {print "ok 23\n";} else {print "not ok 23\n";} + +$h{'foo'} = ''; +print ($h{'foo'} eq '' ? "ok 24\n" : "not ok 24\n") ; + +$h{''} = 'bar'; +print ($h{''} eq 'bar' ? "ok 25\n" : "not ok 25\n") ; + +# check cache overflow and numeric keys and contents +$ok = 1; +for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } +for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } +print ($ok ? "ok 26\n" : "not ok 26\n"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print ($size > 0 ? "ok 27\n" : "not ok 27\n"); + +@h{0..200} = 200..400; +@foo = @h{0..200}; +print join(':',200..400) eq join(':',@foo) ? "ok 28\n" : "not ok 28\n"; + + +# Now check all the non-tie specific stuff + +# Check NOOVERWRITE will make put fail when attempting to overwrite +# an existing record. + +$status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ; +print ($status == 1 ? "ok 29\n" : "not ok 29\n") ; + +# check that the value of the key 'x' has not been changed by the +# previous test +print ($h{'x'} eq 'X' ? "ok 30\n" : "not ok 30\n") ; + +# standard put +$status = $X->put('key', 'value') ; +print ($status == 0 ? "ok 31\n" : "not ok 31\n") ; + +#check that previous put can be retrieved +$status = $X->get('key', $value) ; +print ($status == 0 ? "ok 32\n" : "not ok 32\n") ; +print ($value eq 'value' ? "ok 33\n" : "not ok 33\n") ; + +# Attempting to delete an existing key should work + +$status = $X->del('q') ; +print ($status == 0 ? "ok 34\n" : "not ok 34\n") ; + +# Make sure that the key deleted, cannot be retrieved +print (($h{'q'} eq undef) ? "ok 35\n" : "not ok 35\n") ; + +# Attempting to delete a non-existant key should fail + +$status = $X->del('joe') ; +print ($status == 1 ? "ok 36\n" : "not ok 36\n") ; + +# Check the get interface + +# First a non-existing key +$status = $X->get('aaaa', $value) ; +print ($status == 1 ? "ok 37\n" : "not ok 37\n") ; + +# Next an existing key +$status = $X->get('a', $value) ; +print ($status == 0 ? "ok 38\n" : "not ok 38\n") ; +print ($value eq 'A' ? "ok 39\n" : "not ok 39\n") ; + +# seq +# ### + +# ditto, but use put to replace the key/value pair. + +# use seq to walk backwards through a file - check that this reversed is + +# check seq FIRST/LAST + +# sync +# #### + +$status = $X->sync ; +print ($status == 0 ? "ok 40\n" : "not ok 40\n") ; + + +# fd +# ## + +$status = $X->fd ; +print ($status != 0 ? "ok 41\n" : "not ok 41\n") ; + +undef $X ; +untie %h ; + +unlink $Dfile; + +# Now try an in memory file +print (($X = tie(%h, DB_File,undef, O_RDWR|O_CREAT, 0640, $DB_HASH )) ? "ok 42\n" : "not ok 42"); + +# fd with an in memory file should return fail +$status = $X->fd ; +print ($status == -1 ? "ok 43\n" : "not ok 43\n") ; + +untie %h ; +undef $X ; + +exit ; diff --git a/t/lib/db-recno.t b/t/lib/db-recno.t new file mode 100755 index 0000000000..64ad7b8a9e --- /dev/null +++ b/t/lib/db-recno.t @@ -0,0 +1,142 @@ +#!./perl + +BEGIN { + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bDB_File\b/) { + print "1..0\n"; + exit 0; + } +} + +use DB_File; +use Fcntl; + +print "1..30\n"; + +$Dfile = "Op.db-recno"; +unlink $Dfile; + +umask(0); + +# Check the interface to RECNOINFO + +$dbh = TIEHASH DB_File::RECNOINFO ; +print (($dbh->{bval} == undef) ? "ok 1\n" : "not ok 1\n") ; +print (($dbh->{cachesize} == undef) ? "ok 2\n" : "not ok 2\n") ; +print (($dbh->{psize} == undef) ? "ok 3\n" : "not ok 3\n") ; +print (($dbh->{flags} == undef) ? "ok 4\n" : "not ok 4\n") ; +print (($dbh->{lorder} == undef) ? "ok 5\n" : "not ok 5\n") ; +print (($dbh->{reclen} == undef) ? "ok 6\n" : "not ok 6\n") ; +print (($dbh->{bfname} == undef) ? "ok 7\n" : "not ok 7\n") ; + +$dbh->{bval} = 3000 ; +print ($dbh->{bval} == 3000 ? "ok 8\n" : "not ok 8\n") ; + +$dbh->{cachesize} = 9000 ; +print ($dbh->{cachesize} == 9000 ? "ok 9\n" : "not ok 9\n") ; + +$dbh->{psize} = 400 ; +print (($dbh->{psize} == 400) ? "ok 10\n" : "not ok 10\n") ; + +$dbh->{flags} = 65 ; +print (($dbh->{flags} == 65) ? "ok 11\n" : "not ok 11\n") ; + +$dbh->{lorder} = 123 ; +print (($dbh->{lorder} == 123) ? "ok 12\n" : "not ok 12\n") ; + +$dbh->{reclen} = 1234 ; +print ($dbh->{reclen} == 1234 ? "ok 13\n" : "not ok 13\n") ; + +$dbh->{bfname} = 1234 ; +print ($dbh->{bfname} == 1234 ? "ok 14\n" : "not ok 14\n") ; + + +# Check that an invalid entry is caught both for store & fetch +eval '$dbh->{fred} = 1234' ; +print ($@ eq '' ? "ok 15\n" : "not ok 15\n") ; +eval '$q = $dbh->{fred}' ; +print ($@ eq '' ? "ok 16\n" : "not ok 16\n") ; + +# Now check the interface to RECNOINFO + +print (($X = tie(@h, DB_File,$Dfile, O_RDWR|O_CREAT, 0640, $DB_RECNO )) ? "ok 17\n" : "not ok 17"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print (($mode & 0777) == 0640 ? "ok 18\n" : "not ok 18\n"); + +#$l = @h ; +$l = $X->length ; +print (!$l ? "ok 19\n" : "not ok 19\n"); + +@data = qw( a b c d ever f g h i j k longername m n o p) ; + +$h[0] = shift @data ; +print ($h[0] eq 'a' ? "ok 20\n" : "not ok 20\n") ; + +foreach (@data) + { $h[++$i] = $_ } + +unshift (@data, 'a') ; + +print (defined $h[1] ? "ok 21\n" : "not ok 21\n"); +print (! defined $h[16] ? "ok 22\n" : "not ok 22\n"); +print ($X->length == @data ? "ok 23\n" : "not ok 23\n") ; + + +# Overwrite an entry & check fetch it +$h[3] = 'replaced' ; +$data[3] = 'replaced' ; +print ($h[3] eq 'replaced' ? "ok 24\n" : "not ok 24\n"); + +#PUSH +@push_data = qw(added to the end) ; +#push (@h, @push_data) ; +$X->push(@push_data) ; +push (@data, @push_data) ; +print ($h[++$i] eq 'added' ? "ok 25\n" : "not ok 25\n"); + +# POP +pop (@data) ; +#$value = pop(@h) ; +$value = $X->pop ; +print ($value eq 'end' ? "not ok 26\n" : "ok 26\n"); + +# SHIFT +#$value = shift @h +$value = $X->shift ; +print ($value eq shift @data ? "not ok 27\n" : "ok 27\n"); + +# UNSHIFT + +# empty list +$X->unshift ; +print ($X->length == @data ? "ok 28\n" : "not ok 28\n") ; + +@new_data = qw(add this to the start of the array) ; +#unshift @h, @new_data ; +$X->unshift (@new_data) ; +unshift (@data, @new_data) ; +print ($X->length == @data ? "ok 29\n" : "not ok 29\n") ; + +# SPLICE + +# Now both arrays should be identical + +$ok = 1 ; +$j = 0 ; +foreach (@data) +{ + $ok = 0, last if $_ ne $h[$j ++] ; +} +print ($ok ? "ok 30\n" : "not ok 30\n") ; + +# IMPORTANT - $X must be undefined before the untie otherwise the +# underlying DB close routine will not get called. +undef $X ; +untie(@h); + +unlink $Dfile; + +exit ; diff --git a/t/lib/english.t b/t/lib/english.t index 5c76407357..d7a30f9305 100755 --- a/t/lib/english.t +++ b/t/lib/english.t @@ -3,7 +3,7 @@ print "1..16\n"; BEGIN { @INC = '../lib' } -require English; import English; +use English; print $PID == $$ ? "ok 1\n" : "not ok 1\n"; @@ -29,7 +29,7 @@ $LIST_SEPARATOR = "\n"; print "@foo"; undef $OUTPUT_RECORD_SEPARATOR; -eval 'no such function'; +eval 'NO SUCH FUNCTION'; print "ok 10\n" if $EVAL_ERROR =~ /method/; print $UID == $< ? "ok 11\n" : "not ok 11\n"; diff --git a/t/lib/gdbm.t b/t/lib/gdbm.t new file mode 100755 index 0000000000..0d2c1fe023 --- /dev/null +++ b/t/lib/gdbm.t @@ -0,0 +1,117 @@ +#!./perl + +# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $ + +BEGIN { + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bGDBM_File\b/) { + print "1..0\n"; + exit 0; + } +} + +use GDBM_File; + +print "1..12\n"; + +unlink <Op.dbmx*>; + +umask(0); +print (tie(%h,GDBM_File,'Op.dbmx', &GDBM_WRCREAT, 0640) ? "ok 1\n" : "not ok 1\n"); + +$Dfile = "Op.dbmx.pag"; +if (! -e $Dfile) { + ($Dfile) = <Op.dbmx*>; +} +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n"); +while (($key,$value) = each(%h)) { + $i++; +} +print (!$i ? "ok 3\n" : "not ok 3\n"); + +$h{'goner1'} = 'snork'; + +$h{'abc'} = 'ABC'; +$h{'def'} = 'DEF'; +$h{'jkl','mno'} = "JKL\034MNO"; +$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); +$h{'a'} = 'A'; +$h{'b'} = 'B'; +$h{'c'} = 'C'; +$h{'d'} = 'D'; +$h{'e'} = 'E'; +$h{'f'} = 'F'; +$h{'g'} = 'G'; +$h{'h'} = 'H'; +$h{'i'} = 'I'; + +$h{'goner2'} = 'snork'; +delete $h{'goner2'}; + +untie(%h); +print (tie(%h,GDBM_File,'Op.dbmx', &GDBM_WRCREAT, 0640) ? "ok 4\n" : "not ok 4\n"); + +$h{'j'} = 'J'; +$h{'k'} = 'K'; +$h{'l'} = 'L'; +$h{'m'} = 'M'; +$h{'n'} = 'N'; +$h{'o'} = 'O'; +$h{'p'} = 'P'; +$h{'q'} = 'Q'; +$h{'r'} = 'R'; +$h{'s'} = 'S'; +$h{'t'} = 'T'; +$h{'u'} = 'U'; +$h{'v'} = 'V'; +$h{'w'} = 'W'; +$h{'x'} = 'X'; +$h{'y'} = 'Y'; +$h{'z'} = 'Z'; + +$h{'goner3'} = 'snork'; + +delete $h{'goner1'}; +delete $h{'goner3'}; + +@keys = keys(%h); +@values = values(%h); + +if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";} + +while (($key,$value) = each(h)) { + if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) { + $key =~ y/a-z/A-Z/; + $i++ if $key eq $value; + } +} + +if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";} + +@keys = ('blurfl', keys(h), 'dyick'); +if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";} + +$h{'foo'} = ''; +$h{''} = 'bar'; + +# check cache overflow and numeric keys and contents +$ok = 1; +for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } +for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } +print ($ok ? "ok 8\n" : "not ok 8\n"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print ($size > 0 ? "ok 9\n" : "not ok 9\n"); + +@h{0..200} = 200..400; +@foo = @h{0..200}; +print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n"; + +print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n"); +print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n"); + +unlink 'Op.dbmx.dir', $Dfile; diff --git a/t/lib/ndbm.t b/t/lib/ndbm.t index c69e2f8739..e3093dbcfb 100755 --- a/t/lib/ndbm.t +++ b/t/lib/ndbm.t @@ -3,6 +3,7 @@ # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $ BEGIN { + chdir 't' if -d 't'; @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bNDBM_File\b/) { @@ -12,13 +13,15 @@ BEGIN { } require NDBM_File; +#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT +use Fcntl; print "1..12\n"; unlink <Op.dbmx*>; umask(0); -print (tie(%h,NDBM_File,'Op.dbmx', 0x202, 0640) ? "ok 1\n" : "not ok 1\n"); +print (tie(%h,NDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n"); $Dfile = "Op.dbmx.pag"; if (! -e $Dfile) { @@ -52,7 +55,7 @@ $h{'goner2'} = 'snork'; delete $h{'goner2'}; untie(%h); -print (tie(%h,NDBM_File,'Op.dbmx', 0x2, 0640) ? "ok 4\n" : "not ok 4\n"); +print (tie(%h,NDBM_File,'Op.dbmx', &O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n"); $h{'j'} = 'J'; $h{'k'} = 'K'; diff --git a/t/lib/odbm.t b/t/lib/odbm.t new file mode 100755 index 0000000000..b49aa91043 --- /dev/null +++ b/t/lib/odbm.t @@ -0,0 +1,120 @@ +#!./perl + +# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $ + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bODBM_File\b/) { + print "1..0\n"; + exit 0; + } +} + +require ODBM_File; +#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT +use Fcntl; + +print "1..12\n"; + +unlink <Op.dbmx*>; + +umask(0); +print (tie(%h,ODBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n"); + +$Dfile = "Op.dbmx.pag"; +if (! -e $Dfile) { + ($Dfile) = <Op.dbmx*>; +} +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n"); +while (($key,$value) = each(%h)) { + $i++; +} +print (!$i ? "ok 3\n" : "not ok 3\n"); + +$h{'goner1'} = 'snork'; + +$h{'abc'} = 'ABC'; +$h{'def'} = 'DEF'; +$h{'jkl','mno'} = "JKL\034MNO"; +$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); +$h{'a'} = 'A'; +$h{'b'} = 'B'; +$h{'c'} = 'C'; +$h{'d'} = 'D'; +$h{'e'} = 'E'; +$h{'f'} = 'F'; +$h{'g'} = 'G'; +$h{'h'} = 'H'; +$h{'i'} = 'I'; + +$h{'goner2'} = 'snork'; +delete $h{'goner2'}; + +untie(%h); +print (tie(%h,ODBM_File,'Op.dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n"); + +$h{'j'} = 'J'; +$h{'k'} = 'K'; +$h{'l'} = 'L'; +$h{'m'} = 'M'; +$h{'n'} = 'N'; +$h{'o'} = 'O'; +$h{'p'} = 'P'; +$h{'q'} = 'Q'; +$h{'r'} = 'R'; +$h{'s'} = 'S'; +$h{'t'} = 'T'; +$h{'u'} = 'U'; +$h{'v'} = 'V'; +$h{'w'} = 'W'; +$h{'x'} = 'X'; +$h{'y'} = 'Y'; +$h{'z'} = 'Z'; + +$h{'goner3'} = 'snork'; + +delete $h{'goner1'}; +delete $h{'goner3'}; + +@keys = keys(%h); +@values = values(%h); + +if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";} + +while (($key,$value) = each(h)) { + if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) { + $key =~ y/a-z/A-Z/; + $i++ if $key eq $value; + } +} + +if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";} + +@keys = ('blurfl', keys(h), 'dyick'); +if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";} + +$h{'foo'} = ''; +$h{''} = 'bar'; + +# check cache overflow and numeric keys and contents +$ok = 1; +for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } +for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } +print ($ok ? "ok 8\n" : "not ok 8\n"); + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat($Dfile); +print ($size > 0 ? "ok 9\n" : "not ok 9\n"); + +@h{0..200} = 200..400; +@foo = @h{0..200}; +print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n"; + +print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n"); +print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n"); + +unlink 'Op.dbmx.dir', $Dfile; diff --git a/t/lib/posix.t b/t/lib/posix.t new file mode 100755 index 0000000000..bde6e0bbac --- /dev/null +++ b/t/lib/posix.t @@ -0,0 +1,74 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bPOSIX\b/) { + print STDERR "1..0\n"; + exit 0; + } +} +use FileHandle; +use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read write); +use strict subs; + +$mystdout = new_from_fd FileHandle 1,"w"; +autoflush STDOUT; +autoflush $mystdout; +print "1..16\n"; + +print $mystdout "ok ",fileno($mystdout),"\n"; +write(1,"ok 2\nnot ok 2\n", 5); + +$testfd = open("TEST", O_RDONLY, 0) and print "ok 3\n"; +read($testfd, $buffer, 9) if $testfd > 2; +print $buffer eq "#!./perl\n" ? "ok 4\n" : "not ok 4\n"; + +@fds = POSIX::pipe(); +print $fds[0] == $testfd + 1 ? "ok 5\n" : "not ok 5\n"; +$writer = FileHandle->new_from_fd($fds[1], "w"); +$reader = FileHandle->new_from_fd($fds[0], "r"); +print $writer "ok 6\n"; +close $writer; +print <$reader>; +close $reader; + +$sigset = new POSIX::SigSet 1,3; +delset $sigset 1; +if (!ismember $sigset 1) { print "ok 7\n" } +if (ismember $sigset 3) { print "ok 8\n" } +$mask = new POSIX::SigSet &SIGINT; +$action = new POSIX::SigAction 'main::SigHUP', $mask, 0; +sigaction(&SIGHUP, $action); +$SIG{'INT'} = 'SigINT'; +kill 'HUP', $$; +sleep 1; +print "ok 12\n"; + +sub SigHUP { + print "ok 9\n"; + kill 'INT', $$; + sleep 2; + print "ok 10\n"; +} + +sub SigINT { + print "ok 11\n"; +} + +print &_POSIX_OPEN_MAX > $fds[1] ? "ok 13\n" : "not ok 13\n"; + +print getcwd() =~ m#/t$# ? "ok 14\n" : "not ok 14\n"; + +# Pick up whether we're really able to dynamically load everything. +print &POSIX::acos(1.0) == 0.0 ? "ok 15\n" : "not ok 15\n"; + +ungetc STDIN 65; +CORE::read(STDIN, $buf,1); +print $buf eq 'A' ? "ok 16\n" : "not ok 16\n"; + +flush STDOUT; +autoflush STDOUT 0; +print '@#!*$@(!@#$'; +_exit(0); diff --git a/t/lib/sdbm.t b/t/lib/sdbm.t index 1304be29b2..a754bb72a4 100755 --- a/t/lib/sdbm.t +++ b/t/lib/sdbm.t @@ -3,21 +3,24 @@ # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $ BEGIN { + chdir 't' if -d 't'; @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bSDBM_File\b/) { - print STDERR "1..0\n"; + print "1..0\n"; exit 0; } } require SDBM_File; +#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT +use Fcntl; print "1..12\n"; unlink <Op.dbmx*>; umask(0); -print (tie(%h,SDBM_File,'Op.dbmx', 0x202, 0640) ? "ok 1\n" : "not ok 1\n"); +print (tie(%h,SDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n"); $Dfile = "Op.dbmx.pag"; if (! -e $Dfile) { @@ -51,7 +54,7 @@ $h{'goner2'} = 'snork'; delete $h{'goner2'}; untie(%h); -print (tie(%h,SDBM_File,'Op.dbmx', 0x2, 0640) ? "ok 4\n" : "not ok 4\n"); +print (tie(%h,SDBM_File,'Op.dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n"); $h{'j'} = 'J'; $h{'k'} = 'K'; diff --git a/t/lib/soundex.t b/t/lib/soundex.t new file mode 100755 index 0000000000..d35f264c7a --- /dev/null +++ b/t/lib/soundex.t @@ -0,0 +1,143 @@ +#!./perl +# +# $Id: soundex.t,v 1.2 1994/03/24 00:30:27 mike Exp $ +# +# test module for soundex.pl +# +# $Log: soundex.t,v $ +# Revision 1.2 1994/03/24 00:30:27 mike +# Subtle bug (any excuse :-) spotted by Rich Pinder <rpinder@hsc.usc.edu> +# in the way I handles leasing characters which were different but had +# the same soundex code. This showed up comparing it with Oracle's +# soundex output. +# +# Revision 1.1 1994/03/02 13:03:02 mike +# Initial revision +# +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Text::Soundex; + +$test = 0; +print "1..13\n"; + +while (<DATA>) +{ + chop; + next if /^\s*;?#/; + next if /^\s*$/; + + ++$test; + $bad = 0; + + if (/^eval\s+/) + { + ($try = $_) =~ s/^eval\s+//; + + eval ($try); + if ($@) + { + $bad++; + print "not ok $test\n"; + print "# eval '$try' returned $@"; + } + } + elsif (/^\(/) + { + ($in, $out) = split (':'); + + $try = "\@expect = $out; \@got = &soundex $in;"; + eval ($try); + + if (@expect != @got) + { + $bad++; + print "not ok $test\n"; + print "# expected ", scalar @expect, " results, got ", scalar @got, "\n"; + print "# expected (", join (', ', @expect), + ") got (", join (', ', @got), ")\n"; + } + else + { + while (@got) + { + $expect = shift @expect; + $got = shift @got; + + if ($expect ne $got) + { + $bad++; + print "not ok $test\n"; + print "# expected $expect, got $got\n"; + } + } + } + } + else + { + ($in, $out) = split (':'); + + $try = "\$expect = $out; \$got = &soundex ($in);"; + eval ($try); + + if ($expect ne $got) + { + $bad++; + print "not ok $test\n"; + print "# expected $expect, got $got\n"; + } + } + + print "ok $test\n" unless $bad; +} + +__END__ +# +# 1..6 +# +# Knuth's test cases, scalar in, scalar out +# +'Euler':'E460' +'Gauss':'G200' +'Hilbert':'H416' +'Knuth':'K530' +'Lloyd':'L300' +'Lukasiewicz':'L222' +# +# 7..8 +# +# check default bad code +# +'2 + 2 = 4':undef +undef:undef +# +# 9 +# +# check array in, array out +# +('Ellery', 'Ghosh', 'Heilbronn', 'Kant', 'Ladd', 'Lissajous'):('E460', 'G200', 'H416', 'K530', 'L300', 'L222') +# +# 10 +# +# check array with explicit undef +# +('Mike', undef, 'Stok'):('M200', undef, 'S320') +# +# 11..12 +# +# check setting $Text::Soundex::noCode +# +eval $soundex_nocode = 'Z000'; +('Mike', undef, 'Stok'):('M200', 'Z000', 'S320') +# +# 13 +# +# a subtle difference between me & oracle, spotted by Rich Pinder +# <rpinder@hsc.usc.edu> +# +CZARKOWSKA:C622 |