github.com/mcuadros/enry@v1.7.3/cmd/enry/main_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 ) 6 7 func TestGetLines(t *testing.T) { 8 tests := []struct { 9 content string 10 wantTotal int 11 wantNonBlank int 12 }{ 13 // 0 14 {content: "This is one line", wantTotal: 1, wantNonBlank: 1}, 15 // 1 Test no content 16 {content: "", wantTotal: 0, wantNonBlank: 0}, 17 // 2 A single blank line 18 {content: "One blank line\n\nTwo nonblank lines", wantTotal: 3, wantNonBlank: 2}, 19 // 3 Testing multiple blank lines in a row 20 {content: "\n\n", wantTotal: 3, wantNonBlank: 0}, 21 // 4 ' 22 {content: "\n\n\n\n", wantTotal: 5, wantNonBlank: 0}, 23 // 5 Multiple blank lines content on ends 24 {content: "content\n\n\n\ncontent", wantTotal: 5, wantNonBlank: 2}, 25 // 6 Content with blank lines on ends 26 {content: "\n\n\ncontent\n\n\n", wantTotal: 7, wantNonBlank: 1}, 27 } 28 29 for i, test := range tests { 30 t.Run("", func(t *testing.T) { 31 gotTotal, gotNonBlank := getLines("", []byte(test.content)) 32 if gotTotal != test.wantTotal || gotNonBlank != test.wantNonBlank { 33 t.Errorf("wrong line counts obtained for test case #%d:\n %7s, %7s\nGOT: %7d, %7d\nWANT: %7d, %7d\n", i, "TOTAL", "NON_BLANK", 34 gotTotal, gotNonBlank, test.wantTotal, test.wantNonBlank) 35 } 36 }) 37 } 38 }