# Tests for tr command; invoked by command file "fulltests"
#   Written by Dave Tribby (August 1997)
#   $Id: dotests,v 1.4 1998/03/11 17:12:57 tribby Exp $

### NOTE: The "file1" text files should be included in the test archive:
###   file1.UPPER    file1.Ul     file1.mixed  file1.noalpha  file1.nolower 
###   file1.novowel  file1.onlyup 
### Some "file2" and "file3" files use control control characters and
### must be generated by the program genbin. The easiest way to create
### genbin and the following files:
###   file2.bin1     file2.bin2   file2.bin3 
###   file3.alnum    file3.alpha  file3.blank  file3.cntrl    file3.digit
###   file3.full     file3.graph  file3.lower  file3.print    file3.punct
###   file3.space    file3.upper  file3.xdigit 
### is to execute dmake with no additional parameters.

# Location of the tr command to be tested
set testcmd="/obj/gno/usr.bin/tr/tr"

# Record starting time
echo -n "Testing command $testcmd beginning at"
date

set src="file1.mixed"
set cmp="file1.UPPER"
set dest="/tmp/$cmp"
echo "Upshifting all characters in $src using character classes"
$testcmd '[:lower:]' '[:upper:]' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set dest="/tmp/${cmp}B"
echo "Upshifting all characters in $src using character ranges"
$testcmd 'a-z' 'A-Z' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="file1.novowel"
set dest="/tmp/$cmp"
echo "Removing lower-case vowels in $src"
$testcmd -d 'aeiouy' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="file1.nolower"
set dest="/tmp/$cmp"
echo "Removing lower-case letters and squeezing spaces in $src"
$testcmd -ds '[:lower:]' ' ' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="file1.onlyup"
set dest="/tmp/$cmp"
echo "Keeping only upper-case letters and squeezing spaces in $src"
$testcmd -c -ds '[:upper:]' ' ' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="file1.noalpha"
set dest="/tmp/$cmp"
echo "Replace all alpha characters in $src with \"~\" and sqeeze"
$testcmd -s '[:alpha:]' '~' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="file1.Ul"
set dest="/tmp/$cmp"
echo "Replace u.c. chars with \"U\", l.c. chars with \"l\" in $src"
$testcmd "[:upper:][:lower:]" '[U*26][l*26]' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set src="file2.bin1"
set cmp="file2.bin2"
set dest="/tmp/$cmp"
echo "Binary file: setting high-order bit on control characters using range"
$testcmd '\000-\037' '\200-\237' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set dest="/tmp/${cmp}B"
echo "Binary file: setting high-order bit on control characters using class"
$testcmd '[:cntrl:]' '\200-\237' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="file2.bin3"   
set dest="/tmp/$cmp"
echo "Binary file: Translating special characters to alphabetic"
$testcmd '\a\b\f\n\r\t\v' 'ABFNRTV' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""


set src="file3.full"
set class="alnum"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="alpha"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="cntrl"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="digit"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="graph"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="lower"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="print"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="punct"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="space"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="upper"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="xdigit"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set class="blank"
set cmp="file3.$class"
set dest="/tmp/$cmp"
echo "ASCII subset class: $class"
$testcmd -c -d "[:$class:]" < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

echo "***** Error Messages *****"

set dest="/tmp/err.cond"

echo ""
echo "Expected error: illegal option"
$testcmd -x $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: misplaced equivalence equals sign"
$testcmd '[=equiv=]' '[=equiv=]' < $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: sequences only valid in string2"
$testcmd '[X*26]' '[:upper:]' < $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: misplaced sequence asterisk"
$testcmd '[:lower:]' '[26*X]' < $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: illegal sequence count"
$testcmd '[:lower:]' '[X*XX]' < $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: unknown class:"
$testcmd '[:lower:]' '[:badclass:]' < $src > $dest
echo "  Error completion status = $status (expected: 1)"
