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

# Issue 41: "yl" and "dl" when cursor is at end of line and
# dNl where N is a decimal number, near the end of the line
# should pick up the last character of the line.
# This also applies to c < > ! although classic vi doesn't do them.
#
# Was https://github.com/martinwguy/xvi/issues/41

source scripts/term
start_vi

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

# Create a test pattern
test 101 "aabcde[esc]"	1 4 [list "abcde" "~"]

# Try a one-character yank at end of line
test 102 ylp		1 5 [list "abcdee" "~"]

# Restore abcde and try exactly the last 2 characters
test 103 {x$hd2l}	1 2 [list "abc" "~"]
# Check the prefix the other way round too
test 113 {p$h2dl}	1 2 [list "abc" "~"]

# Restore and sitting on the d, try taking more than there are
# (it should take 2)
test 104 {p$hd3l}	1 2 [list "abc" "~"]
test 114 {p$h3dl} 	1 2 [list "abc" "~"]

# Check that a numeric prefix is OK in the middle of the line too.
test 105 {p0l2dl}	1 1 [list "ade" "~"]

# Check that it works for the other operators

# c
exp_send "0Cabc[esc]"
test 106 "\$clX[esc]"	1 2 [list "abX" "~"]
# nvi fails the next test because it doesn't put the cursor at first non-blank
test 107 "\$>l"		1 8 [list "        abX" "~"]
test 108 "\$<l"		1 0 [list "abX" "~"]
test 109 "\$!ltr b Y\r"	1 0 [list "aYX" "~"]

stop_vi

exit 0
