github.com/aretext/aretext@v1.3.0/file/load_test.go (about)

     1  package file
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestLoad(t *testing.T) {
    12  	testCases := []struct {
    13  		name                 string
    14  		fileContents         string
    15  		expectedTreeContents string
    16  	}{
    17  		{
    18  			name:                 "empty",
    19  			fileContents:         "",
    20  			expectedTreeContents: "",
    21  		},
    22  		{
    23  			name:                 "ends with character, no POSIX eof",
    24  			fileContents:         "ab\ncd",
    25  			expectedTreeContents: "ab\ncd",
    26  		},
    27  		{
    28  			name:                 "POSIX eof",
    29  			fileContents:         "abcd\n",
    30  			expectedTreeContents: "abcd",
    31  		},
    32  	}
    33  
    34  	for _, tc := range testCases {
    35  		t.Run(tc.name, func(t *testing.T) {
    36  			filePath := createTestFile(t, tc.fileContents)
    37  
    38  			tree, watcher, err := Load(filePath, time.Second)
    39  			require.NoError(t, err)
    40  			defer watcher.Stop()
    41  
    42  			assert.Equal(t, tc.expectedTreeContents, tree.String())
    43  		})
    44  	}
    45  }