# How to use this expect-lite file, Lines that begin with:
#	'>' send to remote host, implies "wait for prompt"
#	'<' _MUST_ be received from the remote host, or this config script will fail
#	# are comment lines, and have no effect
#	; are printable (in stdout) comments, and have no other effect
#	@ change the expect timeout value
#	! Embedded Expect commands
#	? If statement, use format ?cond?action::else_action
# For more info see: expect-lite.html

#
#	test of Code Blocks implemented in expect-lite
#	and self tested (where possible)


# Turn on warnings
!set ::WARN 1

; ==== Set Timeout ====
@4

*EXP_INFO

; === basic if code block
?if 1==1?[
>echo "if1 good"
]
<\nif1 good
>


; === if else code block
?if 1!=1?>echo "BAD" :: [
	>echo "if2 good"
]
<\nif2 good
>

; === third if too many code blocks - should have warning
?if 1!=1? [:: [
	>echo "if3 bad"
]
-<\nif3 bad
>

; === nested ifs
?if 1 == 1? ?if 2==2? [ 
	>echo "good"
]
<good
>

$test=3
; === nested ifs using code blocks
?if 1 < $test ? [ :: >echo "else 1"
	?if 2 < $test ? [ :: >echo "else 2"
		>echo "good"
	]
]
<good
>

; === while loops with code blocks

; === simple while loop
$i=0
[$i < 5
	>echo "hello ken2"
	<ken
	+$i
]
?if $i == 5 ? >echo "good"
<good
>

; === while loop with break
$i=0
[$i < 5
	>echo "hello ken2"
	<ken
	#break
	?if $i == 3? $i=5
	+$i
]
?if $i == 6 ? >echo "good"
<good
>

; === Nested While loops
; == should repeat "hello ken" 3 times, with 2 "bye now"s inside each outer loop
>
$i=0
[ $i < 3
	>echo "hello ken"
	<ken
	$j=0
	[ $j < 2 
		>echo "bye now"
		>
		+$j
	]
	+$i
]
?if $i == 3 ? >echo "good"
<good
>
?if $j == 2 ? >echo "good"
<good
>

; === Negative testing of code blocks

*INFINITE_LOOP 15

; == test blank arg2
>
$blank=
[3 == $blank
	>echo "blank"
]
-<blank
>
; === test just number 
>
[3
>echo "blank3"
]
>
; === extra right bracket
>
]

>
; === test with no closure
[ 1 < 2
>echo "good"
# empty open bracket
[
<good
>




>
# put this at the end of the file, it tests jumping to the end of the file
; === just [ ]
[
>echo "blank4"
]










