diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-04-25 07:46:37 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-04-25 07:46:37 -0700 |
commit | 07ed770a33acef21ea523f4ac5ac2e8f3b510b4f (patch) | |
tree | 131b059bf1731c6a850b1e1d4c8ba56070140cc0 /testcases-array | |
parent | 7253942c532942d8789d45451e5aa6998c30cb32 (diff) | |
download | cppawk-07ed770a33acef21ea523f4ac5ac2e8f3b510b4f.tar.gz cppawk-07ed770a33acef21ea523f4ac5ac2e8f3b510b4f.tar.bz2 cppawk-07ed770a33acef21ea523f4ac5ac2e8f3b510b4f.zip |
New header: <array.h>
Diffstat (limited to 'testcases-array')
-rw-r--r-- | testcases-array | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/testcases-array b/testcases-array new file mode 100644 index 0000000..1d28c50 --- /dev/null +++ b/testcases-array @@ -0,0 +1,108 @@ +1: +$cppawk ' +#include <array.h> + +BEGIN { + $0 = "1 2 3 4" + fields_to_array(a) + + for (i in a) + count++ + + print "count =", count + + for (i = 1; i <= 4; i++) + printf "a[%s] = %s\n", i, a[i] + + print "a[0] =", a[0] +}' +: +count = 5 +a[1] = 1 +a[2] = 2 +a[3] = 3 +a[4] = 4 +a[0] = 1 2 3 4 +-- +2: +$cppawk ' +#include <array.h> + +BEGIN { + fields_to_array(a) + + count = 0 + for (i in a) + count++ + + print "count =", count + print "a[0] =", a[0] +}' +: +count = 1 +a[0] = +-- +3: +$cppawk ' +#include <array.h> +BEGIN { + x = fun(cos) +} +: +ERR +-- +4: +$cppawk ' +#include <array.h> + +BEGIN { + a[0] = "foo" + for (i = 1; i <= 10; i++) + a[i] = i + delete a[7] + array_to_fields(a) + print +}' +: +1 2 3 4 5 6 +-- +5: +$cppawk ' +#include <array.h> +#include <cons.h> +#include <fun.h> + +function even(x) +{ + return x % 2 == 0 +} + +BEGIN { + group_by(fun(even), iota(1, 10), a) + print sexp(a[0]); + print sexp(a[1]); +}' +: +(1 3 5 7 9) +(2 4 6 8 10) +-- +6: +$cppawk ' +#include <array.h> +#include <cons.h> +#include <fun.h> + +function even(x) +{ + return x % 2 == 0 +} + +BEGIN { + group_by(fun(even), iota(1, 10), a) + maparray(fun(reverse), a, b) + print sexp(b[0]) + print sexp(b[1]) +}' +: +(9 7 5 3 1) +(10 8 6 4 2) |