#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl \
exec tclsh "$0" ${1+"$@"}

# See if the towers of hanoi solving vi macros work

source scripts/term
start_vi

# Read the macros
exp_send ":so data/hanoi\r"

# Buffer should still be empty and there should be no error messages
# on the status line
# vim has trailing line,column info.
# nvi leaves the status line blank if successful

test 100 ""		1 0 [list "" "~"]

term_expect timeout {
	puts "After :so hanoi, status line is \"[statusline]\"."
	fail 101
    } \
    { statusline_starts ":so data/hanoi" } { } \
    { statusline_is "" } { }

# Run the initialization code
#test 102 "I" 9 0 \
#	[list "" "01234567" "0" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
# map I KMYNOQNOSkRTV
test 1 "K"	2 0 [list "" "" "~"]
test 2 "M"	1 0 [list "" "~"]
test 3 "Y"	2 7 [list "" "01234567" "~"]
test 4 "NO"	3 0 [list "" "01234567" "01234567" "~"]
test 5 "Q"	3 0 [list "" "01234567" "T01234567" "~"]
test 6 "NO"	4 0 [list "" "01234567" "T01234567" "T01234567" "~"]
test 7 "S"	4 8 [list "" "01234567" "T01234567" "T0123456$" "~"]
test 8 "k"	3 8 [list "" "01234567" "T01234567" "T0123456$" "~"]
test 9 "R"	3 8 [list "" "01234567" "T0123456n" "T0123456$" "~"]
test 10 "T"	6 0 [list "" "01234567" "0" "0" "" "" "T0123456n" "T0123456$" "~"]
test 11 "V"	9 0 [list "" "01234567" "0" "0" "" "" "T0123456n" "T0123456$" "/" "~"]

# Run the first iteration screen-change by screen-change so as to isolate
# any problems
# L 1G/t^MX/^0^M$P1GJ$An$BGC0e$X0E0F$X/T^M@f^M@h^M$A1GJ@f0l$Xn$PU
test 20 "1G"	1 0 [list "" "01234567" "0" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 21 "/t\r"	2 7 [list "" "01234567" "0" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 22 "X"	2 6 [list "" "0123456" "0" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 23 "/^0\r"	3 0 [list "" "0123456" "0" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 24 "\$P"	3 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 25 "1G"	1 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 26 "J"	2 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 27 "\$"	2 6 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 28 "An"	4 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 29 "\$BG"	9 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 30 "C"	9 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/6" "~"]
test 31 "0"	9 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/6" "~"]
test 32 "e$"	9 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/6" "~"]
test 33 "X"	9 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 34 "0E"	9 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/0" "~"]
test 35 "0"	9 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/0" "~"]
test 36 "F\$"	9 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/0" "~"]
test 37 "X"	9 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 38	"/T\r"	7 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 39 "@f\r"	7 7 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 40 "@h\r"	8 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 41 "\$"	8 8 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 42 "A1G"	1 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 43 "J"	2 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 44 "@f"	2 6 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 45 "0"	2 0 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 46 "l"	2 1 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 47 "\$"	2 6 [list "" "0123456" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 48 "X"	2 5 [list "" "012345" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 49 "n"	4 0 [list "" "012345" "07" "0" "" "" "T0123456n" "T0123456$" "/" "~"]
test 50 "\$P"	4 1 [list "" "012345" "07" "06" "" "" "T0123456n" "T0123456$" "/" "~"]

# Run the main loop
set timeout 10
test 111 "L" 2 0 \
	[list "" "0" "01234567" "0" "" "" "T0123456n" "T0123456$" "/" "~"]

stop_vi

exit 0
