| 1 | #!./perl |
| 2 | |
| 3 | BEGIN { |
| 4 | chdir 't' if -d 't'; |
| 5 | @INC = '../lib'; |
| 6 | } |
| 7 | |
| 8 | print "1..4\n"; |
| 9 | |
| 10 | $DICT = <<EOT; |
| 11 | Aarhus |
| 12 | Aaron |
| 13 | Ababa |
| 14 | aback |
| 15 | abaft |
| 16 | abandon |
| 17 | abandoned |
| 18 | abandoning |
| 19 | abandonment |
| 20 | abandons |
| 21 | abase |
| 22 | abased |
| 23 | abasement |
| 24 | abasements |
| 25 | abases |
| 26 | abash |
| 27 | abashed |
| 28 | abashes |
| 29 | abashing |
| 30 | abasing |
| 31 | abate |
| 32 | abated |
| 33 | abatement |
| 34 | abatements |
| 35 | abater |
| 36 | abates |
| 37 | abating |
| 38 | Abba |
| 39 | EOT |
| 40 | |
| 41 | use Search::Dict; |
| 42 | |
| 43 | open(DICT, "+>dict-$$") or die "Can't create dict-$$: $!"; |
| 44 | binmode DICT; # To make length expected one. |
| 45 | print DICT $DICT; |
| 46 | |
| 47 | my $pos = look *DICT, "Ababa"; |
| 48 | chomp($word = <DICT>); |
| 49 | print "not " if $pos < 0 || $word ne "Ababa"; |
| 50 | print "ok 1\n"; |
| 51 | |
| 52 | if (ord('a') > ord('A') ) { # ASCII |
| 53 | |
| 54 | $pos = look *DICT, "foo"; |
| 55 | chomp($word = <DICT>); |
| 56 | |
| 57 | print "not " if $pos != length($DICT); # will search to end of file |
| 58 | print "ok 2\n"; |
| 59 | |
| 60 | my $pos = look *DICT, "abash"; |
| 61 | chomp($word = <DICT>); |
| 62 | print "not " if $pos < 0 || $word ne "abash"; |
| 63 | print "ok 3\n"; |
| 64 | |
| 65 | } |
| 66 | else { # EBCDIC systems e.g. os390 |
| 67 | |
| 68 | $pos = look *DICT, "FOO"; |
| 69 | chomp($word = <DICT>); |
| 70 | |
| 71 | print "not " if $pos != length($DICT); # will search to end of file |
| 72 | print "ok 2\n"; |
| 73 | |
| 74 | my $pos = look *DICT, "Abba"; |
| 75 | chomp($word = <DICT>); |
| 76 | print "not " if $pos < 0 || $word ne "Abba"; |
| 77 | print "ok 3\n"; |
| 78 | } |
| 79 | |
| 80 | $pos = look *DICT, "aarhus", 1, 1; |
| 81 | chomp($word = <DICT>); |
| 82 | |
| 83 | print "not " if $pos < 0 || $word ne "Aarhus"; |
| 84 | print "ok 4\n"; |
| 85 | |
| 86 | close DICT or die "cannot close"; |
| 87 | unlink "dict-$$"; |