@@@ tvec setvar
[mLib] / test / tests.at
index 30c898a..456729d 100644 (file)
@@ -50,13 +50,13 @@ dnl test_parse(TY, IN, OUT)
 m4_define([test_parse], [
 AT_DATA([tv],
 [;;; -*-conf-*-
-@<:@$1@:>@
+@<:@copy-$1@:>@
 $1 = $2
 @show = t
 ])
 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
-[left_pad([matched $1], [17]) = $3
-$1: ok
+[left_pad([matched $1], [21]) = $3
+copy-$1: ok
 PASSED all 1 test in 1 group
 ])])
 
@@ -64,18 +64,19 @@ dnl test_parserr(TY, IN, LNO, ERR)
 m4_define([test_parserr], [
 AT_DATA([tv],
 [;;; -*-conf-*-
-@<:@$1@:>@
+@<:@copy-$1@:>@
 $1 = $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)
+[tv:$3: ERROR: $4
+tv:={N:\d+}: ERROR: required register `$1' not set in test `copy-$1'
+tv:={N:\d+}: `copy-$1' skipped: erroneous test data
+copy-$1 skipped
+PASSED 0 tests (1 skipped) 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'
+[tvec.t: tv:$3: ERROR: $4
+tvec.t: tv:={N:\d+}: ERROR: required register `$1' not set in test `copy-$1'
 ])])
 
 ###--------------------------------------------------------------------------
@@ -85,31 +86,48 @@ 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], [0o33], [27 ; = 0x1b = @%:@escape = '\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_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>])
-
-test_parserr([int], [123456], [3],
-       [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
+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_parserr([int], [-_1],
+       [3], [invalid signed integer `-_1'])
+test_parserr([int], [+1234_],
+       [3], [syntax error: expected end-of-line but found `_'])
+test_parse([int], [-1234_5], [-12345 ; = -0x3039])
+test_parserr([int], [+0x_abc],
+       [3], [syntax error: expected end-of-line but found `x'])
+test_parse([int], [-0xa_bc], [-2748 ; = -0x0abc])
+test_parserr([int], [-0xab__c],
+       [3], [syntax error: expected end-of-line but found `_'])
+test_parserr([int], [+010r1234],
+       [3], [syntax error: expected end-of-line but found `r'])
+test_parserr([int], [-1_0r1234],
+       [3], [syntax error: expected end-of-line but found `r'])
+
+test_parserr([int], [xyzzy],
+       [3], [invalid signed integer `xyzzy'])
+test_parserr([int], [-splat],
+       [3], [invalid signed integer `-splat'])
+test_parserr([int], [- 1],
+       [3], [invalid signed integer `-'])
+
+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])
+
+test_parserr([int], [123456],
+       [3], [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
 
 AT_CLEANUP
 
@@ -119,40 +137,70 @@ AT_SETUP(tvec type-uint)
 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_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_parse([uint], [0], [0 ; = 0x00 = @%:@nul = '\0'])
 
-test_parserr([uint], [], [3],
-       [syntax error: expected unsigned integer but found @%:@<eol>])
-
-test_parserr([uint], [123456], [3],
-       [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
+test_parse([uint], [012345], [12345 ; = 0x3039])
+test_parse([uint], [0x234], [564 ; = 0x0234])
+test_parse([uint], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
+test_parse([uint], [0b1011_1101], [189 ; = 0xbd = '\xbd'])
+test_parse([uint], [12r123], [171 ; = 0xab = '\xab'])
+
+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_parserr([uint], [_1],
+       [3], [invalid unsigned integer `_1'])
+test_parserr([uint], [1234_],
+       [3], [syntax error: expected end-of-line but found `_'])
+test_parse([uint], [1234_5], [12345 ; = 0x3039])
+test_parserr([uint], [0x_abcd],
+       [3], [syntax error: expected end-of-line but found `x'])
+test_parse([uint], [0xa_bcd], [43981 ; = 0xabcd])
+test_parserr([uint], [0xab__cd],
+       [3], [syntax error: expected end-of-line but found `_'])
+test_parserr([uint], [010r1234],
+       [3], [syntax error: expected end-of-line but found `r'])
+test_parserr([uint], [1_0r1234],
+       [3], [syntax error: expected end-of-line but found `r'])
+
+test_parserr([uint], [ +192],
+       [3], [invalid unsigned integer `+192'])
+test_parserr([uint], [ -192],
+       [3], [invalid unsigned integer `-192'])
+
+test_parserr([uint], [xyzzy],
+       [3], [invalid unsigned integer `xyzzy'])
+
+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])
+
+test_parserr([uint], [123456],
+       [3], [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
 
 AT_CLEANUP
 
 ###--------------------------------------------------------------------------
 AT_SETUP([tvec type-float])
 
+test_parse([float], [0.0], [0])
+test_parse([float], [-0.0], [-0])
+
 test_parse([float], [1.234], [1.234])
 
+test_parse([float], [@%:@nan], [@%:@nan])
+test_parse([float], [@%:@+inf], [@%:@+inf])
+test_parse([float], [@%:@inf], [@%:@+inf])
+test_parse([float], [+@%:@inf], [@%:@+inf])
+test_parse([float], [@%:@-inf], [@%:@-inf])
+test_parse([float], [-@%:@inf], [@%:@-inf])
+
 AT_CLEANUP
 
 ###--------------------------------------------------------------------------
@@ -173,14 +221,244 @@ test_parse([penum], [@%:@nil], [@%:@nil])
 AT_CLEANUP
 
 ###--------------------------------------------------------------------------
+AT_SETUP([tvec type-char])
+
+test_parse([char], [a], ['a' ; = 97 = 0x61])
+test_parse([char], [a;?], ['a' ; = 97 = 0x61])
+test_parse([char], [a ;?], ['a' ; = 97 = 0x61])
+test_parse([char], [\\], ['\\' ; = 92 = 0x5c])
+test_parse([char], ['], ['\'' ; = 39 = 0x27])
+test_parse([char], [\'], ['\'' ; = 39 = 0x27])
+test_parse([char], ["], ['"' ; = 34 = 0x22])
+test_parse([char], [';'], [';' ; = 59 = 0x3b])
+test_parse([char], [';';?], [';' ; = 59 = 0x3b])
+test_parse([char], [';' ;?], [';' ; = 59 = 0x3b])
+test_parse([char], [\"], ['"' ; = 34 = 0x22]) # "
+test_parse([char], [@%:@], ['@%:@' ; = 35 = 0x23])
+test_parse([char], ['@%:@'], ['@%:@' ; = 35 = 0x23])
+
+test_parse([char], [\n], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], [\x0a], [@%:@newline ; = '\n' = 10 = 0x0a])
+
+test_parse([char], [@%:@newline], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], [@%:@lf], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], [@%:@del;?], [@%:@delete ; = '\x7f' = 127 = 0x7f])
+test_parse([char], [@%:@space ;?], [' ' ; = 32 = 0x20])
+
+test_parse([char], [' '], [' ' ; = 32 = 0x20])
+test_parse([char], ['a'], ['a' ; = 97 = 0x61])
+test_parse([char], ['\n'], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], ['\12' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], ['\{12}' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], ['\x0a'], [@%:@newline ; = '\n' = 10 = 0x0a])
+test_parse([char], ['\x{0a}'], [@%:@newline ; = '\n' = 10 = 0x0a])
+
+test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
+test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
+
+test_parserr([char], [ ],
+       [3], [syntax error: expected character but found @%:@eol])
+test_parserr([char], [''],
+       [3], [syntax error: expected character but found `''])
+test_parserr([char], ['''],
+       [3], [syntax error: expected character but found `''])
+test_parserr([char], [;],
+       [3], [syntax error: expected character but found `;'])
+test_parserr([char], [';],
+       [3], [syntax error: expected `'' but found @%:@eol])
+test_parserr([char], [\],
+       [3], [syntax error: expected string escape but found @%:@eol])
+test_parserr([char], [\q],
+       [3], [syntax error: expected string escape but found `q'])
+test_parserr([char], ['\],
+       [3], [syntax error: expected string escape but found @%:@eol])
+test_parserr([char], [ab],
+       [3], [syntax error: expected end-of-line but found `b'])
+test_parserr([char], [\x{0a],
+       [3], [syntax error: expected `}' but found @%:@eol])
+test_parserr([char], [\{012],
+       [3], [syntax error: expected `}' but found @%:@eol])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+AT_SETUP([tvec type-text])
+
+test_parse([text], [foo], [foo])
+test_parse([text], [foo bar], ["foo bar"])
+test_parse([text], [foo  bar], ["foo  bar"])
+test_parse([text], [foo  ""  bar], [foobar])
+test_parse([text], [ foo  bar ], ["foo  bar"])
+test_parse([text], [ foo @&t@
+       bar ], ["foo  bar"])
+
+test_parse([text], [foo @%:@nul bar], ["foo\{0}bar"])
+
+test_parse([text], ["f" !repeat 2 { o } "bar"], [foobar])
+test_parse([text], ["{"!repeat 5{"abc"}"}"], ["{abcabcabcabcabc}"])
+
+test_parse([text], [!hex "f" 6f "o"], [foo])
+
+test_parse([text], ["foo\n"], ["foo\n"])
+
+test_parse([text], [foo\
+bar], [
+       "foo\n"
+       "bar"])
+test_parse([text], ["foo\
+bar"], [foobar])
+test_parse([text], ["foo" @%:@newline "bar" @%:@newline], [
+       "foo\n"
+       "bar\n"])
+
+test_parserr([text], [],
+       [4], [syntax error: expected string but found @%:@eof])
+test_parse([text], [""], [""])
+test_parse([text], [''], [""])
+
+test_parse([text], ["f\x{6f}o"], [foo])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+AT_SETUP([tvec type-bytes])
+
+test_parse([bytes], [""], ["" ; empty])
+test_parse([bytes], [61], [61 ; a])
+test_parse([bytes], ["abc"], [616263 ; abc])
+test_parse([bytes], ["abcd"], [61626364 ; abcd])
+test_parse([bytes], ["abcde"], [61626364 65 ; abcde])
+
+test_parse([bytes], [!base64 YWJjZGVmZ2hpamtsbW5vcA==],
+       [61626364 65666768 696a6b6c 6d6e6f70 ; abcdefghijklmnop])
+test_parse([bytes],
+       [!base64 QUJDREVGR0hJSktMTU5PUGFiY2RlZmdo
+                a Wp rbG 1ub3A=],
+       [
+       41424344 45464748 494a4b4c 4d4e4f50 ; @<:@00@:>@ ABCDEFGHIJKLMNOP
+       61626364 65666768 696a6b6c 6d6e6f70 ; @<:@10@:>@ abcdefghijklmnop])
+
+test_parse([bytes], [6 1], [61 ; a])
+test_parserr([bytes], [6 "" 1],
+       [3], [invalid hex sequence end: Excess or nonzero padding bits])
+
+test_parse([bytes], [!base64 AA==], [00 ; .])
+test_parse([bytes], [!base64 AAA=], [0000 ; ..])
+test_parse([bytes], [!base64 AAAA], [000000 ; ...])
+test_parse([bytes], [!base64 AA], [00 ; .])
+test_parse([bytes], [!base64 AAA], [0000 ; ..])
+
+test_parserr([text], [],
+       [4], [syntax error: expected string but found @%:@eof])
+test_parserr([bytes], [0],
+       [4], [invalid hex sequence end: Excess or nonzero padding bits])
+test_parserr([bytes], [!base64 A],
+       [4], [invalid base64 sequence end: Excess or nonzero padding bits])
+test_parserr([bytes], [!base64 A=],
+       [3], [invalid base64 fragment `A=': Excess or nonzero padding bits])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+AT_SETUP([tvec type-buffer])
+
+test_parse([buffer], [16], [16 B])
+test_parse([buffer], [16;?], [16 B])
+test_parse([buffer], [16 ;?], [16 B])
+test_parse([buffer], [16384], [16 kB])
+test_parse([buffer], [16777216], [16 MB])
+test_parse([buffer], [16k], [16 kB])
+test_parse([buffer], [16k;?], [16 kB])
+test_parse([buffer], [16k ;?], [16 kB])
+test_parse([buffer], [16 k], [16 kB])
+test_parse([buffer], [16 k;?], [16 kB])
+test_parse([buffer], [16 k ;?], [16 kB])
+test_parse([buffer], [16kB], [16 kB])
+test_parse([buffer], [16kB;?], [16 kB])
+test_parse([buffer], [16kB ;?], [16 kB])
+test_parse([buffer], [16 kB], [16 kB])
+test_parse([buffer], [16 kB;?], [16 kB])
+test_parse([buffer], [16 kB ;?], [16 kB])
+
+test_parserr([buffer], [16!], [3], [invalid buffer length `16!'])
+test_parserr([buffer], [16   !], [3], [invalid buffer length `16 !'])
+test_parserr([buffer], [16 k!], [3], [invalid buffer length `16 k!'])
+test_parserr([buffer], [16 kB!], [3], [invalid buffer length `16 kB!'])
+test_parserr([buffer], [16 kB !],
+       [3], [syntax error: expected end-of-line but found `!'])
+test_parserr([buffer], [16 EB], [3], [buffer length `16 EB' out of range])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+AT_SETUP([tvec remote])
+
+AT_DATA([tv],
+[;;; -*-conf-*-
+
+@<:@crash@:>@
+
+crash = t
+x = 1
+z = 0
+@progress = %RUN
+@exit = killed | SIGABRT
+
+crash = nil
+x = 0
+z = 0
+@reconnect = skip
+
+crash = nil
+x = 1
+z = 1
+
+crash = nil
+x = 1
+z = 1
+@progress = %DONE
+@exit = running
+])
+check_template([BUILDDIR/t/tvec.t -fh tv], [0],
+[tv:11: `crash' skipped: no connection
+crash: ok (1 skipped)
+PASSED ={N:\d+} tests (1 skipped) in 1 group
+])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+AT_SETUP([tvec timeout])
+
+AT_DATA([tv],
+[;;; -*-conf-*-
+
+@<:@sleep@:>@
+
+time = 0.5
+z = 0
+@progress = %RUN
+@exit = killed | SIGALRM
+
+time = 0.125
+z = 1
+])
+check_template([BUILDDIR/t/tvec.t -fh tv], [0],
+[sleep: ok
+PASSED all ={N:\d+} tests in 1 group
+])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
 AT_SETUP([tvec serialize])
 
 AT_DATA([tv],
-[@<:@types@:>@
+[@<:@multi@:>@
 
 int = -2
 uint = 7
-float = 6.28
+float = @%:@nan
 fltish = 0.1
 char = x
 ienum = greater
@@ -188,7 +466,7 @@ uenum = banana
 fenum = tau
 penum = alice
 flags = red-fg | white-bg | bright
-string = "Hello, world!"
+text = "Hello, world!"
 bytes =
        2923be84 e16cd6ae 529049f1 f1bbe9eb
        b3a6db3c 870c3e99 245e0d1c 06b747de
@@ -198,6 +476,7 @@ bytes =
        ad4f14f2 444066d0 6bc430b7 323ba122
        f622919d e18b1fda b0ca9902 b9729d49
        2c807ec5 99d5e980 b2eac9cc 53bf67d6
+@show = t
 ])
 AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore])