xref: /freebsd/usr.bin/column/tests/column.sh (revision 313713b24c6d2a3061972c4f431515c4f1b01c77)
1# SPDX-License-Identifier: ISC
2#
3# Copyright (c) 2025 Lexi Winter
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17atf_test_case "basic"
18basic_head()
19{
20	atf_set descr "Basic column(1) with default options"
21}
22
23basic_body()
24{
25	cat >input.1 <<END
26this is the first input file
27it has multiple lines
28END
29
30	cat >input.2 <<END
31here lies the second input file
32some lines
33
34are empty
35END
36
37	cat >input.3 <<END
38third of the input files am i
39and i have
40more
41lines
42than before
43END
44
45	cat >expected <<END
46this is the first input file	are empty			lines
47it has multiple lines		third of the input files am i	than before
48here lies the second input file	and i have
49some lines			more
50END
51
52	atf_check -o save:output column -c120 input.1 input.2 input.3
53	atf_check diff expected output
54}
55
56atf_test_case "rows"
57rows_head()
58{
59	atf_set descr "column(1) with -x (row-wise) option"
60}
61
62rows_body()
63{
64	cat >input.1 <<END
65this is the first input file
66it has multiple lines
67END
68
69	cat >input.2 <<END
70here lies the second input file
71some lines
72
73are empty
74END
75
76	cat >input.3 <<END
77third of the input files am i
78and i have
79more
80lines
81than before
82END
83
84	cat >expected <<END
85this is the first input file	it has multiple lines		here lies the second input file
86some lines			are empty			third of the input files am i
87and i have			more				lines
88than before
89END
90
91	atf_check -o save:output column -xc120 input.1 input.2 input.3
92	atf_check diff expected output
93}
94
95atf_test_case "basic_table"
96basic_table_head()
97{
98	atf_set descr "column(1) with -t (table) option"
99}
100
101basic_table_body()
102{
103	cat >input.1 <<END
1041 2 3 4
105foo bar baz quux
106END
107
108	cat >input.2 <<END
109fie fi fo fum
110END
111
112	cat >input.3 <<END
113where did my
114fields go
115argh
116END
117
118	cat >expected <<END
1191       2    3    4
120foo     bar  baz  quux
121fie     fi   fo   fum
122where   did  my
123fields  go
124argh
125END
126
127	atf_check -o save:output column -tc120 input.1 input.2 input.3
128	atf_check diff expected output
129}
130
131atf_test_case "colonic_table"
132colonic_table_head()
133{
134	atf_set descr "column(1) with -t (table) and -s options"
135}
136
137colonic_table_body()
138{
139	cat >input <<END
140one:two.three
141four.five:six
142seven.:eight.:nine
143:ein
144::zwei
145drei..
146vier:
147:
148
149END
150
151	cat >expected <<END
152one    two    three
153four   five   six
154seven  eight  nine
155ein
156zwei
157drei
158vier
159END
160
161	atf_check -o save:output column -tc120 -s:. input
162	atf_check diff expected output
163}
164
165atf_test_case "ncols"
166ncols_head()
167{
168	atf_set descr "column(1) with -t (table) and -s and -l options"
169}
170
171ncols_body()
172{
173	cat >input <<END
174now we have five columns
175here there are four
176now only three
177just two
178one
179END
180
181	cat >expected <<END
182now   we     have five columns
183here  there  are four
184now   only   three
185just  two
186one
187END
188
189	atf_check -o save:output column -tc120 -l3 input
190	atf_check diff expected output
191}
192
193atf_init_test_cases()
194{
195	atf_add_test_case basic
196	atf_add_test_case rows
197	atf_add_test_case basic_table
198	atf_add_test_case colonic_table
199	atf_add_test_case ncols
200}
201