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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
## Copyright (C) 2003-2012, 2014, 2020, 2023 Free Software Foundation, Inc.
## Written by Keisuke Nishida, Roger While, Simon Sobisch, Edward Hart
##
## This file is part of GnuCOBOL.
##
## The GnuCOBOL compiler 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.
##
## GnuCOBOL 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 GnuCOBOL. If not, see <https://www.gnu.org/licenses/>.
### GnuCOBOL Test Suite
### ISO+IEC+1989-2002 8.4.1.2 Subscripts## 8.4.1.2.3 General rules
AT_SETUP([Non-numeric subscript])
AT_KEYWORDS([subscripts])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 G1.
02 X PIC X OCCURS 10.
01 I PIC X.
PROCEDURE DIVISION.
DISPLAY X(I)
END-DISPLAY.
DISPLAY X(I + 1)
END-DISPLAY.
STOP RUN.
])
AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:10: error: 'I' is not an integer
prog.cob:12: error: 'I' is not numeric
])
AT_CLEANUP
AT_SETUP([Subscript range check])
AT_KEYWORDS([subscripts])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 G1.
02 X OCCURS 2.
03 Y PIC X OCCURS 3.
PROCEDURE DIVISION.
DISPLAY X(0)
END-DISPLAY.
DISPLAY X(1)
END-DISPLAY.
DISPLAY X(2)
END-DISPLAY.
DISPLAY X(3)
END-DISPLAY.
DISPLAY Y(1, 0)
END-DISPLAY.
DISPLAY Y(1, 1)
END-DISPLAY.
DISPLAY Y(1, 3)
END-DISPLAY.
DISPLAY Y(1, 4)
END-DISPLAY.
STOP RUN.
])
AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:10: error: subscript of 'X' out of bounds: 0
prog.cob:16: error: subscript of 'X' out of bounds: 3
prog.cob:18: error: subscript of 'Y' out of bounds: 0
prog.cob:24: error: subscript of 'Y' out of bounds: 4
])
AT_CHECK([$COMPILE_ONLY -frelax-syntax-checks prog.cob], [0], [],
[prog.cob:10: warning: subscript of 'X' out of bounds: 0
prog.cob:16: warning: subscript of 'X' out of bounds: 3
prog.cob:18: warning: subscript of 'Y' out of bounds: 0
prog.cob:24: warning: subscript of 'Y' out of bounds: 4
])
AT_CLEANUP
AT_SETUP([Subscript bounds with OCCURS DEPENDING ON])
AT_KEYWORDS([runsubscripts subscripts odo])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 G.
02 X PIC X OCCURS 4 TO 6 DEPENDING ON N.
01 N PIC 9 VALUE 4.
PROCEDURE DIVISION.
DISPLAY X(0)
DISPLAY X(7)
STOP RUN.
])
AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:10: error: subscript of 'X' out of bounds: 0
prog.cob:11: error: subscript of 'X' out of bounds: 7
])
AT_CLEANUP
## 8.4.1.2.2 Syntax rules
AT_SETUP([Subscripted item requires OCCURS clause])
AT_KEYWORDS([subscripts])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 G.
02 X PIC X.
PROCEDURE DIVISION.
DISPLAY G(1)
END-DISPLAY.
DISPLAY X(1)
END-DISPLAY.
STOP RUN.
])
AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:9: error: 'G' cannot be subscripted
prog.cob:11: error: 'X' cannot be subscripted
])
AT_CLEANUP
AT_SETUP([Number of subscripts])
AT_KEYWORDS([subscripts])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 G1.
02 X OCCURS 2.
03 Y PIC X OCCURS 3.
PROCEDURE DIVISION.
DISPLAY X
END-DISPLAY.
DISPLAY X(1)
END-DISPLAY.
DISPLAY X(1, 2)
END-DISPLAY.
DISPLAY Y(1)
END-DISPLAY.
DISPLAY Y(1, 2)
END-DISPLAY.
DISPLAY Y(1, 2, 3)
END-DISPLAY.
STOP RUN.
])
AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:10: error: 'X' requires one subscript
prog.cob:14: error: 'X' requires one subscript
prog.cob:16: error: 'Y' requires 2 subscripts
prog.cob:20: error: 'Y' requires 2 subscripts
])
AT_CHECK([$COMPILE_ONLY -frelax-syntax-checks prog.cob], [1], [],
[prog.cob:10: warning: subscript missing for 'X' - defaulting to 1
prog.cob:14: error: 'X' requires one subscript
prog.cob:16: warning: subscript missing for 'Y' - defaulting to 1
prog.cob:20: error: 'Y' requires 2 subscripts
])
AT_CLEANUP
AT_SETUP([SET SSRANGE syntax])
AT_KEYWORDS([subscripts directive extensions])
AT_DATA([prog.cob], [
*> Valid
$SET SSRANGE
$SET SSRANGE(1)
$SET SSRANGE "2"
$SET SSRANGE (3)
*> Invalid
$SET SSRANGE(0)
$SET SSRANGE(4)
$SET SSRANGE "variable"
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
PROCEDURE DIVISION.
GOBACK
.
])
AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:9: error: invalid SSRANGE directive option '0'
prog.cob:10: error: invalid SSRANGE directive option '4'
prog.cob:11: error: invalid SSRANGE directive option 'variable'
])
AT_CLEANUP
|