@@ -131,8 +131,10 @@ pub fn read_and_cut_lines<A: BufRead, B: Write>(
131
131
132
132
#[ cfg( test) ]
133
133
mod tests {
134
+ use std:: str:: FromStr ;
135
+
134
136
use crate :: {
135
- bounds:: { BoundsType , UserBounds , UserBoundsList } ,
137
+ bounds:: { BoundsType , UserBoundsList } ,
136
138
options:: EOL ,
137
139
} ;
138
140
@@ -147,29 +149,10 @@ mod tests {
147
149
}
148
150
}
149
151
150
- fn bof_f1 ( ) -> BoundOrFiller {
151
- BoundOrFiller :: Bound ( UserBounds :: new ( Side :: Some ( 1 ) , Side :: Some ( 1 ) ) )
152
- }
153
-
154
- fn bof_f2 ( ) -> BoundOrFiller {
155
- BoundOrFiller :: Bound ( UserBounds :: new ( Side :: Some ( 2 ) , Side :: Some ( 2 ) ) )
156
- }
157
- fn bof_f3 ( ) -> BoundOrFiller {
158
- BoundOrFiller :: Bound ( UserBounds :: new ( Side :: Some ( 3 ) , Side :: Some ( 3 ) ) )
159
- }
160
- fn bof_r2_3 ( ) -> BoundOrFiller {
161
- BoundOrFiller :: Bound ( UserBounds :: new ( Side :: Some ( 2 ) , Side :: Some ( 3 ) ) )
162
- }
163
- fn bof_neg1 ( ) -> BoundOrFiller {
164
- BoundOrFiller :: Bound ( UserBounds :: new ( Side :: Some ( -1 ) , Side :: Some ( -1 ) ) )
165
- }
166
- fn bof_f1_to_end ( ) -> BoundOrFiller {
167
- BoundOrFiller :: Bound ( UserBounds :: new ( Side :: Some ( 1 ) , Side :: Continue ) )
168
- }
169
152
#[ test]
170
153
fn fwd_cut_one_field ( ) {
171
154
let mut opt = make_lines_opt ( ) ;
172
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1 ( ) ] ) ;
155
+ opt. bounds = UserBoundsList :: from_str ( "1" ) . unwrap ( ) ;
173
156
174
157
let mut input = b"a\n b" . as_slice ( ) ;
175
158
let mut output = Vec :: with_capacity ( 100 ) ;
@@ -180,7 +163,7 @@ mod tests {
180
163
#[ test]
181
164
fn fwd_cut_multiple_fields ( ) {
182
165
let mut opt = make_lines_opt ( ) ;
183
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1 ( ) , bof_f2 ( ) ] ) ;
166
+ opt. bounds = UserBoundsList :: from_str ( "1:2" ) . unwrap ( ) ;
184
167
185
168
let mut input = b"a\n b" . as_slice ( ) ;
186
169
let mut output = Vec :: with_capacity ( 100 ) ;
@@ -191,7 +174,7 @@ mod tests {
191
174
#[ test]
192
175
fn fwd_support_ranges ( ) {
193
176
let mut opt = make_lines_opt ( ) ;
194
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1 ( ) , bof_r2_3 ( ) ] ) ;
177
+ opt. bounds = UserBoundsList :: from_str ( "1,2:3" ) . unwrap ( ) ;
195
178
196
179
let mut input = b"a\n b\n c" . as_slice ( ) ;
197
180
let mut output = Vec :: with_capacity ( 100 ) ;
@@ -202,7 +185,7 @@ mod tests {
202
185
#[ test]
203
186
fn fwd_supports_no_join ( ) {
204
187
let mut opt = make_lines_opt ( ) ;
205
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1 ( ) , bof_f3 ( ) ] ) ;
188
+ opt. bounds = UserBoundsList :: from_str ( "1,3" ) . unwrap ( ) ;
206
189
opt. join = false ;
207
190
208
191
let mut input = b"a\n b\n c" . as_slice ( ) ;
@@ -214,7 +197,7 @@ mod tests {
214
197
#[ test]
215
198
fn fwd_supports_no_right_bound ( ) {
216
199
let mut opt = make_lines_opt ( ) ;
217
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1_to_end ( ) ] ) ;
200
+ opt. bounds = UserBoundsList :: from_str ( "1:" ) . unwrap ( ) ;
218
201
219
202
let mut input = b"a\n b" . as_slice ( ) ;
220
203
let mut output = Vec :: with_capacity ( 100 ) ;
@@ -225,7 +208,7 @@ mod tests {
225
208
#[ test]
226
209
fn fwd_handle_out_of_bounds ( ) {
227
210
let mut opt = make_lines_opt ( ) ;
228
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f3 ( ) ] ) ;
211
+ opt. bounds = UserBoundsList :: from_str ( "3" ) . unwrap ( ) ;
229
212
opt. join = true ;
230
213
231
214
let mut input = b"a\n b" . as_slice ( ) ;
@@ -237,7 +220,7 @@ mod tests {
237
220
#[ test]
238
221
fn fwd_ignore_last_empty ( ) {
239
222
let mut opt = make_lines_opt ( ) ;
240
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f3 ( ) ] ) ;
223
+ opt. bounds = UserBoundsList :: from_str ( "3" ) . unwrap ( ) ;
241
224
242
225
let mut input1 = b"a\n b" . as_slice ( ) ;
243
226
let mut input2 = b"a\n b\n " . as_slice ( ) ;
@@ -255,7 +238,7 @@ mod tests {
255
238
#[ test]
256
239
fn cut_lines_handle_negative_idx ( ) {
257
240
let mut opt = make_lines_opt ( ) ;
258
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_neg1 ( ) ] ) ;
241
+ opt. bounds = UserBoundsList :: from_str ( "-1" ) . unwrap ( ) ;
259
242
260
243
let mut input = b"a\n b" . as_slice ( ) ;
261
244
let mut output = Vec :: with_capacity ( 100 ) ;
@@ -266,7 +249,7 @@ mod tests {
266
249
#[ test]
267
250
fn cut_lines_ignore_last_empty_when_using_positive_idx ( ) {
268
251
let mut opt = make_lines_opt ( ) ;
269
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f3 ( ) ] ) ;
252
+ opt. bounds = UserBoundsList :: from_str ( "3" ) . unwrap ( ) ;
270
253
271
254
let mut input1 = b"a\n b" . as_slice ( ) ;
272
255
let mut input2 = b"a\n b\n " . as_slice ( ) ;
@@ -284,7 +267,7 @@ mod tests {
284
267
#[ test]
285
268
fn cut_lines_ignore_last_empty_when_using_negative_idx ( ) {
286
269
let mut opt = make_lines_opt ( ) ;
287
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_neg1 ( ) ] ) ;
270
+ opt. bounds = UserBoundsList :: from_str ( "-1" ) . unwrap ( ) ;
288
271
289
272
let mut input1 = b"a\n b" . as_slice ( ) ;
290
273
let mut input2 = b"a\n b\n " . as_slice ( ) ;
@@ -302,7 +285,7 @@ mod tests {
302
285
#[ test]
303
286
fn fwd_cut_zero_delimited ( ) {
304
287
let mut opt = make_lines_opt ( ) ;
305
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1 ( ) ] ) ;
288
+ opt. bounds = UserBoundsList :: from_str ( "1" ) . unwrap ( ) ;
306
289
opt. eol = EOL :: Zero ;
307
290
opt. delimiter = String :: from ( "\0 " ) ;
308
291
@@ -315,7 +298,7 @@ mod tests {
315
298
#[ test]
316
299
fn cut_lines_zero_delimited ( ) {
317
300
let mut opt = make_lines_opt ( ) ;
318
- opt. bounds = UserBoundsList :: new ( vec ! [ bof_f1 ( ) ] ) ;
301
+ opt. bounds = UserBoundsList :: from_str ( "1" ) . unwrap ( ) ;
319
302
opt. eol = EOL :: Zero ;
320
303
opt. delimiter = String :: from ( "\0 " ) ;
321
304
0 commit comments