add test for cursor motion optimization

This commit is contained in:
John Hood
2015-10-15 22:30:27 -04:00
parent e0f6eb78ef
commit e13011f318
2 changed files with 97 additions and 0 deletions
+1
View File
@@ -11,6 +11,7 @@ displaytests = \
e2e-failure.test \
emulation-80th-column.test \
emulation-back-tab.test \
emulation-cursor-motion.test \
emulation-multiline-scroll.test \
server-network-timeout.test \
server-signal-timeout.test \
+96
View File
@@ -0,0 +1,96 @@
#!/bin/sh
#
# This test exercises a particular optimization involving small cursor
# motions in Mosh.
#
fail()
{
printf "$@" 2>&1
exit 99
}
PATH=$PATH:.:$srcdir
# Top-level wrapper.
if [ $# -eq 0 ]; then
e2e-test $0 baseline direct verify
exit
fi
# OK, we have arguments, we're one of the test hooks.
if [ $# -ne 1 ]; then
fail "bad arguments %s\n" "$@"
fi
sleepf()
{
(sleep .1 || sleep 1) > /dev/null 2>&1
}
seq()
{
if [ $# -lt 1 -o $# -gt 3 ]; then
echo "bad args" >&2
fi
first=$1
incr=1
last=0
case $# in
3)
incr=$2
last=$3
;;
2)
last=$2
;;
1)
;;
esac
while :; do
printf '%d\n' $first
first=$(expr $first + $incr)
if [ $first -gt $last ]; then
break
fi
done
}
baseline()
{
printf '\033[H\033[J'
while read x y text; do
printf '\033[%d;%dH%s' $y $x $text
sleepf
done <<EOF
1 1 A
10 1 B
1 2 C
1 4 D
10 4 E
1 7 F
1 11 G
10 11 H
1 16 I
2 16 J
1 22 K
60 23 L
59 23 M
57 23 N
54 23 O
50 23 P
45 23 Q
39 23 R
32 23 S
1 24 done
EOF
}
case $1 in
baseline|direct)
baseline;;
*)
fail "unknown test argument %s\n" $1;;
esac