@@ -23,160 +23,106 @@ class PrintCommandTest {
2323
2424 @ Test
2525 void printsAsciiTableDefault (QuarkusMainLauncher launcher ) {
26- LaunchResult result = launcher .launch ("print" , "-f" , TEST_FILE );
27-
28- assertThat (result .exitCode ()).isZero ();
29- String output = result .getOutput ().replace (System .lineSeparator (), "\n " );
30-
31- // For default small file, we know exact ASCII output
32- assertThat (output ).isEqualTo ("""
26+ assertOutput (launcher .launch ("print" , "-f" , TEST_FILE ), """
3327 +----+-------+
3428 | id | value |
3529 +----+-------+
3630 | 1 | 100 |
37- +----+-------+
3831 | 2 | 200 |
39- +----+-------+
4032 | 3 | 300 |
4133 +----+-------+""" );
4234 }
4335
4436 @ Test
45- void noLineSeparatorBetweenRows (QuarkusMainLauncher launcher ) {
46- LaunchResult result = launcher .launch ("print" , "-f" , TEST_FILE , "--no-row-delimiter" );
47-
48- assertThat (result .exitCode ()).isZero ();
49- String output = result .getOutput ().replace (System .lineSeparator (), "\n " );
50-
51- // For default small file, we know exact ASCII output
52- assertThat (output ).isEqualTo ("""
37+ void lineSeparatorBetweenRows (QuarkusMainLauncher launcher ) {
38+ assertOutput (launcher .launch ("print" , "-f" , TEST_FILE , "--row-delimiter" ), """
5339 +----+-------+
5440 | id | value |
5541 +----+-------+
5642 | 1 | 100 |
43+ +----+-------+
5744 | 2 | 200 |
45+ +----+-------+
5846 | 3 | 300 |
5947 +----+-------+""" );
6048 }
6149
6250 @ Test
6351 void tail (QuarkusMainLauncher launcher ) {
64- LaunchResult result = launcher .launch ("print" , "-f" , TEST_FILE , "-n" , "-2" );
65-
66- assertThat (result .exitCode ()).isZero ();
67- String output = result .getOutput ().replace (System .lineSeparator (), "\n " );
68-
69- // For default small file, we know exact ASCII output
70- assertThat (output ).isEqualTo ("""
52+ assertOutput (launcher .launch ("print" , "-f" , TEST_FILE , "-n" , "-2" ), """
7153 +----+-------+
7254 | id | value |
7355 +----+-------+
7456 | 2 | 200 |
75- +----+-------+
7657 | 3 | 300 |
7758 +----+-------+""" );
7859 }
7960
8061 @ Test
8162 void head (QuarkusMainLauncher launcher ) {
82- LaunchResult result = launcher .launch ("print" , "-f" , TEST_FILE , "-n" , "2" );
83-
84- assertThat (result .exitCode ()).isZero ();
85- String output = result .getOutput ().replace (System .lineSeparator (), "\n " );
86-
87- // For default small file, we know exact ASCII output
88- assertThat (output ).isEqualTo ("""
63+ assertOutput (launcher .launch ("print" , "-f" , TEST_FILE , "-n" , "2" ), """
8964 +----+-------+
9065 | id | value |
9166 +----+-------+
9267 | 1 | 100 |
93- +----+-------+
9468 | 2 | 200 |
9569 +----+-------+""" );
9670 }
9771
9872 @ Test
9973 void byteArrayAsString (QuarkusMainLauncher launcher ) {
100- LaunchResult result = launcher .launch ("print" , "-f" , BYTE_ARRAY_FILE );
101-
102- assertThat (result .exitCode ()).isZero ();
103- assertThat (result .getOutput ().replace (System .lineSeparator (), "\n " ))
104- .isEqualTo ("""
105- +----+----------------+-----------------+
106- | id | prefix_strings | varying_strings |
107- +----+----------------+-----------------+
108- | 1 | apple | hello |
109- +----+----------------+-----------------+
110- | 2 | application | world |
111- +----+----------------+-----------------+
112- | 3 | apply | wonderful |
113- +----+----------------+-----------------+
114- | 4 | banana | wonder |
115- +----+----------------+-----------------+
116- | 5 | bandana | wander |
117- +----+----------------+-----------------+
118- | 6 | band | wandering |
119- +----+----------------+-----------------+
120- | 7 | bandwidth | test |
121- +----+----------------+-----------------+
122- | 8 | ban | testing |
123- +----+----------------+-----------------+""" );
74+ assertOutput (launcher .launch ("print" , "-f" , BYTE_ARRAY_FILE ), """
75+ +----+----------------+-----------------+
76+ | id | prefix_strings | varying_strings |
77+ +----+----------------+-----------------+
78+ | 1 | apple | hello |
79+ | 2 | application | world |
80+ | 3 | apply | wonderful |
81+ | 4 | banana | wonder |
82+ | 5 | bandana | wander |
83+ | 6 | band | wandering |
84+ | 7 | bandwidth | test |
85+ | 8 | ban | testing |
86+ +----+----------------+-----------------+""" );
12487 }
12588
12689 @ Test
12790 void showsRowIndexWhenEnabled (QuarkusMainLauncher launcher ) {
128- LaunchResult result = launcher .launch ("print" , "-f" , TEST_FILE , "-ri" );
129-
130- assertThat (result .exitCode ()).isZero ();
131- assertThat (result .getOutput ().replace (System .lineSeparator (), "\n " ))
132- .isEqualTo ("""
133- +----------+----+-------+
134- | rowIndex | id | value |
135- +----------+----+-------+
136- | 0 | 1 | 100 |
137- +----------+----+-------+
138- | 1 | 2 | 200 |
139- +----------+----+-------+
140- | 2 | 3 | 300 |
141- +----------+----+-------+""" );
91+ assertOutput (launcher .launch ("print" , "-f" , TEST_FILE , "-ri" ), """
92+ +----------+----+-------+
93+ | rowIndex | id | value |
94+ +----------+----+-------+
95+ | 0 | 1 | 100 |
96+ | 1 | 2 | 200 |
97+ | 2 | 3 | 300 |
98+ +----------+----+-------+""" );
14299 }
143100
144101 @ Test
145102 void truncatesWhenEnabled (QuarkusMainLauncher launcher ) {
146- LaunchResult result = launcher .launch ("print" , "-f" , BYTE_ARRAY_FILE , "--no-truncate" , "-mw" , "5" );
147-
148- assertThat (result .exitCode ()).isZero ();
149- assertThat (result .getOutput ().replace (System .lineSeparator (), "\n " ))
150- .isEqualTo ("""
151- +----+-------+-------+
152- | id | prefi | varyi |
153- | | x_str | ng_st |
154- | | ings | rings |
155- +----+-------+-------+
156- | 1 | apple | hello |
157- +----+-------+-------+
158- | 2 | appli | world |
159- | | catio | |
160- | | n | |
161- +----+-------+-------+
162- | 3 | apply | wonde |
163- | | | rful |
164- +----+-------+-------+
165- | 4 | banan | wonde |
166- | | a | r |
167- +----+-------+-------+
168- | 5 | banda | wande |
169- | | na | r |
170- +----+-------+-------+
171- | 6 | band | wande |
172- | | | ring |
173- +----+-------+-------+
174- | 7 | bandw | test |
175- | | idth | |
176- +----+-------+-------+
177- | 8 | ban | testi |
178- | | | ng |
179- +----+-------+-------+""" );
103+ assertOutput (launcher .launch ("print" , "-f" , BYTE_ARRAY_FILE , "--no-truncate" , "-mw" , "5" ), """
104+ +----+-------+-------+
105+ | id | prefi | varyi |
106+ | | x_str | ng_st |
107+ | | ings | rings |
108+ +----+-------+-------+
109+ | 1 | apple | hello |
110+ | 2 | appli | world |
111+ | | catio | |
112+ | | n | |
113+ | 3 | apply | wonde |
114+ | | | rful |
115+ | 4 | banan | wonde |
116+ | | a | r |
117+ | 5 | banda | wande |
118+ | | na | r |
119+ | 6 | band | wande |
120+ | | | ring |
121+ | 7 | bandw | test |
122+ | | idth | |
123+ | 8 | ban | testi |
124+ | | | ng |
125+ +----+-------+-------+""" );
180126 }
181127
182128 @ Test
@@ -195,4 +141,10 @@ void rejectsRemoteUri(QuarkusMainLauncher launcher) {
195141 assertThat (result .getErrorOutput ().replace (System .lineSeparator (), "\n " ))
196142 .isEqualTo ("Remote URIs are not implemented yet." );
197143 }
144+
145+ private void assertOutput (LaunchResult result , String expected ) {
146+ assertThat (result .exitCode ()).isZero ();
147+ String output = result .getOutput ().replace (System .lineSeparator (), "\n " );
148+ assertThat (output ).isEqualTo (expected );
149+ }
198150}
0 commit comments