encoding-guesser: Avoid reading uninitialized data for zero-length files.
[pspp] / tests / language / expressions / evaluate.at
index d16bac5df7a6f2c0ae07cebabb5435d73ad2b718..cd574eb10f79eb8cea949a754d6b20ffc2947355 100644 (file)
@@ -1,17 +1,35 @@
+dnl PSPP - a program for statistical analysis.
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl
+dnl This program is free software: you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
 m4_define([CHECK_EXPR_EVAL],
   [AT_SETUP([expressions - $1])
+   AT_KEYWORDS([expression])
    AT_DATA([evaluate.sps],
      [set mxwarn 1000.
 set mxerr 1000.
+set epoch 1940.
 m4_foreach([check], [m4_shift($@)],
                  [DEBUG EVALUATE NOOPT m4_argn(4, check)/[]m4_car(check).
 DEBUG EVALUATE m4_argn(4, check)/[]m4_car(check).
 ])])
    AT_CAPTURE_FILE([evaluate.sps])
-   m4_pushdef([i], [2])
-   AT_CHECK([pspp --testing-mode --error-file=- --no-output evaluate.sps], 
+   m4_pushdef([i], [3])
+   AT_CHECK([pspp --testing-mode -O format=csv evaluate.sps],
      [m4_if(m4_bregexp([m4_foreach([check], [m4_shift($@)], [m4_argn(3, check)])], [error:]), [-1], [0], [1])],
-     [m4_foreach([check], [m4_shift($@)],
+     [stdout])
+   AT_DATA([expout], [m4_foreach([check], [m4_shift($@)],
         [m4_define([i], m4_incr(i))dnl
 m4_if(m4_argn(3, check), [], [], [evaluate.sps:[]i[]: m4_argn(3, check)
 ])dnl
@@ -20,7 +38,21 @@ m4_define([i], m4_incr(i))dnl
 m4_if(m4_argn(3, check), [], [], [evaluate.sps:[]i[]: m4_argn(3, check)
 ])dnl
 m4_argn(2, check)
-])], [])
+])])
+   AT_CHECK([[sed '
+# Transform "file:line.column:" into plain "file:line:",
+# because column numbers change between opt and noopt versions.
+s/\(evaluate.sps:[0-9]\{1,\}\)\.[0-9]\{1,\}:/\1:/
+
+# Remove leading or trailing quotes and un-double CSV quotes.
+s/^"//
+s/"$//
+s/""/"/g
+# "
+
+# Delete blank lines
+/^$/d' stdout]],
+     [0], [expout], [])
    m4_popdef([i])
    AT_CLEANUP])
 
@@ -38,11 +70,11 @@ CHECK_EXPR_EVAL([coercion to/from Boolean],
   [[1 OR $false], [true]],
   [[1 OR $sysmis], [true]],
   [[2 OR $sysmis], [sysmis],
-   [error: DEBUG EVALUATE: An operand of the logical disjunction ("OR") operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
+   [error: DEBUG EVALUATE: An operand of the logical disjunction (`OR') operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
   [[2 AND $sysmis], [false],
-   [error: DEBUG EVALUATE: An operand of the logical conjunction ("AND") operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
+   [error: DEBUG EVALUATE: An operand of the logical conjunction (`AND') operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
   [['string' AND $sysmis], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying logical conjunction ("AND") operator: cannot convert string to boolean.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying logical conjunction (`AND') operator: cannot convert string to boolean.]],
   [[0 AND $sysmis], [false]],
   [[(1>2) + 1], [1.00]],
   [[$true + $false], [1.00]])
@@ -53,19 +85,19 @@ CHECK_EXPR_EVAL([addition and subtraction],
   [[$sysmis + 1], [sysmis]],
   [[7676 + $sysmis], [sysmis]],
   [[('foo') + 5], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying addition ("+") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying addition (`+') operator: cannot convert string to number.]],
   dnl Arithmetic concatenation requires CONCAT:
   [[('foo') + ('bar')], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying addition ("+") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying addition (`+') operator: cannot convert string to number.]],
   dnl Lexical concatenation succeeds:
   [['foo' + 'bar'], ["foobar"]],
   [[1 +3 - 2 +4 -5], [1.00]],
   [[1 - $true], [0.00]],
   [[$true - 4/3], [-0.33]],
   [['string' - 1e10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying subtraction ("-") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying subtraction (`-') operator: cannot convert string to number.]],
   [[9.5 - ''], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying subtraction ("-") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying subtraction (`-') operator: cannot convert string to number.]],
   [[1 - 2], [-1.00]],
   [[52 -23], [29.00]])
 
@@ -85,7 +117,7 @@ CHECK_EXPR_EVAL([exponentiation],
   [[2**8], [256.00]],
   [[(2**3)**4], [4096.00]],
   [[2**3**4], [4096.00],
-   [warning: DEBUG EVALUATE: The exponentiation operator ("**") is left-associative, even though right-associative semantics are more useful.  That is, "a**b**c" equals "(a**b)**c", not as "a**(b**c)".  To disable this warning, insert parentheses.]])
+   [warning: DEBUG EVALUATE: The exponentiation operator (`**') is left-associative, even though right-associative semantics are more useful.  That is, `a**b**c' equals `(a**b)**c', not as `a**(b**c)'.  To disable this warning, insert parentheses.]])
 
 CHECK_EXPR_EVAL([unary minus],
   [[2+-3], [-1.00]],
@@ -141,14 +173,14 @@ CHECK_EXPR_EVAL([NOT truth table],
   [[not $false], [true]],
   [[not 0], [true]],
   [[not 2.5], [true],
-   [error: DEBUG EVALUATE: An operand of the logical negation ("NOT") operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
+   [error: DEBUG EVALUATE: An operand of the logical negation (`NOT') operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
   [[not $true], [false]],
   [[not 1], [false]],
   [[not $sysmis], [sysmis]],
   [[~ $false], [true]],
   [[~ 0], [true]],
   [[~ 2.5], [true],
-   [error: DEBUG EVALUATE: An operand of the logical negation ("NOT") operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
+   [error: DEBUG EVALUATE: An operand of the logical negation (`NOT') operator was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0.]],
   [[~ $true], [false]],
   [[~ 1], [false]],
   [[~ $sysmis], [sysmis]])
@@ -159,13 +191,13 @@ CHECK_EXPR_EVAL([= <= <],
   [[1 eq 2], [false]],
   [[2 = 3], [false]],
   [[1 eq 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric equality ("EQ") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric equality (`EQ') operator: cannot convert string to number.]],
   [[5 eq 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric equality ("EQ") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric equality (`EQ') operator: cannot convert string to number.]],
   [['baz' = 10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string equality ("=") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string equality (`=') operator: cannot convert number to string.]],
   [['quux' = 5.55], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string equality ("=") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string equality (`=') operator: cannot convert number to string.]],
   [['foobar' = 'foobar'], [true]],
   [['quux' = 'bar'], [false]],
   [['bar   ' = 'bar'], [true]],
@@ -174,12 +206,12 @@ CHECK_EXPR_EVAL([= <= <],
 dnl Check precedence:
   [[1 + 2 = 3], [true]],
   [[1 >= 2 = 2 ge 3], [false],
-   [warning: DEBUG EVALUATE: Chaining relational operators (e.g. "a < b < c") will not produce the mathematically expected result.  Use the AND logical operator to fix the problem (e.g. "a < b AND b < c").  If chaining is really intended, parentheses will disable this warning (e.g. "(a < b) < c".)]],
+   [warning: DEBUG EVALUATE: Chaining relational operators (e.g. `a < b < c') will not produce the mathematically expected result.  Use the AND logical operator to fix the problem (e.g. `a < b AND b < c').  If chaining is really intended, parentheses will disable this warning (e.g. `(a < b) < c'.)]],
 dnl Mathematically true:
   [[3 ne 2 ~= 1], [false],
-   [warning: DEBUG EVALUATE: Chaining relational operators (e.g. "a < b < c") will not produce the mathematically expected result.  Use the AND logical operator to fix the problem (e.g. "a < b AND b < c").  If chaining is really intended, parentheses will disable this warning (e.g. "(a < b) < c".)]],
+   [warning: DEBUG EVALUATE: Chaining relational operators (e.g. `a < b < c') will not produce the mathematically expected result.  Use the AND logical operator to fix the problem (e.g. `a < b AND b < c').  If chaining is really intended, parentheses will disable this warning (e.g. `(a < b) < c'.)]],
   [[3 > 2 > 1], [false],
-   [warning: DEBUG EVALUATE: Chaining relational operators (e.g. "a < b < c") will not produce the mathematically expected result.  Use the AND logical operator to fix the problem (e.g. "a < b AND b < c").  If chaining is really intended, parentheses will disable this warning (e.g. "(a < b) < c".)]],
+   [warning: DEBUG EVALUATE: Chaining relational operators (e.g. `a < b < c') will not produce the mathematically expected result.  Use the AND logical operator to fix the problem (e.g. `a < b AND b < c').  If chaining is really intended, parentheses will disable this warning (e.g. `(a < b) < c'.)]],
 
   [[1 <= 2], [true]],
   [[2.5 <= 1.5], [false]],
@@ -188,15 +220,15 @@ dnl Mathematically true:
   [[2 le 2], [true]],
 dnl Make sure <= token can't be split:
   [[2 < = 2], [error],
-   [error: DEBUG EVALUATE: Syntax error in expression at `='.]],
+   [error: DEBUG EVALUATE: Syntax error at `='.]],
   [[1 <= 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric less-than-or-equal-to ("<=") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric less-than-or-equal-to (`<=') operator: cannot convert string to number.]],
   [[5 <= 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric less-than-or-equal-to ("<=") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric less-than-or-equal-to (`<=') operator: cannot convert string to number.]],
   [['baz' <= 10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string less-than-or-equal-to ("<=") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string less-than-or-equal-to (`<=') operator: cannot convert number to string.]],
   [['quux' <= 5.55], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string less-than-or-equal-to ("<=") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string less-than-or-equal-to (`<=') operator: cannot convert number to string.]],
   [['0123' <= '0123'], [true]],
   [['0123' <= '0124'], [true]],
   [['0124' le '0123'], [false]],
@@ -208,13 +240,13 @@ dnl Make sure <= token can't be split:
   [[3.5 lt 4], [true]],
   [[4 lt 3.5], [false]],
   [[1 lt 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric less than ("<") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric less than (`<') operator: cannot convert string to number.]],
   [[5 lt 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric less than ("<") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric less than (`<') operator: cannot convert string to number.]],
   [['baz' < 10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string less than ("<") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string less than (`<') operator: cannot convert number to string.]],
   [['quux' < 5.55], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string less than ("<") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string less than (`<') operator: cannot convert number to string.]],
   [['0123' lt '0123'], [false]],
   [['0123' < '0124'], [true]],
   [['0124' lt '0123'], [false]],
@@ -229,15 +261,15 @@ CHECK_EXPR_EVAL([>= > <>],
   [[2 ge 2], [true]],
 dnl Make sure >= token can't be split:
   [[2 > = 2], [error],
-   [error: DEBUG EVALUATE: Syntax error in expression at `='.]],
+   [error: DEBUG EVALUATE: Syntax error at `='.]],
   [[1 >= 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater-than-or-equal-to (">=") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater-than-or-equal-to (`>=') operator: cannot convert string to number.]],
   [[5 ge 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater-than-or-equal-to (">=") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater-than-or-equal-to (`>=') operator: cannot convert string to number.]],
   [['baz' ge 10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string greater-than-or-equal-to (">=") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string greater-than-or-equal-to (`>=') operator: cannot convert number to string.]],
   [['quux' >= 5.55], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string greater-than-or-equal-to (">=") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string greater-than-or-equal-to (`>=') operator: cannot convert number to string.]],
   [['0123' ge '0123'], [true]],
   [['0123' >= '0124'], [false]],
   [['0124' >= '0123'], [true]],
@@ -249,13 +281,13 @@ dnl Make sure >= token can't be split:
   [[3.5 gt 4], [false]],
   [[4 gt 3.5], [true]],
   [[1 gt 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater than (">") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater than (`>') operator: cannot convert string to number.]],
   [[5 gt 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater than (">") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric greater than (`>') operator: cannot convert string to number.]],
   [['baz' > 10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string greater than (">") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string greater than (`>') operator: cannot convert number to string.]],
   [['quux' > 5.55], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string greater than (">") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string greater than (`>') operator: cannot convert number to string.]],
   [['0123' gt '0123'], [false]],
   [['0123' > '0124'], [false]],
   [['0124' gt '0123'], [true]],
@@ -267,13 +299,13 @@ dnl Make sure >= token can't be split:
   [[1 <> 2], [true]],
   [[2 ne 3], [true]],
   [[1 ~= 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric inequality ("<>") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric inequality (`<>') operator: cannot convert string to number.]],
   [[5 <> 'foobar'], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying numeric inequality ("<>") operator: cannot convert string to number.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying numeric inequality (`<>') operator: cannot convert string to number.]],
   [['baz' ne 10], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string inequality ("<>") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string inequality (`<>') operator: cannot convert number to string.]],
   [['quux' ~= 5.55], [error],
-   [error: DEBUG EVALUATE: Type mismatch while applying string inequality ("<>") operator: cannot convert number to string.]],
+   [error: DEBUG EVALUATE: Type mismatch while applying string inequality (`<>') operator: cannot convert number to string.]],
   [['foobar' <> 'foobar'], [false]],
   [['quux' ne 'bar'], [true]],
   [['bar   ' <> 'bar'], [false]],
@@ -281,10 +313,10 @@ dnl Make sure >= token can't be split:
   [['asdfj   ' ne 'asdf'], [true]],
 dnl <> token can't be split:
   [[1 < > 1], [error],
-   [error: DEBUG EVALUATE: Syntax error in expression at `GT'.]],
+   [error: DEBUG EVALUATE: Syntax error at `>'.]],
 dnl # ~= token can't be split:
   [[1 ~ = 1], [error],
-   [error: DEBUG EVALUATE: Syntax error expecting end of command at `NOT'.]])
+   [error: DEBUG EVALUATE: Syntax error at `~': expecting end of command.]])
 
 CHECK_EXPR_EVAL([exp lg10 ln sqrt abs mod mod10 rnd trunc],
   [[exp(10)], [22026.47]],
@@ -328,15 +360,37 @@ CHECK_EXPR_EVAL([exp lg10 ln sqrt abs mod mod10 rnd trunc],
   [[rnd(5.6)], [6.00]],
   [[rnd(-5.4)], [-5.00]],
   [[rnd(-5.6)], [-6.00]],
+  [[rnd(5.56, .1)], [5.60]],
+  [[rnd(-5.56, .1)], [-5.60]],
+  [[rnd(.5)], [1.00]],
+  [[rnd(.5 - 2**-53)], [1.00]],
+  [[rnd(.5 - 2**-52)], [1.00]],
+  [[rnd(.5 - 2**-51)], [1.00]],
+  [[rnd(.5 - 2**-45)], [0.00]],
+  [[rnd(.5 - 2**-45, 1, 10)], [1.00]],
   [[rnd('x')], [error],
-   [error: DEBUG EVALUATE: Type mismatch invoking RND(number) as rnd(string).]],
+   [error: DEBUG EVALUATE: Function invocation rnd(string) does not match any known function.  Candidates are:
+RND(number)
+RND(number, number)
+RND(number, number, number).]],
 
   [[trunc(1.2)], [1.00]],
   [[trunc(1.9)], [1.00]],
   [[trunc(-1.2)], [-1.00]],
   [[trunc(-1.9)], [-1.00]],
+  [[trunc(5.06, .1)], [5.00]],
+  [[trunc(-5.06, .1)], [-5.00]],
+  [[trunc(1)], [1.00]],
+  [[trunc(1 - 2**-53)], [1.00]],
+  [[trunc(1 - 2**-52)], [1.00]],
+  [[trunc(1 - 2**-51)], [1.00]],
+  [[trunc(1 - 2**-45)], [0.00]],
+  [[trunc(1 - 2**-45, 1, 10)], [1.00]],
   [[trunc('x')], [error],
-   [error: DEBUG EVALUATE: Type mismatch invoking TRUNC(number) as trunc(string).]])
+   [error: DEBUG EVALUATE: Function invocation trunc(string) does not match any known function.  Candidates are:
+TRUNC(number)
+TRUNC(number, number)
+TRUNC(number, number, number).]])
 
 CHECK_EXPR_EVAL([acos arsin artan cos sin tan],
   [[acos(.5) / 3.14159 * 180], [60.00]],
@@ -482,7 +536,7 @@ ANY(string, string[, string]...).]],
   [[any('a', 'a  ', 'b', 'c')], [true]],
   [[any('b   ', 'a', 'b', 'c')], [true]],
   [[any('c   ', 'a', 'b', 'c     ')], [true]],
-  [[any(a, 'b', 'c', 'd')], [error],
+  [[any(a10, 'b', 'c', 'd')], [error],
    [error: DEBUG EVALUATE: Function invocation any(format, string, string, string) does not match any known function.  Candidates are:
 ANY(number, number[, number]...)
 ANY(string, string[, string]...).]],
@@ -519,11 +573,11 @@ ANY(string, string[, string]...).]],
 RANGE(number, number, number[, number, number]...)
 RANGE(string, string, string[, string, string]...).]],
   [[range(1, 2)], [error],
-   [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an even number of arguments in list.]],
+   [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an odd number of arguments.]],
   [[range(1, 2, 3, 4)], [error],
-   [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an even number of arguments in list.]],
+   [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an odd number of arguments.]],
   [[range(1, 2, 3, 4, 5, 6)], [error],
-   [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an even number of arguments in list.]],
+   [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an odd number of arguments.]],
   [[range('1', 2, 3)], [error],
    [error: DEBUG EVALUATE: Function invocation range(string, number, number) does not match any known function.  Candidates are:
 RANGE(number, number, number[, number, number]...)
@@ -562,11 +616,11 @@ RANGE(string, string, string[, string, string]...).]],
 RANGE(number, number, number[, number, number]...)
 RANGE(string, string, string[, string, string]...).]],
   [[range('1', '2')], [error],
-   [error: DEBUG EVALUATE: RANGE(string, string, string[, string, string]...) must have an even number of arguments in list.]],
+   [error: DEBUG EVALUATE: RANGE(string, string, string[, string, string]...) must have an odd number of arguments.]],
   [[range('1', '2', '3', '4')], [error],
-   [error: DEBUG EVALUATE: RANGE(string, string, string[, string, string]...) must have an even number of arguments in list.]],
+   [error: DEBUG EVALUATE: RANGE(string, string, string[, string, string]...) must have an odd number of arguments.]],
   [[range('1', '2', '3', '4', '5', '6')], [error],
-   [error: DEBUG EVALUATE: RANGE(string, string, string[, string, string]...) must have an even number of arguments in list.]],
+   [error: DEBUG EVALUATE: RANGE(string, string, string[, string, string]...) must have an odd number of arguments.]],
   [[range(1, '2', '3')], [error],
    [error: DEBUG EVALUATE: Function invocation range(number, string, string) does not match any known function.  Candidates are:
 RANGE(number, number, number[, number, number]...)
@@ -592,7 +646,7 @@ MAX(string[, string]...).]],
   [[max(1, 2, 3, $sysmis)], [3.00]],
   [[max.4(1, 2, 3, $sysmis)], [sysmis]],
   [[max.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With MAX(number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
+   [error: DEBUG EVALUATE: For MAX(number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
 
   [[max("2", "3", "5", "1", "4")], ["5"]],
   [[max("1", "2")], ["2"]],
@@ -610,13 +664,13 @@ MIN(string[, string]...).]],
   [[min(1, 2, 3, $sysmis)], [1.00]],
   [[min.4(1, 2, 3, $sysmis)], [sysmis]],
   [[min.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With MIN(number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
+   [error: DEBUG EVALUATE: For MIN(number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
 
   [[min("2", "3", "5", "1", "4")], ["1"]],
   [[min("1", "2")], ["1"]],
   [[min("1")], ["1"]])
 
-CHECK_EXPR_EVAL([cfvar mean sd sum variance],
+CHECK_EXPR_EVAL([cfvar mean median sd sum variance],
   [[cfvar(1, 2, 3, 4, 5)], [0.53]],
   [[cfvar(1, $sysmis, 2, 3, $sysmis, 4, 5)], [0.53]],
   [[cfvar(1, 2)], [0.47]],
@@ -626,7 +680,7 @@ CHECK_EXPR_EVAL([cfvar mean sd sum variance],
   [[cfvar(1, 2, 3, $sysmis)], [0.50]],
   [[cfvar.4(1, 2, 3, $sysmis)], [sysmis]],
   [[cfvar.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With CFVAR(number, number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
+   [error: DEBUG EVALUATE: For CFVAR(number, number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
   [[cfvar('x')], [error],
    [error: DEBUG EVALUATE: Type mismatch invoking CFVAR(number, number[, number]...) as cfvar(string).]],
   [[cfvar('x', 1, 2, 3)], [error],
@@ -642,8 +696,27 @@ CHECK_EXPR_EVAL([cfvar mean sd sum variance],
   [[mean(1, 2, 3, $sysmis)], [2.00]],
   [[mean.4(1, 2, 3, $sysmis)], [sysmis]],
   [[mean.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With MEAN(number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
-
+   [error: DEBUG EVALUATE: For MEAN(number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
+
+  [[median(1, 2, 3, 4, 5)], [3.00]],
+  [[median(2, 3, 4, 5, 1)], [3.00]],
+  [[median(2, 3, 4, 1, 5)], [3.00]],
+  [[median(2, 1, 4, 5, 3)], [3.00]],
+  [[median(1, 2, 3, 4)], [2.50]],
+  [[median(2, 3, 1, 4)], [2.50]],
+  [[median(2, 3, 4, 1)], [2.50]],
+  [[median(2, 1, 4, 3)], [2.50]],
+  [[median(1, $sysmis, 3, 4, 5)], [3.50]],
+  [[median(2, 3, 4, 5, $sysmis, 1)], [3.00]],
+  [[median($sysmis, $sysmis, $sysmis, 2, 3, 4, 1, 5)], [3.00]],
+  [[median(1, 2, 3)], [2.00]],
+  [[median(1)], [1.00]],
+  [[median(1, 2)], [1.50]],
+  [[median(1, 2, $sysmis)], [1.50]],
+  [[median(1, $sysmis, $sysmis)], [1.00]],
+  [[median($sysmis, $sysmis, $sysmis)], [sysmis]],
+  [[median.3(1, 2, $sysmis)], [sysmis]],
+  [[median.2(1, $sysmis)], [sysmis]],
 
   [[sd(1, 2, 3, 4, 5)], [1.58]],
   [[sd(1, $sysmis, 2, 3, $sysmis, 4, 5)], [1.58]],
@@ -654,7 +727,7 @@ CHECK_EXPR_EVAL([cfvar mean sd sum variance],
   [[sd(1, 2, 3, $sysmis)], [1.00]],
   [[sd.4(1, 2, 3, $sysmis)], [sysmis]],
   [[sd.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With SD(number, number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
+   [error: DEBUG EVALUATE: For SD(number, number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
   [[sd('x')], [error],
    [error: DEBUG EVALUATE: Type mismatch invoking SD(number, number[, number]...) as sd(string).]],
   [[sd('x', 1, 2, 3)], [error],
@@ -670,7 +743,7 @@ CHECK_EXPR_EVAL([cfvar mean sd sum variance],
   [[sum(1, 2, 3, $sysmis)], [6.00]],
   [[sum.4(1, 2, 3, $sysmis)], [sysmis]],
   [[sum.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With SUM(number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
+   [error: DEBUG EVALUATE: For SUM(number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
 
   [[variance(1, 2, 3, 4, 5)], [2.50]],
   [[variance(1, $sysmis, 2, 3, $sysmis, 4, 5)], [2.50]],
@@ -681,7 +754,7 @@ CHECK_EXPR_EVAL([cfvar mean sd sum variance],
   [[variance(1, 2, 3, $sysmis)], [1.00]],
   [[variance.4(1, 2, 3, $sysmis)], [sysmis]],
   [[variance.4(1, 2, 3)], [error],
-   [error: DEBUG EVALUATE: With VARIANCE(number, number[, number]...), using minimum valid argument count of 4 does not make sense when passing only 3 arguments in list.]],
+   [error: DEBUG EVALUATE: For VARIANCE(number, number[, number]...) with 3 arguments, at most 3 (not 4) may be required to be valid.]],
   [[variance('x')], [error],
    [error: DEBUG EVALUATE: Type mismatch invoking VARIANCE(number, number[, number]...) as variance(string).]],
   [[variance('x', 1, 2, 3)], [error],
@@ -753,6 +826,7 @@ CHECK_EXPR_EVAL([concat index rindex length lower],
   [[rindex('abcbcde', 'abc', 1)], [5.00]],
   [[rindex('abcbcde', 'bccb', 2)], [4.00]],
   [[rindex('abcbcde', 'bcbc', 2)], [4.00]],
+  [[rindex('abcbcde', 'bcbc', 0)], [sysmis]],
   [[rindex('abcbcde', 'bcbc', $sysmis)], [sysmis]],
   [[rindex('abcbcde', 'bcbcg', 2)], [sysmis]],
   [[rindex('abcbcde', 'bcbcg', $sysmis)], [sysmis]],
@@ -792,7 +866,22 @@ RINDEX(string, string, number).]],
   [[lower(1)], [error],
    [error: DEBUG EVALUATE: Type mismatch invoking LOWER(string) as lower(number).]])
 
-CHECK_EXPR_EVAL([lpad number ltrim lpad rtrim rpad string substr upcase],
+CHECK_EXPR_EVAL([replace],
+  [[replace('banana', 'an', 'AN')], ["bANANa"]],
+  [[replace('banana', 'an', 'a')], ["baaa"]],
+  [[replace('banana', 'an', '')], ["ba"]],
+  [[replace('banana', 'na', '')], ["ba"]],
+  [[replace('banana', 'ba', 'BA')], ["BAnana"]],
+  [[replace('banana', 'na', 'xyzzy')], ["baxyzzyxyzzy"]],
+  [[replace('banana', 'an', 'xyzzy', 1)], ["bxyzzyana"]],
+  [[replace('banana', 'an', 'xyzzy', 1.5)], ["bxyzzyana"]],
+  [[replace('banana', 'bananana', 'xyzzy')], ["banana"]],
+  [[replace('banana', '', 'xyzzy')], ["banana"]],
+  [[replace('banana', 'ba', '', 0)], ["banana"]],
+  [[replace('banana', 'ba', '', -1)], ["banana"]],
+  [[replace('banana', 'ba', '', $sysmis)], ["banana"]])
+
+CHECK_EXPR_EVAL([lpad number ltrim lpad rtrim rpad string strunc substr upcase],
   [[lpad('abc', -1)], [""]],
   [[lpad('abc', 0)], ["abc"]],
   [[lpad('abc', 2)], ["abc"]],
@@ -948,6 +1037,29 @@ dnl E has a minimum width of 6 on output:
    [error: DEBUG EVALUATE: Type mismatch invoking STRING(number, num_output_format) as string(number, format).]],
   [[string(123, e6.0)], ["1E+002"]],
 
+  [[strunc('a c   ', 9)], ["a c"]],
+  [[strunc('a c   ', 7)], ["a c"]],
+  [[strunc('a c   ', 6)], ["a c"]],
+  [[strunc('a c   ', 5)], ["a c"]],
+  [[strunc('a c   ', 4)], ["a c"]],
+  [[strunc('a c   ', 3)], ["a c"]],
+  [[strunc('a c   ', 2)], ["a"]],
+  [[strunc('a c   ', 1)], ["a"]],
+  [[strunc('a c   ', 0)], [""]],
+  [[strunc('a c   ', -1)], [""]],
+  [[strunc('a c   ', $sysmis)], [""]],
+  [[strunc('  abc  ', 9)], ["  abc"]],
+  [[strunc('  abc  ', 8)], ["  abc"]],
+  [[strunc('  abc  ', 7)], ["  abc"]],
+  [[strunc('  abc  ', 6)], ["  abc"]],
+  [[strunc('  abc  ', 5)], ["  abc"]],
+  [[strunc('  abc  ', 4)], ["  ab"]],
+  [[strunc('  abc  ', 3)], ["  a"]],
+  [[strunc('  abc  ', 2)], [""]],
+  [[strunc('  abc  ', 1)], [""]],
+  [[strunc('  abc  ', -1)], [""]],
+  [[strunc('  abc  ', $sysmis)], [""]],
+
   [[substr('abcdefgh', -5)], [""]],
   [[substr('abcdefgh', 0)], [""]],
   [[substr('abcdefgh', 1)], ["abcdefgh"]],
@@ -1281,7 +1393,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.date(date.mdy(10,7,1943) + time.hms(2,57,52)) / 86400], [131845.00]],
   [[xdate.date(date.mdy(3,17,1992) + time.hms(16,45,44)) / 86400], [149539.00]],
   [[xdate.date(date.mdy(2,25,1996) + time.hms(21,30,57)) / 86400], [150979.00]],
-  [[xdate.date(date.mdy(9,29,41) + time.hms(4,25,9)) / 86400], [131107.00]],
+  [[xdate.date(date.mdy(9,29,1941) + time.hms(4,25,9)) / 86400], [131107.00]],
   [[xdate.date(date.mdy(4,19,43) + time.hms(6,49,27)) / 86400], [131674.00]],
   [[xdate.date(date.mdy(10,7,43) + time.hms(2,57,52)) / 86400], [131845.00]],
   [[xdate.date(date.mdy(3,17,92) + time.hms(16,45,44)) / 86400], [149539.00]],
@@ -1305,7 +1417,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.hour(date.mdy(10,7,1943) + time.hms(2,57,52))], [2.00]],
   [[xdate.hour(date.mdy(3,17,1992) + time.hms(16,45,44))], [16.00]],
   [[xdate.hour(date.mdy(2,25,1996) + time.hms(21,30,57))], [21.00]],
-  [[xdate.hour(date.mdy(9,29,41) + time.hms(4,25,9))], [4.00]],
+  [[xdate.hour(date.mdy(9,29,1941) + time.hms(4,25,9))], [4.00]],
   [[xdate.hour(date.mdy(4,19,43) + time.hms(6,49,27))], [6.00]],
   [[xdate.hour(date.mdy(10,7,43) + time.hms(2,57,52))], [2.00]],
   [[xdate.hour(date.mdy(3,17,92) + time.hms(16,45,44))], [16.00]],
@@ -1331,7 +1443,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.jday(date.mdy(10,7,1943) + time.hms(2,57,52))], [280.00]],
   [[xdate.jday(date.mdy(3,17,1992) + time.hms(16,45,44))], [77.00]],
   [[xdate.jday(date.mdy(2,25,1996) + time.hms(21,30,57))], [56.00]],
-  [[xdate.jday(date.mdy(9,29,41) + time.hms(4,25,9))], [272.00]],
+  [[xdate.jday(date.mdy(9,29,1941) + time.hms(4,25,9))], [272.00]],
   [[xdate.jday(date.mdy(4,19,43) + time.hms(6,49,27))], [109.00]],
   [[xdate.jday(date.mdy(10,7,43) + time.hms(2,57,52))], [280.00]],
   [[xdate.jday(date.mdy(3,17,92) + time.hms(16,45,44))], [77.00]],
@@ -1355,7 +1467,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.mday(date.mdy(10,7,1943) + time.hms(2,57,52))], [7.00]],
   [[xdate.mday(date.mdy(3,17,1992) + time.hms(16,45,44))], [17.00]],
   [[xdate.mday(date.mdy(2,25,1996) + time.hms(21,30,57))], [25.00]],
-  [[xdate.mday(date.mdy(9,29,41) + time.hms(4,25,9))], [29.00]],
+  [[xdate.mday(date.mdy(9,29,1941) + time.hms(4,25,9))], [29.00]],
   [[xdate.mday(date.mdy(4,19,43) + time.hms(6,49,27))], [19.00]],
   [[xdate.mday(date.mdy(10,7,43) + time.hms(2,57,52))], [7.00]],
   [[xdate.mday(date.mdy(3,17,92) + time.hms(16,45,44))], [17.00]],
@@ -1376,7 +1488,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.minute(date.mdy(10,7,1943) + time.hms(2,57,52))], [57.00]],
   [[xdate.minute(date.mdy(3,17,1992) + time.hms(16,45,44))], [45.00]],
   [[xdate.minute(date.mdy(2,25,1996) + time.hms(21,30,57))], [30.00]],
-  [[xdate.minute(date.mdy(9,29,41) + time.hms(4,25,9))], [25.00]],
+  [[xdate.minute(date.mdy(9,29,1941) + time.hms(4,25,9))], [25.00]],
   [[xdate.minute(date.mdy(4,19,43) + time.hms(6,49,27))], [49.00]],
   [[xdate.minute(date.mdy(10,7,43) + time.hms(2,57,52))], [57.00]],
   [[xdate.minute(date.mdy(3,17,92) + time.hms(16,45,44))], [45.00]],
@@ -1397,7 +1509,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.month(date.mdy(10,7,1943) + time.hms(2,57,52))], [10.00]],
   [[xdate.month(date.mdy(3,17,1992) + time.hms(16,45,44))], [3.00]],
   [[xdate.month(date.mdy(2,25,1996) + time.hms(21,30,57))], [2.00]],
-  [[xdate.month(date.mdy(9,29,41) + time.hms(4,25,9))], [9.00]],
+  [[xdate.month(date.mdy(9,29,1941) + time.hms(4,25,9))], [9.00]],
   [[xdate.month(date.mdy(4,19,43) + time.hms(6,49,27))], [4.00]],
   [[xdate.month(date.mdy(10,7,43) + time.hms(2,57,52))], [10.00]],
   [[xdate.month(date.mdy(3,17,92) + time.hms(16,45,44))], [3.00]],
@@ -1418,7 +1530,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.quarter(date.mdy(10,7,1943) + time.hms(2,57,52))], [4.00]],
   [[xdate.quarter(date.mdy(3,17,1992) + time.hms(16,45,44))], [1.00]],
   [[xdate.quarter(date.mdy(2,25,1996) + time.hms(21,30,57))], [1.00]],
-  [[xdate.quarter(date.mdy(9,29,41) + time.hms(4,25,9))], [3.00]],
+  [[xdate.quarter(date.mdy(9,29,1941) + time.hms(4,25,9))], [3.00]],
   [[xdate.quarter(date.mdy(4,19,43) + time.hms(6,49,27))], [2.00]],
   [[xdate.quarter(date.mdy(10,7,43) + time.hms(2,57,52))], [4.00]],
   [[xdate.quarter(date.mdy(3,17,92) + time.hms(16,45,44))], [1.00]],
@@ -1439,7 +1551,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.second(date.mdy(10,7,1943) + time.hms(2,57,52))], [52.00]],
   [[xdate.second(date.mdy(3,17,1992) + time.hms(16,45,44))], [44.00]],
   [[xdate.second(date.mdy(2,25,1996) + time.hms(21,30,57))], [57.00]],
-  [[xdate.second(date.mdy(9,29,41) + time.hms(4,25,9))], [9.00]],
+  [[xdate.second(date.mdy(9,29,1941) + time.hms(4,25,9))], [9.00]],
   [[xdate.second(date.mdy(4,19,43) + time.hms(6,49,27))], [27.00]],
   [[xdate.second(date.mdy(10,7,43) + time.hms(2,57,52))], [52.00]],
   [[xdate.second(date.mdy(3,17,92) + time.hms(16,45,44))], [44.00]],
@@ -1460,7 +1572,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.tday(date.mdy(10,7,1943) + time.hms(2,57,52))], [131845.00]],
   [[xdate.tday(date.mdy(3,17,1992) + time.hms(16,45,44))], [149539.00]],
   [[xdate.tday(date.mdy(2,25,1996) + time.hms(21,30,57))], [150979.00]],
-  [[xdate.tday(date.mdy(9,29,41) + time.hms(4,25,9))], [131107.00]],
+  [[xdate.tday(date.mdy(9,29,1941) + time.hms(4,25,9))], [131107.00]],
   [[xdate.tday(date.mdy(4,19,43) + time.hms(6,49,27))], [131674.00]],
   [[xdate.tday(date.mdy(10,7,43) + time.hms(2,57,52))], [131845.00]],
   [[xdate.tday(date.mdy(3,17,92) + time.hms(16,45,44))], [149539.00]],
@@ -1481,7 +1593,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.time(date.mdy(10,7,1943) + time.hms(2,57,52))], [10672.00]],
   [[xdate.time(date.mdy(3,17,1992) + time.hms(16,45,44))], [60344.00]],
   [[xdate.time(date.mdy(2,25,1996) + time.hms(21,30,57))], [77457.00]],
-  [[xdate.time(date.mdy(9,29,41) + time.hms(4,25,9))], [15909.00]],
+  [[xdate.time(date.mdy(9,29,1941) + time.hms(4,25,9))], [15909.00]],
   [[xdate.time(date.mdy(4,19,43) + time.hms(6,49,27))], [24567.00]],
   [[xdate.time(date.mdy(10,7,43) + time.hms(2,57,52))], [10672.00]],
   [[xdate.time(date.mdy(3,17,92) + time.hms(16,45,44))], [60344.00]],
@@ -1502,7 +1614,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.week(date.mdy(10,7,1943) + time.hms(2,57,52))], [40.00]],
   [[xdate.week(date.mdy(3,17,1992) + time.hms(16,45,44))], [11.00]],
   [[xdate.week(date.mdy(2,25,1996) + time.hms(21,30,57))], [8.00]],
-  [[xdate.week(date.mdy(9,29,41) + time.hms(4,25,9))], [39.00]],
+  [[xdate.week(date.mdy(9,29,1941) + time.hms(4,25,9))], [39.00]],
   [[xdate.week(date.mdy(4,19,43) + time.hms(6,49,27))], [16.00]],
   [[xdate.week(date.mdy(10,7,43) + time.hms(2,57,52))], [40.00]],
   [[xdate.week(date.mdy(3,17,92) + time.hms(16,45,44))], [11.00]],
@@ -1523,7 +1635,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.wkday(date.mdy(10,7,1943))], [5.00]],
   [[xdate.wkday(date.mdy(3,17,1992))], [3.00]],
   [[xdate.wkday(date.mdy(2,25,1996))], [1.00]],
-  [[xdate.wkday(date.mdy(9,29,41))], [2.00]],
+  [[xdate.wkday(date.mdy(9,29,1941))], [2.00]],
   [[xdate.wkday(date.mdy(4,19,43))], [2.00]],
   [[xdate.wkday(date.mdy(10,7,43))], [5.00]],
   [[xdate.wkday(date.mdy(3,17,92))], [3.00]],
@@ -1544,7 +1656,7 @@ CHECK_EXPR_EVAL([xdate],
   [[xdate.year(date.mdy(10,7,1943) + time.hms(2,57,52))], [1943.00]],
   [[xdate.year(date.mdy(3,17,1992) + time.hms(16,45,44))], [1992.00]],
   [[xdate.year(date.mdy(2,25,1996) + time.hms(21,30,57))], [1996.00]],
-  [[xdate.year(date.mdy(9,29,41) + time.hms(4,25,9))], [1941.00]],
+  [[xdate.year(date.mdy(9,29,1941) + time.hms(4,25,9))], [1941.00]],
   [[xdate.year(date.mdy(4,19,43) + time.hms(6,49,27))], [1943.00]],
   [[xdate.year(date.mdy(10,7,43) + time.hms(2,57,52))], [1943.00]],
   [[xdate.year(date.mdy(3,17,92) + time.hms(16,45,44))], [1992.00]],
@@ -1565,8 +1677,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(4,19,1943), date.mdy(10,7,1943), 'years')], [0.00]],
   [[datediff(date.mdy(10,7,1943), date.mdy(3,17,1992), 'years')], [-48.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(2,25,1996), 'years')], [-3.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(2,25,1996), 'years')], [-54.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(4,19,43), 'years')], [-1.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(2,25,1996), 'years')], [-54.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(4,19,43), 'years')], [-1.00]],
   [[datediff(date.mdy(4,19,43), date.mdy(10,7,43), 'years')], [0.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(3,17,92), 'years')], [-48.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(2,25,96), 'years')], [-3.00]],
@@ -1588,8 +1700,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(4,19,1943), date.mdy(10,7,1943), 'quarters')], [-1.00]],
   [[datediff(date.mdy(10,7,1943), date.mdy(3,17,1992), 'quarters')], [-193.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(2,25,1996), 'quarters')], [-15.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(2,25,1996), 'quarters')], [-217.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(4,19,43), 'quarters')], [-6.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(2,25,1996), 'quarters')], [-217.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(4,19,43), 'quarters')], [-6.00]],
   [[datediff(date.mdy(4,19,43), date.mdy(10,7,43), 'quarters')], [-1.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(3,17,92), 'quarters')], [-193.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(2,25,96), 'quarters')], [-15.00]],
@@ -1611,8 +1723,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(4,19,1943), date.mdy(10,7,1943), 'months')], [-5.00]],
   [[datediff(date.mdy(10,7,1943), date.mdy(3,17,1992), 'months')], [-581.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(2,25,1996), 'months')], [-47.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(2,25,1996), 'months')], [-652.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(4,19,43), 'months')], [-18.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(2,25,1996), 'months')], [-652.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(4,19,43), 'months')], [-18.00]],
   [[datediff(date.mdy(4,19,43), date.mdy(10,7,43), 'months')], [-5.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(3,17,92), 'months')], [-581.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(2,25,96), 'months')], [-47.00]],
@@ -1634,8 +1746,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(4,19,1943), date.mdy(10,7,1943), 'weeks')], [-24.00]],
   [[datediff(date.mdy(10,7,1943), date.mdy(3,17,1992), 'weeks')], [-2527.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(2,25,1996), 'weeks')], [-205.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(2,25,1996), 'weeks')], [-2838.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(4,19,43), 'weeks')], [-81.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(2,25,1996), 'weeks')], [-2838.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(4,19,43), 'weeks')], [-81.00]],
   [[datediff(date.mdy(4,19,43), date.mdy(10,7,43), 'weeks')], [-24.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(3,17,92), 'weeks')], [-2527.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(2,25,96), 'weeks')], [-205.00]],
@@ -1657,8 +1769,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(4,19,1943), date.mdy(10,7,1943), 'days')], [-171.00]],
   [[datediff(date.mdy(10,7,1943), date.mdy(3,17,1992), 'days')], [-17694.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(2,25,1996), 'days')], [-1440.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(2,25,1996), 'days')], [-19872.00]],
-  [[datediff(date.mdy(9,29,41), date.mdy(4,19,43), 'days')], [-567.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(2,25,1996), 'days')], [-19872.00]],
+  [[datediff(date.mdy(9,29,1941), date.mdy(4,19,43), 'days')], [-567.00]],
   [[datediff(date.mdy(4,19,43), date.mdy(10,7,43), 'days')], [-171.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(3,17,92), 'days')], [-17694.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(2,25,96), 'days')], [-1440.00]],
@@ -1680,8 +1792,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(10,7,1943), date.mdy(4,19,1943), 'years')], [0.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(10,7,1943), 'years')], [48.00]],
   [[datediff(date.mdy(2,25,1996), date.mdy(3,17,1992), 'years')], [3.00]],
-  [[datediff(date.mdy(2,25,1996), date.mdy(9,29,41), 'years')], [54.00]],
-  [[datediff(date.mdy(4,19,43), date.mdy(9,29,41), 'years')], [1.00]],
+  [[datediff(date.mdy(2,25,1996), date.mdy(9,29,1941), 'years')], [54.00]],
+  [[datediff(date.mdy(4,19,43), date.mdy(9,29,1941), 'years')], [1.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(4,19,43), 'years')], [0.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(10,7,43), 'years')], [48.00]],
   [[datediff(date.mdy(2,25,96), date.mdy(3,17,92), 'years')], [3.00]],
@@ -1703,8 +1815,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(10,7,1943), date.mdy(4,19,1943), 'months')], [5.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(10,7,1943), 'months')], [581.00]],
   [[datediff(date.mdy(2,25,1996), date.mdy(3,17,1992), 'months')], [47.00]],
-  [[datediff(date.mdy(2,25,1996), date.mdy(9,29,41), 'months')], [652.00]],
-  [[datediff(date.mdy(4,19,43), date.mdy(9,29,41), 'months')], [18.00]],
+  [[datediff(date.mdy(2,25,1996), date.mdy(9,29,1941), 'months')], [652.00]],
+  [[datediff(date.mdy(4,19,43), date.mdy(9,29,1941), 'months')], [18.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(4,19,43), 'months')], [5.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(10,7,43), 'months')], [581.00]],
   [[datediff(date.mdy(2,25,96), date.mdy(3,17,92), 'months')], [47.00]],
@@ -1726,8 +1838,8 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(10,7,1943), date.mdy(4,19,1943), 'quarters')], [1.00]],
   [[datediff(date.mdy(3,17,1992), date.mdy(10,7,1943), 'quarters')], [193.00]],
   [[datediff(date.mdy(2,25,1996), date.mdy(3,17,1992), 'quarters')], [15.00]],
-  [[datediff(date.mdy(2,25,1996), date.mdy(9,29,41), 'quarters')], [217.00]],
-  [[datediff(date.mdy(4,19,43), date.mdy(9,29,41), 'quarters')], [6.00]],
+  [[datediff(date.mdy(2,25,1996), date.mdy(9,29,1941), 'quarters')], [217.00]],
+  [[datediff(date.mdy(4,19,43), date.mdy(9,29,1941), 'quarters')], [6.00]],
   [[datediff(date.mdy(10,7,43), date.mdy(4,19,43), 'quarters')], [1.00]],
   [[datediff(date.mdy(3,17,92), date.mdy(10,7,43), 'quarters')], [193.00]],
   [[datediff(date.mdy(2,25,96), date.mdy(3,17,92), 'quarters')], [15.00]],
@@ -1735,7 +1847,42 @@ CHECK_EXPR_EVAL([datediff],
   [[datediff(date.mdy(7,18,2094), date.mdy(11,10,2038), 'quarters')], [222.00]],
   [[datediff(date.mdy(2,29,1904), date.mdy(2,29,1900), 'quarters')], [15.00]],
   [[datediff(date.mdy(2,29,1908), date.mdy(2,29,1904), 'quarters')], [16.00]],
-  [[datediff(date.mdy(2,28,1903), date.mdy(2,29,1900), 'quarters')], [11.00]])
+  [[datediff(date.mdy(2,28,1903), date.mdy(2,29,1900), 'quarters')], [11.00]],
+
+dnl time of day is significant for DATEDIFF
+  [[datediff(date.mdy(10,15,1910) + 234, date.mdy(10,10,1910) + 123, 'days')],
+    [5.00]],
+  [[datediff(date.mdy(10,15,1910) + 123, date.mdy(10,10,1910) + 234, 'days')],
+    [4.00]],
+  [[datediff(date.mdy(10,24,1910) + 234, date.mdy(10,10,1910) + 123, 'weeks')],
+    [2.00]],
+  [[datediff(date.mdy(10,24,1910) + 123, date.mdy(10,10,1910) + 234, 'weeks')],
+    [1.00]],
+  [[datediff(date.mdy(10,10,1910) + 234, date.mdy(5,10,1910) + 123, 'months')],
+    [5.00]],
+  [[datediff(date.mdy(10,10,1910) + 123, date.mdy(5,10,1910) + 234, 'months')],
+    [4.00]],
+  [[datediff(date.mdy(5,10,1919) + 234, date.mdy(5,10,1910) + 123, 'years')],
+    [9.00]],
+  [[datediff(date.mdy(5,10,1919) + 123, date.mdy(5,10,1910) + 234, 'years')],
+    [8.00]],
+
+  [[datediff(date.mdy(10,10,1910) + 123, date.mdy(10,15,1910) + 234, 'days')],
+    [-5.00]],
+  [[datediff(date.mdy(10,10,1910) + 234, date.mdy(10,15,1910) + 123, 'days')],
+    [-4.00]],
+  [[datediff(date.mdy(10,10,1910) + 123, date.mdy(10,24,1910) + 234, 'weeks')],
+    [-2.00]],
+  [[datediff(date.mdy(10,10,1910) + 234, date.mdy(10,24,1910) + 123, 'weeks')],
+    [-1.00]],
+  [[datediff(date.mdy(5,10,1910) + 123, date.mdy(10,10,1910) + 234, 'months')],
+    [-5.00]],
+  [[datediff(date.mdy(5,10,1910) + 234, date.mdy(10,10,1910) + 123, 'months')],
+    [-4.00]],
+  [[datediff(date.mdy(5,10,1910) + 123, date.mdy(5,10,1919) + 234, 'years')],
+    [-9.00]],
+  [[datediff(date.mdy(5,10,1910) + 234, date.mdy(5,10,1919) + 123, 'years')],
+    [-8.00]])
 
 CHECK_EXPR_EVAL([datesum],
 dnl DATESUM with non-leap year
@@ -1808,7 +1955,13 @@ dnl DATESUM with leap year
   [[ctime.days(datesum(date.mdy(6,10,1648), 1, 'hours') - date.mdy(6,10,1648))], [0.04]],
   [[ctime.days(datesum(date.mdy(6,30,1680), 2.5, 'hours') - date.mdy(6,30,1680))], [0.10]],
   [[ctime.days(datesum(date.mdy(6,19,1768), -4, 'hours') - date.mdy(6,19,1768))], [-0.17]],
-  [[ctime.days(datesum(date.mdy(8,2,1819), 5, 'hours') - date.mdy(8,2,1819))], [0.21]])
+  [[ctime.days(datesum(date.mdy(8,2,1819), 5, 'hours') - date.mdy(8,2,1819))], [0.21]],
+
+dnl DATESUM preserves time-of-day for units of days and longer.
+  [[ctime.days(datesum(date.mdy(8,2,1819) + time.hms(1,2,3), 5, 'days') - (date.mdy(8,2,1819) + time.hms(1,2,3)))], [5.00]],
+  [[ctime.days(datesum(date.mdy(8,2,1819) + time.hms(1,2,3), 5, 'weeks') - (date.mdy(8,2,1819) + time.hms(1,2,3)))], [35.00]],
+  [[ctime.days(datesum(date.mdy(8,2,1819) + time.hms(1,2,3), 5, 'months') - (date.mdy(8,2,1819) + time.hms(1,2,3)))], [153.00]],
+  [[ctime.days(datesum(date.mdy(8,2,1819) + time.hms(1,2,3), 5, 'years') - (date.mdy(8,2,1819) + time.hms(1,2,3)))], [1827.00]])
 
 CHECK_EXPR_EVAL([miscellaneous],
 dnl These test values are from Applied Statistics, Algorithm AS 310.
@@ -1843,3 +1996,231 @@ dnl Tests correctness of generic optimizations in optimize_tree().
   [[mod(0, x)], [0.00], [], [(X = 5.00)]],
   [[x ** 1], [5.00], [], [(X = 5.00)]],
   [[x ** 2], [25.00], [], [(X = 5.00)]])
+
+CHECK_EXPR_EVAL([negative checks],
+  [[$nonexistent], [error], [error: DEBUG EVALUATE: Unknown system variable $nonexistent.]],
+  [[RANGE(1, 2)], [error], [error: DEBUG EVALUATE: RANGE(number, number, number[, number, number]...) must have an odd number of arguments.]],
+  [[CONCAT.1('a', 'b')], [error], [error: DEBUG EVALUATE: CONCAT(string[, string]...) function cannot accept suffix .1 to specify the minimum number of valid arguments.]],
+  [[foobar(x)], [error], [error: DEBUG EVALUATE: No function or vector named foobar.]],
+  [[CONCAT.1('a' b)], [error], [error: DEBUG EVALUATE: Syntax error at `b': expecting `,' or `)'.]],
+  [[NCDF.CHISQ(1, 2, 3)], [error], [error: DEBUG EVALUATE: NCDF.CHISQ(number, number, number) is not available in this version of PSPP.]])
+
+AT_SETUP([LAG function])
+AT_DATA([lag.sps], [dnl
+data list /W 1.
+begin data.
+1
+2
+3
+4
+5
+end data.
+
+compute X=lag(w,1).
+compute Y=lag(x).
+compute Z=lag(w,2).
+list.
+])
+AT_CHECK([pspp -o pspp.csv lag.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Reading 1 record from INLINE.
+Variable,Record,Columns,Format
+W,1,1-1,F1.0
+
+Table: Data List
+W,X,Y,Z
+1,.  ,.  ,.  @&t@
+2,1.00,.  ,.  @&t@
+3,2.00,1.00,1.00
+4,3.00,2.00,2.00
+5,4.00,3.00,3.00
+])
+AT_CLEANUP
+
+AT_SETUP([LAG crash bug])
+AT_DATA([lag.sps], [dnl
+DATA LIST LIST /x.
+BEGIN DATA
+1
+2
+END DATA.
+
+DO IF (x <> LAG(x) ).
+       ECHO 'hello'.
+END IF.
+
+EXECUTE.
+])
+AT_CHECK([pspp -o pspp.csv lag.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Reading free-form data from INLINE.
+Variable,Format
+x,F8.0
+
+hello
+])
+AT_CLEANUP
+
+dnl Tests for a bug which caused UNIFORM(x) to always return zero.
+AT_SETUP([UNIFORM function])
+AT_DATA([uniform.sps], [dnl
+set seed=10.
+input program.
++ loop #i = 1 to 20.
++    do repeat response=R1.
++       compute response = uniform(10).
++    end repeat.
++    end case.
++ end loop.
++ end file.
+end input program.
+
+list.
+])
+AT_CHECK([pspp -o pspp.csv uniform.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Data List
+R1
+7.71
+2.99
+.21
+4.95
+6.34
+4.43
+7.49
+8.32
+4.99
+5.83
+2.25
+.25
+1.98
+7.09
+7.61
+2.66
+1.69
+2.64
+.88
+1.50
+])
+AT_CLEANUP
+
+AT_SETUP([VALUELABEL function])
+AT_DATA([valuelabel.sps], [dnl
+DATA LIST notable /n 1 s 2(a).
+VALUE LABELS /n 0 'Very dissatisfied'
+                1 'Dissatisfied'
+               1.5 'Slightly Peeved'
+                2 'Neutral'
+                3 'Satisfied'
+                4 'Very satisfied'.
+VALUE LABELS /s 'a' 'Wouldn''t buy again'
+                'b' 'Unhappy'
+                'c' 'Bored'
+                'd' 'Satiated'
+                'e' 'Elated'.
+STRING nlabel slabel(a10).
+COMPUTE nlabel = VALUELABEL(n).
+COMPUTE slabel = VALUELABEL(s).
+LIST.
+BEGIN DATA.
+
+0a
+1b
+2c
+3d
+4e
+5f
+6g
+END DATA.
+])
+AT_CHECK([pspp -o pspp.csv valuelabel.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Data List
+n,s,nlabel,slabel
+.,,,
+0,a,Very dissa,Wouldn't b
+1,b,Dissatisfi,Unhappy
+2,c,Neutral,Bored
+3,d,Satisfied,Satiated
+4,e,Very satis,Elated
+5,f,,
+6,g,,
+])
+AT_CLEANUP
+
+AT_SETUP([variables in expressions])
+AT_DATA([variables.sps], [dnl
+DATA LIST NOTABLE/N1 TO N5 1-5.
+MISSING VALUES N1 TO N5 (3 THRU 5, 1).
+BEGIN DATA.
+12345
+6789
+END DATA.
+
+COMPUTE P1=N1.
+COMPUTE P2=N2.
+COMPUTE P3=N3.
+COMPUTE P4=N4.
+COMPUTE P5=N5.
+
+COMPUTE MC=NMISS(N1 TO N5).
+COMPUTE VC=NVALID(N1 TO N5).
+
+COMPUTE S1=SYSMIS(N1).
+COMPUTE S2=SYSMIS(N2).
+COMPUTE S3=SYSMIS(N3).
+COMPUTE S4=SYSMIS(N4).
+COMPUTE S5=SYSMIS(N5).
+
+COMPUTE M1=MISSING(N1).
+COMPUTE M2=MISSING(N2).
+COMPUTE M3=MISSING(N3).
+COMPUTE M4=MISSING(N4).
+COMPUTE M5=MISSING(N5).
+
+COMPUTE V1=VALUE(N1).
+COMPUTE V2=VALUE(N2).
+COMPUTE V3=VALUE(N3).
+COMPUTE V4=VALUE(N4).
+COMPUTE V5=VALUE(N5).
+
+FORMATS ALL (F1).
+
+LIST.
+])
+AT_CHECK([pspp -o pspp.csv variables.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Data List
+N1,N2,N3,N4,N5,P1,P2,P3,P4,P5,MC,VC,S1,S2,S3,S4,S5,M1,M2,M3,M4,M5,V1,V2,V3,V4,V5
+1,2,3,4,5,.,2,.,.,.,4,1,0,0,0,0,0,1,0,1,1,1,1,2,3,4,5
+6,7,8,9,.,6,7,8,9,.,1,4,0,0,0,0,1,0,0,0,0,1,6,7,8,9,.
+])
+AT_CLEANUP
+
+AT_SETUP([vectors in expressions])
+AT_DATA([vectors.sps], [dnl
+DATA LIST NOTABLE /N1 TO N5 1-5.
+MISSING VALUES N1 TO N5 (3 THRU 5, 1).
+BEGIN DATA.
+12345
+6789
+END DATA.
+
+VECTOR N=N1 TO N5.
+VECTOR X(5).
+LOOP I=1 TO 5.
+COMPUTE X(I)=N(I) + 1.
+END LOOP.
+
+FORMATS ALL (F2).
+
+LIST.
+])
+AT_CHECK([pspp -o pspp.csv vectors.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Data List
+N1,N2,N3,N4,N5,X1,X2,X3,X4,X5,I
+1,2,3,4,5,.,3,.,.,.,5
+6,7,8,9,.,7,8,9,10,.,5
+])
+AT_CLEANUP