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

#
# Test file for yanking to named buffers in append mode.
#
# POSIX: "If the specified buffer name is an uppercase character, and the buffer
#	contents are to be modified, the buffer shall be appended to rather than
#	being overwritten. If the buffer is not being modified, specifying the
#	buffer name in lowercase and uppercase shall have identical results."
# and: "The text of each buffer shall have the characteristic of being in either
#	line or character mode. Appending text to a non-empty buffer shall set
#	the mode to match the characteristic of the text being
#	appended. Appending text to a buffer shall cause the creation of at
#	least one additional line in the buffer. All text stored into buffers
#	by ex commands shall be in line mode. The ex commands that use buffers
#	as the source of text specify individually how buffers of different
#	modes are handled. Each open or visual mode command that uses buffers
#	for any purpose specifies individually the mode of the text stored
#	into the buffer and how buffers of different modes are handled."
#
# Was https://github.com/martinwguy/xvi/issues/87
#

source scripts/term
start_vi

# Tests begin

test 100 "aone\rtwo[esc]1G"		1 0 [list "one" "two" "~"]

#
# Test all 4 combinations of appending a char/line buffer to a line/char buffer
#

# Append lines to a line-based yank
test 101 "\"ayyj\"Ayy\"ap"		3 0 [list "one" "two" "one" "two" "~"]

# Append chars to a single-line char-based yank.
# We yank "one", append "two" to it and dump the result in the centre of abcd.
test 102 "1GdGaone two\rabcd[esc]1G"	1 0 [list "one two" "abcd" "~" ]
test 103 "\"by3l4l\"By\$j0l\"bp"	2 2 [list "one two" "abone" "twocd" "~"]

# Append a char to a line-based yank
test 104 "1GdGaone two\rabcd[esc]1G"	1 0 [list "one two" "abcd" "~" ]
# nvi fails the next test because it leaves the buffer line-based.
test 105 "\"cyy0l\"Cylj0l\"cp"		2 2 [list "one two" "abone two" "ncd" "~" ]

# Append a line to a char-based yank
test 106 "1GdGaone two\rabcd[esc]1G"	1 0 [list "one two" "abcd" "~" ]
test 107 "l\"dyl\"Dyyj0l\"dp"		3 0 [list "one two" "abcd" "n" "one two" "~" ]

# Append a line-based yank to a char-based yank of two lines
test 108 "1GdGaone two\rthree four\rabcd[esc]1G" \
					1 0 [list "one two" "three four" "abcd" "~" ]
test 109 "4l\"ey/ four\r2G\"EyyGl\"Ep"	4 0 [list "one two" "three four" "abcd" "two" "three" "three four" "~" ]

# Append a line-based yank to a char-based yank of three lines.
# It should pick up from "two" to "five" inclusive as the first yank,
# then the line "three four" and add after the "abcd" line:
#	two
#	three four
#	five
#	three four
# This is what classic vi, nvi and vim do.

test 110 "1GdGaone two\rthree four\rfive six\rabcd[esc]1G" \
					1 0 [list "one two" "three four" "five six" "abcd" "~" ]
test 111 "4l\"ey/ six\r2G\"EyyGl\"Ep"	5 0 [list "one two" "three four" "five six" "abcd" "two" "three four" "five" "three four" "~" ]

#
# Check appending to an empty buffer
# (this test fails with xvi);
#
test 112 "1G\"Fy3l\$\"fp"		1 7 [list "one twoone"]

#
# Test all 9 cases of appending a char-based yank to a char-based buffer,
# when 1st, 1st+2nd or 1st+line_buf+2nd are set in each.
#

stop_vi

exit 0
