summaryrefslogtreecommitdiff
path: root/agen5/test/define.test
blob: 68008e493d712a4f6544039bfc32e93b3a8c4522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#! /bin/sh
#  -*- Mode: Shell-script -*-
# define.test --- test evalstack functionality
#
# Time-stamp:        "2012-04-07 09:40:07 bkorb"
# Author:            Bruce Korb <bkorb@gnu.org>
##
## This file is part of AutoGen.
## AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
## AutoGen is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
## Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## AutoGen is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program.  If not, see <http://www.gnu.org/licenses/>.
##
#
# ----------------------------------------------------------------------

. ./defs

# # # # # # # TEMPLATE LIBRARY FILE # # # # # #

echo creating $testname.tlib
cat > $testname.tlib <<'_EOF_'
[+ AutoGen5 Template Library +]
[+

# * * * * * * * * * * * *

      VISUAL SEPARATION
+][+

DEFINE first_macro
+][+(for-index)+] Argument list:
	[+
  FOR arg "\n\t"
    +]arg[ [+(for-index)+] ] = [+ arg +][+
  ENDFOR +][+
ENDDEF +][+

# * * * * * * * * * * * *

      VISUAL SEPARATION
+][+

DEFINE last_macro
  +]This is the last (number [+(for-index)+]) macro.[+
ENDDEF +]
_EOF_


# # # # # # # # # # TEMPLATE FILE # # # # # # # # #

echo creating $testname.tpl
cat > $testname.tpl <<'_EOF_'
[= AutoGen5 Template test =]
[=

DEFINE nest     =][=
  IF (exist? "name") =]
level [=level=] iteration [=(for-index)=] Nested Name:  [=name=][=
  ENDIF         =][=

  FOR .nesting  =][=
    nest        =][=
  ENDFOR        =][=

ENDDEF nest     =][=

FOR value

=][=
  IF (or (first-for?) (last-for?)) =][=
    INVOKE (string-append (get "value") "_macro")
       arg = one  arg = "the second arg = the second"
       arg = (shell "date +'%A, %D'") arg = 'done.' =][=
  ELSE =]

     non first/last value: [=value=] = [= (for-index) =]
[=ENDIF         =][=
ENDFOR          =]
[=invoke nest   =]
Done.
_EOF_


# # # # # # # # # # DEFINITIONS FILE # # # # # # # # #

echo creating $testname.def
cat > $testname.def <<_EOF_
autogen definitions $testname;

value = first;
value[2] = secondary;
value[4] = tertiary;
value[6] = last;

level = 0;
nesting[1] = {
  level = 1;
  name = primary;
  nesting[1] = {
    level = 2;
    name = secondary;
  }, {
    level = 2;
    /* no name defined - default to primary level */
    nesting[1] = {
      level = 3;
      name = tertiary;
    };
  };
};
_EOF_

# this is the output we should expect to see
cat > $testname.samp <<_EOF_
0 Argument list:
	arg[ 0 ] = one
	arg[ 1 ] = the second arg = the second
	arg[ 2 ] = `date +'%A, %D'`
	arg[ 3 ] = done.

     non first/last value: secondary = 2


     non first/last value: tertiary = 4
This is the last (number 6) macro.

level 1 iteration 1 Nested Name:  primary
level 2 iteration 1 Nested Name:  secondary
level 2 iteration 2 Nested Name:  primary
level 3 iteration 1 Nested Name:  tertiary
Done.
_EOF_

run_ag x --lib=$testname.tlib $testname.def || \
  failure "autogen failed"
set -x
cmp -s $testname.samp $testname.test || \
  failure "`diff $testname.samp $testname.test`"

cleanup

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## sh-basic-offset: 2
## End:

# end of define.test