-# Copyright © 2020-2021, 2023 Nick Bowler
+# Copyright © 2020-2021, 2023-2024 Nick Bowler
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
AT_CHECK([cdecl99 -f test.dat], [0], [expout])
AT_CLEANUP])
+dnl SIMPLE_DECLS_SIMPLIFY([arg], [arg ...])
+dnl
+dnl Generate tests to validate the expected operation of the "simplify"
+dnl command. The arguments are a quoted list of quoted items, with the
+dnl first item of each list being the input declaration and the second
+dnl item being the expected simplified output.
+dnl
+dnl The items should be related to each other as the user-visible test
+dnl group name is determined only by the first argument.
+m4_define([SIMPLE_DECLS_SIMPLIFY],
+[AT_SETUP([Simplify "m4_car($1)"m4_ifnblank([$2], [ etc.])])
+AT_DATA([test.dat],
+[m4_map_args([simplify m4_curry([_SIMPLE_DECL_ARG], [1])], $@)])
+AT_DATA([expout],
+[m4_map_args([m4_curry([_SIMPLE_DECL_ARG], [2])], $@)])
+AT_CHECK([cdecl99 -f test.dat], [0], [expout])
+AT_CLEANUP])
+
dnl SIMPLE_DECLS(arg, [arg ...])
m4_define([SIMPLE_DECLS],
[SIMPLE_DECLS_EXPLAIN($@)
[[int @<:@n@:>@], [type variable-length array n of int]],
[[int @<:@*@:>@], [type variable-length array of int]])
+SIMPLE_DECLS(
+ [[int f(a, b)], [declare f as function (a, b) returning int]],
+ [[int f(int, b)], [declare f as function (int, b) returning int]],
+ [[int f(a, int)], [declare f as function (a, int) returning int]],
+ [[int (a, b)], [type function (a, b) returning int]],
+ [[int (int, b)], [type function (int, b) returning int]],
+ [[int (a, int)], [type function (a, int) returning int]])
+
+SIMPLE_DECLS(
+ [[int f(a, b, ...)], [declare f as function (a, b, ...) returning int]],
+ [[int f(int, b, ...)], [declare f as function (int, b, ...) returning int]],
+ [[int f(a, int, ...)], [declare f as function (a, int, ...) returning int]],
+ [[int (a, b, ...)], [type function (a, b, ...) returning int]],
+ [[int (int, b, ...)], [type function (int, b, ...) returning int]],
+ [[int (a, int, ...)], [type function (a, int, ...) returning int]])
+
+SIMPLE_DECLS(
+ [[[int f(int (*)[])]],
+ [declare f as function (pointer to array of int) returning int]],
+ [[[int f(int (*)[][1])]],
+ [declare f as function (pointer to array of array 1 of int) returning int]],
+ [[[int f(int (*)())]],
+ [declare f as function (pointer to function returning int) returning int]],
+ [[[int f(a (*)[])]],
+ [declare f as function (pointer to array of a) returning int]],
+ [[[int f(a (*)[][1])]],
+ [declare f as function (pointer to array of array 1 of a) returning int]],
+ [[[int f(a (*)())]],
+ [declare f as function (pointer to function returning a) returning int]],
+ [[[int (int (*)[])]],
+ [type function (pointer to array of int) returning int]],
+ [[[int (int (*)[][1])]],
+ [type function (pointer to array of array 1 of int) returning int]],
+ [[[int (int (*)())]],
+ [type function (pointer to function returning int) returning int]],
+ [[[int (a (*)[])]],
+ [type function (pointer to array of a) returning int]],
+ [[[int (a (*)[][1])]],
+ [type function (pointer to array of array 1 of a) returning int]],
+ [[[int (a (*)())]],
+ [type function (pointer to function returning a) returning int]])
+
+SIMPLE_DECLS_EXPLAIN(
+ [[[int f(int ([]))]],
+ [declare f as function (array of int) returning int],
+ [[int f(int [])]]],
+ [[[int f(a ([]))]],
+ [declare f as function (array of a) returning int],
+ [[int f(a [])]]],
+ [[[int f(int (()))]],
+ [declare f as function (function returning int) returning int],
+ [[int f(int ())]]],
+ [[[int f(a (()))]],
+ [declare f as function (function returning a) returning int],
+ [[int f(a ())]]],
+ [[[int (int ([]))]],
+ [type function (array of int) returning int],
+ [[int (int [])]]],
+ [[[int (a ([]))]],
+ [type function (array of a) returning int],
+ [[int (a [])]]],
+ [[[int (int (()))]],
+ [type function (function returning int) returning int],
+ [[int (int ())]]],
+ [[[int (a (()))]],
+ [type function (function returning a) returning int],
+ [[int (a ())]]])
+
SIMPLE_DECLS_EXPLAIN(
[[int ((int))], [type function (int) returning int], [int (int)]],
[[int (x(int))], [declare x as function (int) returning int], [int x(int)]],
[declare as as function (function) returning returning]],
[[pointer *declare], [declare declare as pointer to pointer]],
[[type to], [declare to as type]])
+
+dnl Test the explain command with multiple declarators, which produces
+dnl multiple lines of English output.
+SIMPLE_DECLS_EXPLAIN(
+ [[int x, y], [m4_n([declare x as int])declare y as int]])
+
+dnl Test the simplify command with multiple declarators. This is the only
+dnl command in cdecl99 which will print a single C declaration with more than
+dnl one full declarator.
+SIMPLE_DECLS_SIMPLIFY(
+ [[int x, y], [int x, y]],
+ [[int (x), ((y))], [int x, y]])