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

# Test that 'r' on an empty line (or Nr with less than N characters
# under/after the cursor) fails.
#
# Was https://github.com/martinwguy/xvi/issues/106

source scripts/term
start_vi

# Tests begin

# Check it started up OK
test 100 ""		1 0 [list "" "~"]

# Try replace on an empty line. The 'r' should be ignored and the : should
# take us to the command prompt.
# We have to send these separately because a failed "r" unstuffs buffered input.
exp_send "r"
test 101 ":"		[expr $rows] 1 [list "" "~"]

# Try the same with a repeat count.
test 102 "[esc]aabc[esc]0l"	1 1 [list "abc" "~"]

# A multi-char replacement with exactly the right number of chars available
# should be carried out.
exp_send "2r"
test 103 "X"		1 2 [list "aXX" "~"]
test 104 "u0fb"		1 1 [list "abc" "~"]

# A multi-char replacement with one char too few available should fail
# and the : should take us to the command line.
exp_send "3r"
test 105 ":"		[expr $rows] 1 [list "abc" "~"]
exp_send [esc]

# Check that a failed 'r' cancels a map command.
# If the 'r' fails as it should, the rest of the X macro should be ignored.
# If the 'r' is done, it will insert an A and append "bcde" after it.
exp_send ":map X rAabcde\r"
test 106 "0DX"		1 0 [list "" "~"]

exp_send [esc]		;# In case it got left in insert mode

stop_vi

exit 0
