github.com/paweljw/pop@v4.13.1+incompatible/fix/auto_timestamps_off_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"io/ioutil"
     5  	"regexp"
     6  	"testing"
     7  
     8  	"github.com/gobuffalo/packr/v2"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_AutoTimestampsOff(t *testing.T) {
    13  	r := require.New(t)
    14  	box := packr.New("./fixtures/auto_timestamps_off/raw", "./fixtures/auto_timestamps_off/raw")
    15  	boxPatched := packr.New("./fixtures/auto_timestamps_off/patched", "./fixtures/auto_timestamps_off/patched")
    16  
    17  	err := box.Walk(func(path string, info packr.File) error {
    18  		t.Run(path, func(tt *testing.T) {
    19  			rr := require.New(tt)
    20  			b, err := ioutil.ReadAll(info)
    21  			rr.NoError(err)
    22  
    23  			body := string(b)
    24  			patched, err := AutoTimestampsOff(body)
    25  			rr.NoError(err)
    26  			expected, err := boxPatched.FindString(path)
    27  			rr.NoError(err)
    28  
    29  			re := regexp.MustCompile(`(?m)([\n\r])+$`)
    30  
    31  			cleaned := re.ReplaceAllString(expected, "")
    32  			cleanedPatched := re.ReplaceAllString(patched, "")
    33  
    34  			rr.Equal(cleaned, cleanedPatched)
    35  
    36  		})
    37  		return nil
    38  	})
    39  	r.NoError(err)
    40  }