# Process with autom4te to create an -*- Autotest -*- test suite.

AT_INIT([expr-test])
# AT_COPYRIGHT([])

# AT_TESTED([expr-test])

# Usage: _EXPR_TEST(<flags>, <dds>, <constraint>, <baseline file>, <xfail?>)

m4_define([_EXPR_TEST], [
    # AT_BANNER([Test $1 $2 $3])
    AT_SETUP([expr-test $1 $2 -k $3 ($5)])
    AT_KEYWORDS([expr])

    # Added || true because expr-test returns 0 (failure) for some of
    # these tests which is correct for the test - we expect some of
    # the input to trigger an error response from the parser, et
    # cetera. That's also why we capture both stdout and stderr -
    # successful runs are sent to stdout while the errors are sent to
    # stderr.

    AT_CHECK([$abs_builddir/expr-test $1 $2 -k $3 -f "dummy" || true], [], [stdout], [stderr])
    AT_CHECK([diff -b -B $4 stdout || diff -b -B $4 stderr], [], [ignore],[],[])
    AT_XFAIL_IF([test "$5" = "xfail"])
    AT_CLEANUP
])


m4_define([EXPR_RESPONSE_P], [
    # AT_BANNER([EXPR response for $1, $2, $4.])
    # Test the serialize/deserialize methods
    _EXPR_TEST([-w], [$abs_srcdir/expr-testsuite/$1], [$2], [$abs_srcdir/expr-testsuite/$3.base], $4)
    # Test the intern_data method (which combines serialize and deserialze)
    _EXPR_TEST([-W], [$abs_srcdir/expr-testsuite/$1], [$2], [$abs_srcdir/expr-testsuite/$3.base], $4)
])

# The -b option to expr-test uses the 'series values' feature of the Test
# classes.
m4_define([EXPR_RESPONSE_B], [
    # AT_BANNER([EXPR response for $1, $2, $4.])
    _EXPR_TEST([-b -w], [$abs_srcdir/expr-testsuite/$1], [$2], [$abs_srcdir/expr-testsuite/$3.base], $4)
    _EXPR_TEST([-b -W], [$abs_srcdir/expr-testsuite/$1], [$2], [$abs_srcdir/expr-testsuite/$3.base], $4)
])

EXPR_RESPONSE_P([test.1], [i], [test.1], [pass])
EXPR_RESPONSE_P([test.1], [i,j], [test.1a], [pass])
EXPR_RESPONSE_P([test.1], ['i,j&i=j'], [test.1b], [pass])
EXPR_RESPONSE_P([test.1], ['i&i=j'], [test.1d], [pass])
EXPR_RESPONSE_P([test.2], [s1], [test.2], [pass])
EXPR_RESPONSE_P([test.2], [s2], [test.2a], [pass])
EXPR_RESPONSE_P([test.2], [s2,s3], [test.2b], [pass])
EXPR_RESPONSE_P([test.2], [s2[[2:2:4]],s3.o], [test.2c], [pass])

EXPR_RESPONSE_P([test.2], [s2[[2:2:4]].m], [test.2d], [pass])
EXPR_RESPONSE_P([test.2], [s2[[2:2:4]].m,s2[[2:2:4]].l], [test.2e], [pass])

EXPR_RESPONSE_P([test.2a], [s2[[2:4]].m[[0:4]],s2[[2:4]].l[[0:5]]], [test.2f], [pass])
EXPR_RESPONSE_P([test.3], [i[[1:10]]], [test.3], [pass])
EXPR_RESPONSE_P([test.4], ['s&s=~"^Silly.*"'], [test.4], [pass])

dnl In changing the TestStr class so that it writes a constant value (Silly ...: 1)
dnl I had to hack this test to use the -b option to expr-test. EXPR_RESPONSE_P uses
dnl only the -w/-W options, so I dropped using that macro kluge and went right for the
dnl actual test macro. 12/2/13/ jhrg
dnl
dnl EXPR_RESPONSE_P([test.e], ['names.s&names.s=~".*: 3"'], [test.ea], [pass])
    
_EXPR_TEST([-b -w], [$abs_srcdir/expr-testsuite/test.e], ['names.s&names.s=~".*: 3"'], 
    [$abs_srcdir/expr-testsuite/test.ea.base], [pass])
    
_EXPR_TEST([-b -W], [$abs_srcdir/expr-testsuite/test.e], ['names.s&names.s=~".*: 3"'], 
    [$abs_srcdir/expr-testsuite/test.ea.base], [pass])

dnl since 'Silly ...:5' will never be produced, this tests what happens when the sequence
dnl does not contain the value. Note that this test does not have to be rewritten because
dnl of the change to the TestStr code. 12/2/13 jhrg
EXPR_RESPONSE_P([test.e], ['names.s&names.s=~".*: 5"'], [test.eb], [pass])

EXPR_RESPONSE_P([test.5], [g[[0:2:4]][[0]][[0]]], [test.5], [pass])
EXPR_RESPONSE_P([test.5], [g[[0:2:4]][[0:2:4]][[0:2:4]]], [test.5a], [pass])
EXPR_RESPONSE_P([test.6], [i], [test.6], [pass])
EXPR_RESPONSE_P([test.6], [i[[1:2]][[2:4]]], [test.6a], [pass])
EXPR_RESPONSE_P([test.5], [g.val[[0:1]][[0:1]][[0:1]]], [test.5b], [pass])
EXPR_RESPONSE_P([test.5], [g.length], [test.5c], [pass])
EXPR_RESPONSE_P([test.5], [g.length,g.width], [test.5d], [pass])
EXPR_RESPONSE_P([test.2], [j,o], [test.2g], [pass])
EXPR_RESPONSE_P([test.8], ["data%23i[[0:2:9]][[0:2]]"], [test.8], [pass])
EXPR_RESPONSE_P([test.7], [x,y,f], [test.7], [pass])
EXPR_RESPONSE_P([test.8], ["x%23y,y"], [test.8a], [pass])
EXPR_RESPONSE_P([test.8], ["data%20name,y"], [test.8b], [pass])
EXPR_RESPONSE_P([test.9], ["Data-Set-2.fakeDim0[[0:3]],Data-Set-2.fakeDim1[[0:3]]"], [test.9], [pass])
EXPR_RESPONSE_P([test.5], [g[[1:4:9]]], [test.5e], [pass])
EXPR_RESPONSE_P([test.6], [i[[1:4:9]]], [test.6b], [pass])

# New tests for server functions that take arrays and include array projections
# Added 10/23/13 jhrg
EXPR_RESPONSE_P([test.6], [scale\(i,2\)], [test.6.func1], [pass])
EXPR_RESPONSE_P([test.6], [scale\(i[[2:4]][[3:6]],2\)], [test.6.func2], [pass])

EXPR_RESPONSE_P([test.5], [scale\(i[[3]],2\)], [test.5.func3], [pass])
# This doesn't work yet 10/23/13 jhrg 
EXPR_RESPONSE_P([test.5], [scale\(j,2\)], [test.5.func4], [pass])

EXPR_RESPONSE_P([test.a], ["" -b], [test.a], [pass])
EXPR_RESPONSE_P([test.a], ["&i<2000" -b], [test.aa], [pass])
EXPR_RESPONSE_P([test.a], ["j&i>2000" -b], [test.ab], [pass])
EXPR_RESPONSE_P([test.a], ["i,j&i<0" -b], [test.ac], [pass])
EXPR_RESPONSE_P([test.b], ["" -b], [test.b], [pass])
EXPR_RESPONSE_P([test.b], ["i,f" -b], [test.ba], [pass])
EXPR_RESPONSE_P([test.b], ["i,f&i<2000" -b], [test.bb], [pass])
EXPR_RESPONSE_P([test.b], ["i,f&f<0" -b], [test.bc], [pass])
EXPR_RESPONSE_P([test.b], ["i,j&i<2000" -b], [test.bd], [pass])
EXPR_RESPONSE_P([test.b], ["&i<0" -b], [test.be], [pass])
EXPR_RESPONSE_P([test.d], ["" -b], [test.d], [pass])
EXPR_RESPONSE_P([test.d], ["i,f,a" -b], [test.da], [pass])
EXPR_RESPONSE_P([test.d], ["i,f,a&i<2000" -b], [test.db], [pass])
EXPR_RESPONSE_P([test.d], ["i,f,a&f<0" -b], [test.dc], [pass])
EXPR_RESPONSE_P([test.d], ["i,f,a&a<10" -b], [test.dd], [pass])
EXPR_RESPONSE_P([test.d], ["i,f&i<2000" -b], [test.de], [pass])
EXPR_RESPONSE_P([test.d], ["i&i<2000" -b], [test.df], [pass])
EXPR_RESPONSE_P([test.d], ["i,f,a&i<0" -b], [test.dg], [pass])

EXPR_RESPONSE_B([test.61], [i], [data.61a], [pass])
EXPR_RESPONSE_B([test.61], [ i[[0:2]][[0:2]] ], [data.61b], [pass])
EXPR_RESPONSE_B([test.61], [ i[[1:2]][[0:2]] ], [data.61c], [pass])
EXPR_RESPONSE_B([test.61], [ i[[1:2]][[1:2]] ], [data.61d], [pass])
EXPR_RESPONSE_B([test.c0], [SST], [data.z1], [pass])

EXPR_RESPONSE_B([test.f], [""], [test.fa], [pass])
EXPR_RESPONSE_B([test.f], ["&i<3000"], [test.fb], [pass])
