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

# See if the maze-solving vi macros work

#
# Screen states at various stages
#

# After reading the file and after sourcing the macros, the screen should be:
set preInit [list \
"._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._" \
"| ._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._|_._. ._| . ._|_. | . ._._. |"\
"| ._|_| |_. | | | | ._._|_._|_._. . |_. | | | ._._| |_._._| | ._. ._| . . |_|"\
"|_._._._. | ._|_. ._._._. | | ._. |_._. . | ._._| |_. | ._._._. |_. | |_|_| |"\
"| | . |_._| . ._._._| ._._. ._._| | | |_| . | |_. . ._|_| ._._. |_._|_| . | |"\
"|_._|_._._._|_._._._|_|_._._._|_._|_._._._|_._._._|_._._._|_._._._._._._|_._|"\
]

# After I the screen should be:
set postInit [list \
"._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._"\
"| ._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._|_._. ._| . ._|_. | . ._._. |"\
"| ._|_| |_. | | | | ._._|_._|_._. . |_. | | | ._._| |_._._| | ._. ._| . . |_|"\
"|_._._._. | ._|_. ._._._. | | ._. |_._. . | ._._| |_. | ._._._. |_. | |_|_| |"\
"| | . |_._| . ._._._| ._._. ._._| | | |_| . | |_. . ._|_| ._._. |_._|_| . | |"\
"|_._|_._._._|_._._._|_|_._._._|_._|_._._._|_._._._|_._._._|_._._._._._._|_X_|"\
""\
"See Vim solve a maze!"\
""\
"   type \":so maze_mac<RETURN>\" to load the macros"\
""\
"   type \"g\" to start"\
""\
"to interrupt type \"<CTRL-C>\" or \"<CTRL-BREAK>\""\
"     to quit type \":q!<RETURN>\""\
""\
"sE1  k  N1       sE1_ mm E2       sE2| mm S1       sE2. ll E1"\
"sW1  j  S1       sW1_ mm W2       sW2| mm N1       sW2. hh W1"\
"sN1. hh W1       sN1| mm N2       sN2  k  N1       sN2_ mm E1"\
"sS1. ll E1       sS1| mm S2       sS2  j  S1       sS2_ mm W1"\
"nE1 kF nE2 lF nW1 G\$JF nW2 hF nN1 hF nN2 kF nS1 lF nS2 G\$JF"\
"E1"\
"~"\
]

# After L the screen should be:
set postRun [list \
"._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._"\
"| ._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._|_._. ._| . ._|_. | . ._._. |"\
"| ._|_| |_. | | | | ._._|_._|_._. . |_. | | | ._._| |_._._| | ._. ._| . . |_|"\
"|_._._._. | ._|_. ._._._. | | ._. |_._. . | ._._| |_. | ._._._. |_. | |_|_| |"\
"| | . |_._| . ._._._| ._._. ._._| | | |_| . | |_. . ._|_| ._._. |_._|_| . | |"\
"|_._|_._._._|_._._._|_|_._._._|_._|_._._._|_._._._|_._._._|_._._._._._._|OX_|"\
]

#
# Tests start
#

# Clean up after vim so that it starts up ok
exec rm -f {.1991_maze_sample.swp}

source scripts/term
start_vi data/sample.maz

set timeout 15

test 10 ""			1 0 $preInit
ctest 11 ":so data/maze_mac"	17 ":so data/maze_mac"
test 12 "\r"			1 0 $preInit

# Test the initialization
test 20 "I"			2 1 $postInit

test 30 "L"			22 0 $postRun

stop_vi

exit 0
