File: rec2csv.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 (246 lines) | stat: -rwxr-xr-x 3,360 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
#
# rec2csv.sh - System tests for rec2csv.
#
# Copyright (C) 2011 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 "rec2csv"

#
# Create input files.
#

test_declare_input_file default-records \
'a: a1
b: b1
c: c1

a: a2
b: b2
c: c2
'

test_declare_input_file missing-fields \
'a: a1
b: b1
c: c1

a: a2
c: c2

b: b3
c: c3

a: a4
b: b4
'

test_declare_input_file missing-fields-first \
'a: a1
c: c1

a: a2
b: b2
c: c2
'

test_declare_input_file multi-line \
'a: foo
+ bar
+ baz
b: jo
+ ju
+ je
'

test_declare_input_file escape-quotes \
'a: foo"bar
b: bar"baz
'

test_declare_input_file repeated-fields \
'a: a11
a: a12

a: a21
a: a22
'

test_declare_input_file repeated-missing \
'a: a11
a: a12

b: b2
a: a21
'

test_declare_input_file several-types \
'a: a_none
b: b_none

%rec: foo

a: a_foo
b: b_foo

%rec: bar

a: a_bar
b: b_bar
'

test_declare_input_file sort \
'%rec: Sorted
%sort: foo
%type: bar int

foo: b
bar: 100

foo: a
bar: 50

foo: c
bar: 0
'

#
# Declare tests.
#

test_tool rec2csv-default-record ok \
          rec2csv \
          '' \
          default-records \
'"a","b","c"
"a1","b1","c1"
"a2","b2","c2"
'

test_tool rec2csv-missing-fields ok \
          rec2csv \
          '' \
          missing-fields \
'"a","b","c"
"a1","b1","c1"
"a2",,"c2"
,"b3","c3"
"a4","b4",
'

test_tool rec2csv-missing-fields-first ok \
          rec2csv \
          '' \
          missing-fields-first \
'"a","c","b"
"a1","c1",
"a2","c2","b2"
'

test_tool rec2csv-multi-line ok \
          rec2csv \
          '' \
          multi-line \
'"a","b"
"foo
bar
baz","jo
ju
je"
'

test_tool rec2csv-escape-quotes ok \
          rec2csv \
          '' \
          escape-quotes \
'"a","b"
"foo""bar","bar""baz"
'

test_tool rec2csv-repeated-fields ok \
          rec2csv \
          '' \
          repeated-fields \
'"a","a_2"
"a11","a12"
"a21","a22"
'

test_tool rec2csv-repeated-missing ok \
          rec2csv \
          '' \
          repeated-missing \
'"a","a_2","b"
"a11","a12",
"a21",,"b2"
'

test_tool rec2csv-default-type ok \
          rec2csv \
          '' \
          several-types \
'"a","b"
"a_none","b_none"
'

test_tool rec2csv-with-type ok \
          rec2csv \
          '-t bar' \
          several-types \
'"a","b"
"a_bar","b_bar"
'

test_tool rec2csv-nonexistant-type ok \
          rec2csv \
          '-t jorl' \
          several-types \
''

test_tool rec2csv-sort ok \
          rec2csv \
          '' \
          sort \
'"foo","bar"
"a","50"
"b","100"
"c","0"
'

test_tool rec2csv-sort-field ok \
          rec2csv \
          '-S bar' \
          sort \
'"foo","bar"
"c","0"
"a","50"
"b","100"
'

#
# Cleanup
#

test_cleanup
exit $?

# End of rec2csv.sh