github.com/lingyao2333/mo-zero@v1.4.1/core/iox/textfile_test.go (about) 1 package iox 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestCountLines(t *testing.T) { 11 const val = `1 12 2 13 3 14 4` 15 file, err := os.CreateTemp(os.TempDir(), "test-") 16 if err != nil { 17 t.Fatal(err) 18 } 19 defer os.Remove(file.Name()) 20 21 file.WriteString(val) 22 file.Close() 23 lines, err := CountLines(file.Name()) 24 assert.Nil(t, err) 25 assert.Equal(t, 4, lines) 26 }