github.com/dkishere/pop/v6@v6.103.1/fix/auto_timestamps_off_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"io/fs"
     5  	"os"
     6  	"regexp"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_AutoTimestampsOff(t *testing.T) {
    13  	r := require.New(t)
    14  	box := os.DirFS("fixtures/auto_timestamps_off/raw")
    15  	boxPatched := os.DirFS("fixtures/auto_timestamps_off/patched")
    16  
    17  	err := fs.WalkDir(box, ".", func(path string, d fs.DirEntry, err error) error {
    18  		if err != nil {
    19  			return err
    20  		}
    21  
    22  		if d.IsDir() {
    23  			return nil
    24  		}
    25  
    26  		t.Run(path, func(tt *testing.T) {
    27  			rr := require.New(tt)
    28  			b, err := fs.ReadFile(box, path)
    29  			rr.NoError(err)
    30  
    31  			body := string(b)
    32  			patched, err := AutoTimestampsOff(body)
    33  			rr.NoError(err)
    34  			expected, err := fs.ReadFile(boxPatched, path)
    35  			rr.NoError(err)
    36  
    37  			re := regexp.MustCompile(`(?m)([\n\r])+$`)
    38  
    39  			cleaned := re.ReplaceAllString(string(expected), "")
    40  			cleanedPatched := re.ReplaceAllString(patched, "")
    41  
    42  			rr.Equal(cleaned, cleanedPatched)
    43  		})
    44  		return nil
    45  	})
    46  
    47  	r.NoError(err)
    48  }