/*
 * $Id: subst.inter 3340 2009-12-14 00:00:49Z unsaved $
 *
 * Tests interactive commands :s*.
 */

\c false
/* Since running interactively, need to either invoke with --abortOnErr switch,
 * or use "\c false" Special command, to detect failures. */

CREATE TABLE t(id INTEGER GENERATED BY DEFAULT AS IDENTITY, vc VARCHAR(80));

INSERT INTO t(vc) VALUES('one')

/* In interactive mode, the blank line above will move the command to the
 * edit buffer without executing it. */

:s/n/MM/;
/*Since this executes, command #3 in history will become "INSERT... 'oMMe'".*/

SELECT count(*) FROM t;
*if (*? != 1)
    \q Blank lines not behaving right in Interactive mode
*end if

SELECT count(*) FROM t WHERE vc = 'oMMe';
*if (*? != 1)
    \q Simple substitution of edit buffer failed.
*end if

/* Tailing white space in line below, on purpose. */
:3   s@M@.@g;  

SELECT count(*) FROM t;
*if (*? != 2)
    \q Recall + subst. + exec failed / 1
*end if

SELECT count(*) FROM t WHERE vc = 'o..e';
*if (*? != 1)
    \q Recall + subst. + exec failed / 2
*end if

:3
/* Purposeful trailing white space in following line */
:s:MM:x:g   
:;

SELECT count(*) FROM t;
*if (*? != 3)
    \q Recall + subst., then exec failed / 1
*end if

SELECT count(*) FROM t WHERE vc = 'oxe';
*if (*? != 1)
    \q Recall + subst., then exec failed / 2
*end if

:/INSERT.*MM/
:s/Me/End/;
\q
:/INSERT.*MM/s/(?-i)o/Begin/;

SELECT count(*) FROM t;
*if (*? != 5)
    \q Regex Recall + subst., then exec failed / 1
*end if

SELECT count(*) FROM t WHERE vc = 'oMEnd';
*if (*? != 1)
    \q Regex Recall + subst., then exec failed / 2
*end if

SELECT count(*) FROM t WHERE vc = 'Begin..e';
*if (*? != 1)
    \q Regex Recall + subst., then exec failed / 3
*end if
