@@ -51,6 +51,27 @@ func TestColumn(t *testing.T) {
51
51
if ! bytes .Equal (got , want ) {
52
52
t .Errorf ("want %q, got %q" , want , got )
53
53
}
54
+ got , err = script .File ("testdata/column.input.txt" ).Column (0 ).Bytes ()
55
+ if err != nil {
56
+ t .Error ()
57
+ }
58
+ if ! bytes .Equal (got , []byte {}) {
59
+ t .Errorf ("want %q, got %q" , want , got )
60
+ }
61
+ got , err = script .File ("testdata/column.input.txt" ).Column (- 1 ).Bytes ()
62
+ if err != nil {
63
+ t .Error ()
64
+ }
65
+ if ! bytes .Equal (got , []byte {}) {
66
+ t .Errorf ("want %q, got %q" , want , got )
67
+ }
68
+ got , err = script .File ("testdata/column.input.txt" ).Column (10 ).Bytes ()
69
+ if err != nil {
70
+ t .Error ()
71
+ }
72
+ if ! bytes .Equal (got , []byte {}) {
73
+ t .Errorf ("want %q, got %q" , want , got )
74
+ }
54
75
}
55
76
56
77
func TestConcat (t * testing.T ) {
@@ -232,6 +253,18 @@ func TestFirst(t *testing.T) {
232
253
if err == nil {
233
254
t .Error ("input not closed after reading" )
234
255
}
256
+ input = script .File ("testdata/first.input.txt" )
257
+ gotZero , err = input .First (- 1 ).CountLines ()
258
+ if err != nil {
259
+ t .Fatal (err )
260
+ }
261
+ if gotZero != 0 {
262
+ t .Errorf ("want 0 lines, got %d lines" , gotZero )
263
+ }
264
+ _ , err = ioutil .ReadAll (input .Reader )
265
+ if err == nil {
266
+ t .Error ("input not closed after reading" )
267
+ }
235
268
want , err = script .File ("testdata/first.input.txt" ).Bytes ()
236
269
if err != nil {
237
270
t .Fatal (err )
@@ -312,6 +345,18 @@ func TestLast(t *testing.T) {
312
345
if err == nil {
313
346
t .Error ("input not closed after reading" )
314
347
}
348
+ input = script .File ("testdata/first.input.txt" )
349
+ gotZero , err = input .Last (- 1 ).CountLines ()
350
+ if err != nil {
351
+ t .Fatal (err )
352
+ }
353
+ if gotZero != 0 {
354
+ t .Errorf ("want 0 lines, got %d lines" , gotZero )
355
+ }
356
+ _ , err = ioutil .ReadAll (input .Reader )
357
+ if err == nil {
358
+ t .Error ("input not closed after reading" )
359
+ }
315
360
want , err = script .File ("testdata/first.input.txt" ).Bytes ()
316
361
if err != nil {
317
362
t .Fatal (err )
@@ -350,6 +395,16 @@ func TestMatch(t *testing.T) {
350
395
351
396
func TestMatchRegexp (t * testing.T ) {
352
397
t .Parallel ()
398
+ p := script .File ("testdata/hello.txt" )
399
+ _ , err := p .MatchRegexp (nil ).String ()
400
+ if err == nil {
401
+ t .Error ("nil regex should cause an error" )
402
+ }
403
+ _ , err = ioutil .ReadAll (p .Reader )
404
+ if err == nil {
405
+ t .Error ("input not closed after reading" )
406
+ }
407
+
353
408
testCases := []struct {
354
409
testFileName string
355
410
match string
@@ -397,6 +452,16 @@ func TestReplace(t *testing.T) {
397
452
398
453
func TestReplaceRegexp (t * testing.T ) {
399
454
t .Parallel ()
455
+ p := script .File ("testdata/hello.txt" )
456
+ _ , err := p .ReplaceRegexp (nil , "" ).String ()
457
+ if err == nil {
458
+ t .Error ("nil regex should cause an error" )
459
+ }
460
+ _ , err = ioutil .ReadAll (p .Reader )
461
+ if err == nil {
462
+ t .Error ("input not closed after reading" )
463
+ }
464
+
400
465
testCases := []struct {
401
466
testFileName string
402
467
regexp string
@@ -444,6 +509,16 @@ func TestReject(t *testing.T) {
444
509
445
510
func TestRejectRegexp (t * testing.T ) {
446
511
t .Parallel ()
512
+ p := script .File ("testdata/hello.txt" )
513
+ _ , err := p .RejectRegexp (nil ).String ()
514
+ if err == nil {
515
+ t .Error ("nil regex should cause an error" )
516
+ }
517
+ _ , err = ioutil .ReadAll (p .Reader )
518
+ if err == nil {
519
+ t .Error ("input not closed after reading" )
520
+ }
521
+
447
522
testCases := []struct {
448
523
testFileName string
449
524
reject string
0 commit comments