### MA 02111-1307, USA.
###--------------------------------------------------------------------------
-### tvec
+### Preliminaries.
-dnl test_filter(CMD, SED, RC, STDOUT, STDERR)
-m4_define([test_filter], [
-AT_CHECK([$1], [$3], [stdout-nolog], [stderr-nolog])
-##mv stdout rawout; mv stderr rawerr
-AT_CHECK([sed "AS_ESCAPE([$2])" stdout], [0], [$4])
-AT_CHECK([sed "AS_ESCAPE([$2])" stderr], [0], [$5])])
+dnl padding_string(STRING, N, [PAD])
+m4_define([padding_string],
+[m4_if([m4_expr([m4_len([$1]) > $2])], [1], [],
+[m4_for([i], m4_len([$1]), [($2) - 1], [1], [m4_default([$3], [ ])])])])
-dnl mismatch_filter
-m4_define([mismatch_filter],
- [s/\(@%:@<@<:@0-9a-zA-Z_-@:>@*\) @<:@^>@:>@*>/\1 ...>/g])
+dnl left_pad(STRING, N, [PAD])
+dnl right_pad(STRING, N, [PAD])
+m4_define([left_pad], [padding_string([$1], [$2], [$3])$1])
+m4_define([right_pad], [$1[]padding_string([$1], [$2], [$3])])
+
+dnl check_template(CMD, RC, STDOUT, STDERR)
+m4_define([check_template], [
+AT_CHECK([$1], [$2], [stdout], [stderr-nolog])
+AT_DATA([expout.tpl], [$3])
+$PYTHON $abs_srcdir/template-canonify expout.tpl stdout expout stdout.found
+AT_DATA([experr.tpl], [$4])
+$PYTHON $abs_srcdir/template-canonify experr.tpl stderr experr stderr.found
+AT_CHECK([cat stdout.found; cat stderr.found >&2], [0], [expout], [experr])])
dnl test_parse(TY, IN, OUT)
m4_define([test_parse], [
AT_DATA([tv],
[;;; -*-conf-*-
-[[$1]]
+@<:@$1@:>@
$1 = $2
-@status = ?
+@show = t
])
-test_filter([BUILDDIR/t/tvec.t -fh tv], [mismatch_filter], [1],
-[tv:3: `$1' FAILED
- actual status = `.'
- expected status = `?'
- matched $1 = $3
-$1: 1/1 FAILED
-FAILED 1 out of 1 test in 1 out of 1 group
+check_template([BUILDDIR/t/tvec.t -fh tv], [0],
+[left_pad([matched $1], [17]) = $3
+$1: ok
+PASSED all 1 test in 1 group
])])
dnl test_parserr(TY, IN, LNO, ERR)
m4_define([test_parserr], [
AT_DATA([tv],
[;;; -*-conf-*-
-[[$1]]
+@<:@$1@:>@
$1 = $2
-@status = ?
])
-AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [2], [],
+check_template([BUILDDIR/t/tvec.t -fh tv], [2],
+[tv:$3: $4
+tv:={N:\d+}: required register `$1' not set in test `$1'
+$1: skipped: no tests to run
+PASSED 0 tests in 0 groups (1 skipped)
+ERRORS found in input; tests may not have run correctly
+],
[tvec.t: tv:$3: $4
+tvec.t: tv:={N:\d+}: required register `$1' not set in test `$1'
])])
+###--------------------------------------------------------------------------
AT_SETUP(tvec type-int)
-test_parse([int], [4], [4 ; = 0x04])
-test_parse([int], [ 17; comment], [17 ; = 0x11])
+
+test_parse([int], [4], [4 ; = 0x04 = '\x04'])
+test_parse([int], [ 17; comment], [17 ; = 0x11 = '\x11'])
+
+test_parse([int], [0x234], [564 ; = 0x0234])
+test_parse([int], [033], [27 ; = 0x1b = '\e'])
+
+test_parse([int], [ +192], [192 ; = 0xc0 = '\xc0'])
+test_parse([int], [ -192], [-192 ; = -0xc0])
+
test_parserr([int], [17 : badness], [3],
[syntax error: expected end-of-line but found `:'])
test_parserr([int], [17: badness], [3],
[syntax error: expected end-of-line but found `:'])
-test_parse([int], [0x234], [564 ; = 0x0234])
-test_parse([int], [033], [27 ; = 0x1b])
-test_parse([int], [ +192], [192 ; = 0xc0])
-test_parse([int], [ -192], [-192 ; = -0xc0])
+
test_parserr([int], [xyzzy], [3],
[syntax error: expected signed integer but found `x'])
test_parserr([int], [-splat], [3],
[syntax error: expected signed integer but found `s'])
+
test_parserr([int], [0xq], [3],
[syntax error: expected end-of-line but found `x'])
test_parserr([int], [0x], [3],
[syntax error: expected end-of-line but found `x'])
+
test_parserr([int], [], [3],
- [syntax error: expected signed integer but found <eol>])
+ [syntax error: expected signed integer but found @%:@<eol>])
+
test_parserr([int], [123456], [3],
- [integer 123456 out of range (must be in [[-32768 .. 32767]])])
+ [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
+
AT_CLEANUP
+###--------------------------------------------------------------------------
AT_SETUP(tvec type-uint)
-test_parse([uint], [4], [4 ; = 0x04])
-test_parse([uint], [ 17; comment], [17 ; = 0x11])
+
+test_parse([uint], [4], [4 ; = 0x04 = '\x04'])
+test_parse([uint], [ 17; comment], [17 ; = 0x11 = '\x11'])
+
+test_parse([uint], [0x234], [564 ; = 0x0234])
+test_parse([uint], [033], [27 ; = 0x1b = '\e'])
+
test_parserr([uint], [17 : badness], [3],
[syntax error: expected end-of-line but found `:'])
test_parserr([uint], [17: badness], [3],
[syntax error: expected end-of-line but found `:'])
-test_parse([uint], [0x234], [564 ; = 0x0234])
-test_parse([uint], [033], [27 ; = 0x1b])
+
test_parserr([uint], [ +192], [3],
[syntax error: expected unsigned integer but found `+'])
test_parserr([uint], [ -192], [3],
[syntax error: expected unsigned integer but found `-'])
+
test_parserr([uint], [xyzzy], [3],
[syntax error: expected unsigned integer but found `x'])
+
test_parserr([uint], [0xq], [3],
[syntax error: expected end-of-line but found `x'])
test_parserr([uint], [0x], [3],
[syntax error: expected end-of-line but found `x'])
+
test_parserr([uint], [], [3],
- [syntax error: expected unsigned integer but found <eol>])
+ [syntax error: expected unsigned integer but found @%:@<eol>])
+
test_parserr([uint], [123456], [3],
- [integer 123456 out of range (must be in [[0 .. 65535]])])
+ [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
+
AT_CLEANUP
+###--------------------------------------------------------------------------
+AT_SETUP([tvec type-float])
+
+test_parse([float], [1.234], [1.234])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
AT_SETUP([tvec type-enum])
-test_parse([ienum], [less], [less ; = -1 = -0x01])
-test_parse([ienum], [+1], [greater ; = 1 = 0x01])
-test_parse([ienum], [17], [17 ; = 0x11])
-test_parse([uenum], [banana], [banana ; = 1 = 0x01])
-test_parse([uenum], [clementine], [clementine ; = 2 = 0x02])
-test_parse([uenum], [17], [17 ; = 0x11])
-test_parse([penum], [carol], [carol ; = @%:@<player ...>])
-test_parse([penum], [alice], [alice ; = @%:@<player ...>])
+
+test_parse([ienum], [less], [less ; = -1 = -0x01 = @%:@eof])
+test_parse([ienum], [+1], [greater ; = 1 = 0x01 = '\x01'])
+test_parse([ienum], [17], [17 ; = 0x11 = '\x11'])
+
+test_parse([uenum], [banana], [banana ; = 1 = 0x01 = '\x01'])
+test_parse([uenum], [clementine], [clementine ; = 2 = 0x02 = '\x02'])
+test_parse([uenum], [17], [17 ; = 0x11 = '\x11'])
+
+test_parse([penum], [carol], [carol ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
+test_parse([penum], [alice], [alice ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
test_parse([penum], [@%:@nil], [@%:@nil])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+AT_SETUP([tvec serialize])
+
+AT_DATA([tv],
+[@<:@types@:>@
+
+int = -2
+uint = 7
+float = 6.28
+fltish = 0.1
+char = x
+ienum = greater
+uenum = banana
+fenum = tau
+penum = alice
+flags = red-fg | white-bg | bright
+string = "Hello, world!"
+bytes =
+ 2923be84 e16cd6ae 529049f1 f1bbe9eb
+ b3a6db3c 870c3e99 245e0d1c 06b747de
+ b3124dc8 43bb8ba6 1f035a7d 0938251f
+ 5dd4cbfc 96f5453b 130d890a 1cdbae32
+ 209a50ee 407836fd 124932f6 9e7d49dc
+ ad4f14f2 444066d0 6bc430b7 323ba122
+ f622919d e18b1fda b0ca9902 b9729d49
+ 2c807ec5 99d5e980 b2eac9cc 53bf67d6
+])
+AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore])
+
AT_CLEANUP
###----- That's all, folks --------------------------------------------------