github.com/per1234/editorconfig-checker/v2@v2.8.5/pkg/utils/utils_test.go (about) 1 package utils 2 3 import ( 4 "testing" 5 ) 6 7 func TestGetEolChar(t *testing.T) { 8 getEolCharTests := []struct { 9 input string 10 expected string 11 }{ 12 {"lf", "\n"}, 13 {"cr", "\r"}, 14 {"crlf", "\r\n"}, 15 {"", "\n"}, 16 } 17 18 for _, tt := range getEolCharTests { 19 actual := GetEolChar(tt.input) 20 if actual != tt.expected { 21 t.Errorf("GetEolChar(%s): expected: %v, got: %v", tt.input, tt.expected, actual) 22 } 23 } 24 } 25 26 func TestIsRegularFile(t *testing.T) { 27 isRegularFileTests := []struct { 28 input string 29 expected bool 30 }{ 31 {"./utils.go", true}, 32 {"./notExisting.go", false}, 33 {".", false}, 34 } 35 36 for _, tt := range isRegularFileTests { 37 actual := IsRegularFile(tt.input) 38 if actual != tt.expected { 39 t.Errorf("IsRegularFile(%s): expected: %v, got: %v", tt.input, tt.expected, actual) 40 } 41 } 42 } 43 44 func TestIsDirectory(t *testing.T) { 45 isDirectoryTests := []struct { 46 input string 47 expected bool 48 }{ 49 {".", true}, 50 {"./notExisting", false}, 51 {"./utils.go", false}, 52 } 53 54 for _, tt := range isDirectoryTests { 55 actual := IsDirectory(tt.input) 56 if actual != tt.expected { 57 t.Errorf("IsDirectory(%s): expected: %v, got: %v", tt.input, tt.expected, actual) 58 } 59 } 60 } 61 62 func TestFileExists(t *testing.T) { 63 fileExistsTests := []struct { 64 input string 65 expected bool 66 }{ 67 {"./utils.go", true}, 68 {"./notExisting.go", false}, 69 } 70 71 for _, tt := range fileExistsTests { 72 actual := FileExists(tt.input) 73 if actual != tt.expected { 74 t.Errorf("FileExists(%s): expected: %v, got: %v", tt.input, tt.expected, actual) 75 } 76 } 77 }