Debian Codegraph @

gcc/testsuite/cobol.dg/group2/FUNCTION_TEST-FORMATTED-DATETIME_additional.cob

raw
1 *> { dg-do run }
2
3 identification division.
4 program-id. test.
5 data division.
6 working-storage section.
7 01 datev pic 99999999.
8 01 should_be pic 9999.
9 01 result pic 9999.
10 01 date-integer PIC 999999.
11 01 i PIC 999.
12 01 datex PIC X(8).
13 01 xone PIC X.
14 01 yyyydddv .
15 02 yyyy PIC 9999.
16 02 filler PIC X VALUE "-".
17 02 ddd PIC 999.
18 procedure division.
19 *> TESTING YYYYMMDD
20 move "19000229" to datex
21 move function TEST-FORMATTED-DATETIME("YYYYMMDD", datex) to RESULT
22 move 8 to should_be
23 if result not equal to should_be then
24 display "TEST-FORMATTED-DATETIME("
25 """YYYYMMDD"""
26 ", "
27 function trim(datex)
28 ") should have been "
29 should_be " but was " result
30 move 1 to return-code
31 end-if.
32 *> Test an entire year of YYYYMMDD:
33 move function integer-of-date(19880101) to date-integer
34 perform until date-integer >= function integer-of-date(19890101)
35 move function date-of-integer(date-integer) to datev
36 move function TEST-FORMATTED-DATETIME("YYYYMMDD", datev) to RESULT
37 move zero to should_be
38 if result not equal to should_be then
39 display "TEST-FORMATTED-DATETIME("
40 """YYYYMMDD"""
41 ", "
42 datev
43 ") should have been "
44 should_be " but was " result
45 move 1 to return-code
46 end-if
47 add 1 to date-integer
48 end-perform.
49 *> Make sure foreign characters trigger the correct gazinga in YYYYMMDD
50 move "19530227" to datex
51 perform varying i from 1 by 1 until i > 8
52 move datex(i:1) to xone
53 move 'X' to datex(i:1)
54 move function TEST-FORMATTED-DATETIME("YYYYMMDD", datex) to RESULT
55 move i to should_be
56 if result not equal to should_be then
57 display "TEST-FORMATTED-DATETIME("
58 """YYYYMMDD"""
59 ", "
60 function trim(datex)
61 ") should have been "
62 should_be " but was " result
63 move 1 to return-code
64 end-if
65 move xone to datex(i:1)
66 end-perform.
67 move "19000229" to datex
68 move function TEST-FORMATTED-DATETIME("YYYYMMDD", datex) to RESULT
69 move 8 to should_be
70 if result not equal to should_be then
71 display "TEST-FORMATTED-DATETIME("
72 """YYYYMMDD"""
73 ", "
74 function trim(datex)
75 ") should have been "
76 should_be " but was " result
77 move 1 to return-code
78 end-if.
79 move "20000229" to datex
80 move function TEST-FORMATTED-DATETIME("YYYYMMDD", datex) to RESULT
81 move 0 to should_be
82 if result not equal to should_be then
83 display "TEST-FORMATTED-DATETIME("
84 """YYYYMMDD"""
85 ", "
86 function trim(datex)
87 ") should have been "
88 should_be " but was " result
89 move 1 to return-code
90 end-if.
91 move "20007029" to datex
92 move function TEST-FORMATTED-DATETIME("YYYYMMDD", datex) to RESULT
93 move 5 to should_be
94 if result not equal to should_be then
95 display "TEST-FORMATTED-DATETIME("
96 """YYYYMMDD"""
97 ", "
98 function trim(datex)
99 ") should have been "
100 should_be " but was " result
101 move 1 to return-code
102 end-if.
103 *> TESTING YYYY-DDD
104 move "1988" to yyyy of yyyydddv
105 move "000" to ddd of yyyydddv
106 move function TEST-FORMATTED-DATETIME("YYYY-DDD", yyyydddv) to RESULT
107 move 8 to should_be
108 if result not equal to should_be then
109 display "TEST-FORMATTED-DATETIME("
110 """YYYYDDD"""
111 ", "
112 function trim(yyyydddv)
113 ") should have been "
114 should_be " but was " result
115 move 1 to return-code
116 end-if.
117 move "1988" to yyyy of yyyydddv
118 move "367" to ddd of yyyydddv
119 move function TEST-FORMATTED-DATETIME("YYYY-DDD", yyyydddv) to RESULT
120 move 8 to should_be
121 if result not equal to should_be then
122 display "TEST-FORMATTED-DATETIME("
123 """YYYYDDD"""
124 ", "
125 function trim(yyyydddv)
126 ") should have been "
127 should_be " but was " result
128 move 1 to return-code
129 end-if.
130 move "1988" to yyyy of yyyydddv
131 move "399" to ddd of yyyydddv
132 move function TEST-FORMATTED-DATETIME("YYYY-DDD", yyyydddv) to RESULT
133 move 7 to should_be
134 if result not equal to should_be then
135 display "TEST-FORMATTED-DATETIME("
136 """YYYYDDD"""
137 ", "
138 function trim(yyyydddv)
139 ") should have been "
140 should_be " but was " result
141 move 1 to return-code
142 end-if.
143 move 1988 to yyyy of yyyydddv
144 move 400 to ddd of yyyydddv
145 move function TEST-FORMATTED-DATETIME("YYYY-DDD", yyyydddv) to RESULT
146 move 6 to should_be
147 if result not equal to should_be then
148 display "TEST-FORMATTED-DATETIME("
149 """YYYYDDD"""
150 ", "
151 function trim(yyyydddv)
152 ") should have been "
153 should_be " but was " result
154 move 1 to return-code
155 end-if.
156 move 1988 to yyyy of yyyydddv
157 perform varying i from 1 by 1 until i > 366
158 move i to ddd of yyyydddv
159 move function TEST-FORMATTED-DATETIME("YYYY-DDD", yyyydddv) to RESULT
160 move zero to should_be
161 if result not equal to should_be then
162 display "TEST-FORMATTED-DATETIME("
163 """YYYY-DDD"""
164 ", "
165 function trim(yyyydddv)
166 ") should have been "
167 should_be " but was " result
168 move 1 to return-code
169 end-if
170 add 1 to date-integer
171 end-perform.
172 end program test.
173