#!/bin/sh -e
DICTFMT='../dictfmt --without-time --silent --without-ver'
DICTUNFORMAT='../dictunformat'
DICT='../dict'
DICTD="../dictd -L `pwd`/_dictd.log"
DICTFMT_I2W='../dictfmt_index2word --silent'
DICTFMT_I2S='sh ../dictfmt_index2suffix'
DIFF='diff -u'
##################################################
cmp_2_files (){
if $DIFF "$1" "$2" > log.txt; then
true
else
cat 1>&2 <<EOF
$1 and $2 are different,
see test/log.txt file a difference.
EOF
exit 1
fi
}
##################################################
##################################################
echo ' DICTFMT!!!'
##################################################
echo 'Comparing .dict and .index files (except those created by dictfmt -h)'
rm -f _*
$DICTFMT -c5 _db.c5 < testdb.c5.txt
$DICTFMT -h _db.h < testdb.h.txt
$DICTUNFORMAT _db.c5.index < _db.c5.dict > testdb.t.txt
###
dictfmt_X_eq_Y (){
printf " $1 == $2 ..."
$DICTFMT -$2 _db.$2 < testdb.$2.txt
cmp_2_files _db.$1.index _db.$2.index
cmp_2_files _db.$1.dict _db.$2.dict
printf 'passed\n'
}
dictfmt_X_eq_Y c5 e
dictfmt_X_eq_Y c5 f
dictfmt_X_eq_Y c5 j
dictfmt_X_eq_Y c5 p
dictfmt_X_eq_Y c5 t
###
printf " c5 == expected ..."
cmp_2_files db.expect.index _db.c5.index
cmp_2_files db.expect.dict _db.c5.dict
printf "passed\n"
##################################################
printf "Tests for different dictfmt\'s options\n"
dictfmt_diff_opts (){
num=$1
shift
dbname=$1
shift
printf "%s" " test $dbname $num..."
$DICTFMT "$@" _db.${dbname}_$num < testdb.${dbname}.txt
cmp_2_files db.expect.${dbname}_$num.dict _db.${dbname}_$num.dict
cmp_2_files db.expect.${dbname}_$num.index _db.${dbname}_$num.index
printf 'passed\n'
}
# ASCII database
dictfmt_diff_opts '1' smiley -c5
dictfmt_diff_opts '2' smiley --allchars -u 'somewhere in Internet' -c5
dictfmt_diff_opts '3' smiley --allchars --headword-separator '-' -c5
dictfmt_diff_opts '4' smiley --allchars --without-headword \
--without-header --without-url -c5
dictfmt_diff_opts '5' smiley --allchars --without-headword \
--columns 15 --default-strategy lev --without-info -c5
# UTF-8 database
dictfmt_diff_opts '1' hello --utf8 -c5
dictfmt_diff_opts '2' hello --utf8 --allchars -u 'somewhere in Internet' -c5
dictfmt_diff_opts '3' hello --utf8 --allchars --headword-separator '-' -c5
dictfmt_diff_opts '4' hello --utf8 --allchars --without-headword \
--without-header --without-url -c5
dictfmt_diff_opts '5' hello --utf8 --allchars --without-headword \
--columns 15 --default-strategy lev --without-info -c5
# UTF-8 database (mostly cyrillic)
dictfmt_diff_opts '1' cyrillic --utf8 -c5 -s 'rus words' \
-u 'URL here' --default-strategy word
# case sensitive flag
dictfmt_diff_opts '1' mixedcase --utf8 -c5 -s 'mixed case words' \
-u 'URL here' --without-headword --case-sensitive
# --index-data-separator '|' --index-keep-orig
dictfmt_diff_opts '1' indexdata \
--index-data-separator '|' --index-keep-orig --headword-separator '/' \
-c5 -s 'index/data test' \
-u 'URL here' --without-headword
##################################################
##################################################
echo ' DICTD!!!'
generate_commands (){
conf_file=$1
shift
strats=`echo 'show strat' |
$DICTD -i -c $conf_file |
gawk '!/^[0-9.]/ {print $1}' | LC_ALL=C sort`
if test $? -ne 0; then
exit 2
fi
# echo "strats=$strats" 1>&2
# strats="exact prefix suffix substring"
if test $# = 0; then
strats=exact
else
strats="$@"
fi
gawk -v strats="$strats" '
BEGIN {
cnt=split(strats, strats_arr)
}
{
printf "define \ttestdb\t \"%s\"\n", $0
printf "define testdb \"%s\"\n", $0
for (i=1; i <= cnt; ++i){
printf "match\ttestdb %s\t\"%s\"\n", strats_arr [i], $0
}
}'
}
dictd_test_inetd_base (){
confname=$1
shift
dbname=$1
shift
noorder=$1
shift
#
conf_file=_testdb.$confname.conf
m4 -DCURR_DIR=`pwd` testdb.$confname.conf >$conf_file
#
index_file=`sed -n 's,^.*/\(.*[.]index\).*$,\1,p' $conf_file | head -1`
in_file=_dictd_${dbname}_in.txt
cut -f 1 "$index_file" |
generate_commands $conf_file "$@" > "$in_file"
#
$DICTD -c $conf_file -i --stdin2stdout < "$in_file" |
gawk '/^2[25]0 / { print $1 "\r"; next; } {print}' \
| $noorder > _dictd_${dbname}_res.txt
#
cmp_2_files dictd_${dbname}_res.expected.txt _dictd_${dbname}_res.txt
}
dictd_test_inetd (){
confname=$1
shift
txtname=$1
shift
dictd_test_inetd_base $confname $txtname cat "$@"
}
dictd_test_inetd_noorder (){
confname=$1
shift
txtname=$1
shift
dictd_test_inetd_base $confname $txtname 'env LC_ALL=C sort' "$@"
}
dictd_test_inetd2_base (){
confname=$1
shift
txtname=$1
shift
noorder=$1
shift
#
conf_file=_testdb.$confname.conf
m4 -DCURR_DIR=`pwd` testdb.$confname.conf >$conf_file
#
in_file=input.${txtname}.txt
#
$DICTD -c $conf_file -i --stdin2stdout < "$in_file" |
gawk '/^2[25]0 / { print $1; next; } {print}' \
| $noorder > _dictd_${txtname}_res.txt
#
cmp_2_files dictd_${txtname}_res.expected.txt _dictd_${txtname}_res.txt
}
dictd_test_inetd2 (){
confname=$1
shift
txtname=$1
shift
dictd_test_inetd2_base $confname $txtname cat "$@"
}
dictd_test_inetd2_noorder (){
confname=$1
shift
txtname=$1
shift
dictd_test_inetd2_base $confname $txtname 'env LC_ALL=C sort' "$@"
}
#dictd_test_inetd smiley_1 smiley_1
#printf 'smiley_1 passed\n'
dictd_test_inetd smiley_2 smiley_2
printf 'smiley_2 passed\n'
#dictd_test_inetd smiley_3 smiley_3
#printf 'smiley_3 passed\n'
dictd_test_inetd smiley_4 smiley_4
printf 'smiley_4 passed\n'
dictd_test_inetd smiley_5 smiley_5
printf 'smiley_5 passed\n'
dictd_test_inetd hello_1 hello_1
printf 'hello_1 passed\n'
dictd_test_inetd hello_2 hello_2
printf 'hello_2 passed\n'
dictd_test_inetd hello_3 hello_3
printf 'hello_3 passed\n'
dictd_test_inetd hello_4 hello_4
printf 'hello_4 passed\n'
dictd_test_inetd hello_5 hello_5
printf 'hello_5 passed\n'
dictd_test_inetd cyrillic_1 cyrillic_1 exact word lev suffix prefix substring
printf 'cyrillic_1 passed\n'
#LC_ALL=C sort dictd_cyrillic_1_res.expected.txt \
# > dictd_cyrillic_2_res.expected.txt
#$DICTFMT_I2W --utf8 --silent db.expect.cyrillic_1.index \
# > db.expect.cyrillic_1.index_word
#$DICTFMT_I2S --utf8 --silent db.expect.cyrillic_1.index \
# > db.expect.cyrillic_1.index_suffix
#dictd_test_inetd_noorder cyrillic_2 cyrillic_2 exact word lev suffix prefix substring
#printf 'cyrillic_2 passed\n'
dictd_test_inetd2 cyrillic_1 cyrillic_3
printf 'cyrillic_3 passed\n'
LC_ALL=C sort dictd_cyrillic_3_res.expected.txt \
> dictd_cyrillic_4_res.expected.txt
cp input.cyrillic_3.txt input.cyrillic_4.txt
$DICTFMT_I2S --utf8 --silent db.expect.cyrillic_1.index \
> db.expect.cyrillic_1.index_suffix
dictd_test_inetd2_noorder cyrillic_4 cyrillic_4
printf 'cyrillic_4 passed\n'
dictd_test_inetd2 mixedcase_1 mixedcase_1
printf 'mixedcase_1 passed\n'
dictd_test_inetd2 indexdata_1 indexdata_1
printf 'indexdata_1 passed\n'
dictd_test_inetd2 limits_1 limits_1
printf 'limits_1 passed\n'
dictd_test_inetd2 defstrat_1 defstrat_1
printf 'defstrat_1 passed\n'
dictd_test_inetd2 defstrat_2 defstrat_2
printf 'defstrat_2 passed\n'
syntax highlighted by Code2HTML, v. 0.9.1