File: recset.sh

package info (click to toggle)
recutils 1.7-1.1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 12,276 kB
  • ctags: 7,034
  • sloc: ansic: 64,860; sh: 18,180; lisp: 1,840; yacc: 1,381; makefile: 331; lex: 241; sed: 16
file content (491 lines) | stat: -rwxr-xr-x 8,366 bytes parent folder | download | duplicates (3)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#!/bin/sh
#
# recset.sh - System tests for recset.
#
# Copyright (C) 2010, 2012 Jose E. Marchesi.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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/>.

#
# Initialization
#

: ${srcdir=.}
. $srcdir/testutils.sh
test_init "recset"

#
# Create input files.
#

test_declare_input_file one-record \
'field1: value1
field2: value2
field3: value3
'

test_declare_input_file repeated-fields \
'field1: value1
field2: value21
field2: value22
field3: value3
'

test_declare_input_file integrity \
'%rec: Integrity
%key: Id

Id: 10
other: field
'

test_declare_input_file renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
field2: field121
field2: field122
field2: field123
field3: field13
'

test_declare_input_file renames-multiple \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
field2: field121
field2: field122
field2: field123
field3: field13

field1: field21
field2: field221
field2: field222
field2: field223
field3: field23
'

test_declare_input_file multiple-records \
'field1: value11
field2: value12
field3: value13

field1: value21
field2: value22
field3: value23

field1: value31
field2: value32
field3: value33
'

#
# Declare tests.
#

test_tool recset-append-field ok \
          recset \
          '-n 0 -f foo -a bar' \
          one-record \
'field1: value1
field2: value2
field3: value3
foo: bar
'

test_tool recset-set-field ok \
          recset \
          '-n 0 -f field2 -s bar' \
          one-record \
'field1: value1
field2: bar
field3: value3
'

test_tool recset-delete-field ok \
          recset \
          '-n 0 -f field2 -d' \
          one-record \
'field1: value1
field3: value3
'

test_tool recset-comment-out-field ok \
          recset \
          '-n 0 -f field2 -c' \
          one-record \
'field1: value1
#field2: value2
field3: value3
'

test_tool recset-delete-non-existant ok \
          recset \
          '-n 0 -f nonexistant -d' \
          one-record \
'field1: value1
field2: value2
field3: value3
'

test_tool recset-comment-out-fex-first ok \
          recset \
          '-n 0 -f field2[0] -c' \
          repeated-fields \
'field1: value1
#field2: value21
field2: value22
field3: value3
'

test_tool recset-comment-out-fex-last ok \
          recset \
          '-n 0 -f field2[1] -c' \
          repeated-fields \
'field1: value1
field2: value21
#field2: value22
field3: value3
'

test_tool recset-violate-integrity xfail \
          recset \
          '-n 0 -f Id -d' \
          integrity

test_tool recset-force-integrity ok \
          recset \
          '--force -n 0 -f Id -d' \
          integrity \
'%rec: Integrity
%key: Id

other: field
'

test_tool recset-rename ok \
          recset \
          '--force -t Type1 -n 0 -f field2 -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
foo: field121
foo: field122
foo: field123
field3: field13
'

test_tool recset-rename-first ok \
          recset \
          '--force -t Type1 -n 0 -f field2[0] -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
foo: field121
field2: field122
field2: field123
field3: field13
'

test_tool recset-rename-middle ok \
          recset \
          '--force -t Type1 -n 0 -f field2[1] -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
field2: field121
foo: field122
field2: field123
field3: field13
'

test_tool recset-rename-last ok \
          recset \
          '--force -t Type1 -n 0 -f field2[2] -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
field2: field121
field2: field122
foo: field123
field3: field13
'

test_tool recset-rename-range-first ok \
          recset \
          '--force -t Type1 -n 0 -f field2[0-1] -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
foo: field121
foo: field122
field2: field123
field3: field13
'

test_tool recset-rename-range-last ok \
          recset \
          '--force -t Type1 -n 0 -f field2[1-2] -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
field2: field121
foo: field122
foo: field123
field3: field13
'

test_tool recset-rename-range-all ok \
          recset \
          '--force -t Type1 -n 0 -f field2[0-2] -r foo' \
          renames \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
foo: field121
foo: field122
foo: field123
field3: field13
'

test_tool recset-rename-all ok \
          recset \
          '--force -t Type1 -e "1" -f field2[0-2] -r foo' \
          renames-multiple \
'%rec: Type1
%key: field1
%type: field2 line
%mandatory: field2
%sort: field2

field1: field11
foo: field121
foo: field122
foo: field123
field3: field13

field1: field21
foo: field221
foo: field222
foo: field223
field3: field23
'

test_tool recset-rename-all-descriptor ok \
          recset \
          '--force -t Type1 -f field2[0-2] -r foo' \
          renames-multiple \
'%rec: Type1
%key: field1
%type: foo line
%mandatory: foo
%sort: foo

field1: field11
foo: field121
foo: field122
foo: field123
field3: field13

field1: field21
foo: field221
foo: field222
foo: field223
field3: field23
'

test_tool recset-rename-all-key ok \
          recset \
          '--force -t Type1 -f field1 -r newkey' \
          renames-multiple \
'%rec: Type1
%key: newkey
%type: field2 line
%mandatory: field2
%sort: field2

newkey: field11
field2: field121
field2: field122
field2: field123
field3: field13

newkey: field21
field2: field221
field2: field222
field2: field223
field3: field23
'

test_tool recset-rename-invalid-fex xfail \
          recset \
          '--force -t Type1 -f field1,field2 -r foo' \
          renames-multiple

test_tool recset-set-add-1 ok \
          recset \
          '-f field2 -S foo' \
          one-record \
'field1: value1
field2: foo
field3: value3
'

test_tool recset-set-add-2 ok \
          recset \
          '-f field4 -S foo' \
          one-record \
'field1: value1
field2: value2
field3: value3
field4: foo
'

test_tool recset-set-add-3 ok \
          recset \
          '-f field2,field4 -S foo' \
          one-record \
'field1: value1
field2: foo
field3: value3
field4: foo
'

test_tool recset-quick-simple ok \
          recset \
          '-q value22 -f field1 -s foo' \
          multiple-records \
'field1: value11
field2: value12
field3: value13

field1: foo
field2: value22
field3: value23

field1: value31
field2: value32
field3: value33
'

test_tool recset-set-field-in-range ok \
          recset \
          '-n 0-1 -f field2 -s XXX' \
          multiple-records \
'field1: value11
field2: XXX
field3: value13

field1: value21
field2: XXX
field3: value23

field1: value31
field2: value32
field3: value33
'

test_tool recset-set-field-in-several-indexes ok \
          recset \
          '-n 0,2 -f field2 -s XXX' \
          multiple-records \
'field1: value11
field2: XXX
field3: value13

field1: value21
field2: value22
field3: value23

field1: value31
field2: XXX
field3: value33
'

test_tool recset-random-all ok \
          recset \
          '-m 0 -f field2 -s XXX' \
          multiple-records \
'field1: value11
field2: XXX
field3: value13

field1: value21
field2: XXX
field3: value23

field1: value31
field2: XXX
field3: value33
'

test_tool recset-random-one ok \
          recset \
          '-m 1 -f field2 -s XXX' \
          one-record \
'field1: value1
field2: XXX
field3: value3
'
 
#
# Cleanup.
#

test_cleanup
exit $?

# End of recset.sh