X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/a0629a04f4fc6093900c9e4703e440d6b0ba24ad..a41aa156f28753613f38924fc856d3dc992cfc56:/tests/decl-good.at diff --git a/tests/decl-good.at b/tests/decl-good.at index e06fb76..bb3c168 100644 --- a/tests/decl-good.at +++ b/tests/decl-good.at @@ -1,4 +1,4 @@ -# 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 @@ -69,6 +69,24 @@ AT_DATA([expout], 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($@) @@ -96,6 +114,28 @@ SIMPLE_DECLS( [[int x@<:@@:>@], [declare x as array of int]], [[int @<:@@:>@], [type array of int]]) +SIMPLE_DECLS( + [[int x@<:@n@:>@], [declare x as variable-length array n of int]], + [[int x@<:@*@:>@], [declare x as variable-length array of int]], + [[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_EXPLAIN( [[int ((int))], [type function (int) returning int], [int (int)]], [[int (x(int))], [declare x as function (int) returning int], [int x(int)]], @@ -112,3 +152,15 @@ SIMPLE_DECLS_EXPLAIN( [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]])