github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/internal/fileresolver/directory_windows_test.go (about) 1 package fileresolver 2 3 import "testing" 4 5 func Test_windowsToPosix(t *testing.T) { 6 type args struct { 7 windowsPath string 8 } 9 tests := []struct { 10 name string 11 args args 12 wantPosixPath string 13 }{ 14 { 15 name: "basic case", 16 args: args{ 17 windowsPath: `C:\some\windows\place`, 18 }, 19 wantPosixPath: "/c/some/windows/place", 20 }, 21 { 22 name: "escaped case", 23 args: args{ 24 windowsPath: `C:\\some\\windows\\place`, 25 }, 26 wantPosixPath: "/c/some/windows/place", 27 }, 28 { 29 name: "forward slash", 30 args: args{ 31 windowsPath: `C:/foo/bar`, 32 }, 33 wantPosixPath: "/c/foo/bar", 34 }, 35 { 36 name: "mix slash", 37 args: args{ 38 windowsPath: `C:\foo/bar\`, 39 }, 40 wantPosixPath: "/c/foo/bar", 41 }, 42 { 43 name: "case sensitive case", 44 args: args{ 45 windowsPath: `C:\Foo/bAr\`, 46 }, 47 wantPosixPath: "/c/Foo/bAr", 48 }, 49 { 50 name: "special char case", 51 args: args{ 52 windowsPath: `C:\ふー\バー`, 53 }, 54 wantPosixPath: "/c/ふー/バー", 55 }, 56 } 57 58 for _, tt := range tests { 59 t.Run(tt.name, func(t *testing.T) { 60 if gotPosixPath := windowsToPosix(tt.args.windowsPath); gotPosixPath != tt.wantPosixPath { 61 t.Errorf("windowsToPosix() = %v, want %v", gotPosixPath, tt.wantPosixPath) 62 } 63 }) 64 } 65 } 66 67 func Test_posixToWindows(t *testing.T) { 68 type args struct { 69 posixPath string 70 } 71 tests := []struct { 72 name string 73 args args 74 wantWindowsPath string 75 }{ 76 { 77 name: "basic case", 78 args: args{ 79 posixPath: "/c/some/windows/place", 80 }, 81 wantWindowsPath: `C:\some\windows\place`, 82 }, 83 { 84 name: "escaped case", 85 args: args{ 86 posixPath: "/c/some/windows/place", 87 }, 88 wantWindowsPath: `C:\\some\\windows\\place`, 89 }, 90 { 91 name: "forward slash", 92 args: args{ 93 posixPath: "/c/foo/bar", 94 }, 95 wantWindowsPath: `C:/foo/bar`, 96 }, 97 { 98 name: "mix slash", 99 args: args{ 100 posixPath: "/c/foo/bar", 101 }, 102 wantWindowsPath: `C:\foo/bar\`, 103 }, 104 { 105 name: "case sensitive case", 106 args: args{ 107 posixPath: "/c/Foo/bAr", 108 }, 109 wantWindowsPath: `C:\Foo/bAr\`, 110 }, 111 { 112 name: "special char case", 113 args: args{ 114 posixPath: "/c/ふー/バー", 115 }, 116 wantWindowsPath: `C:\ふー\バー`, 117 }, 118 } 119 for _, tt := range tests { 120 t.Run(tt.name, func(t *testing.T) { 121 if gotWindowsPath := posixToWindows(tt.args.posixPath); gotWindowsPath != tt.wantWindowsPath { 122 t.Errorf("posixToWindows() = %v, want %v", gotWindowsPath, tt.wantWindowsPath) 123 } 124 }) 125 } 126 }