|
| 1 | +package ls_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/microsoft/typescript-go/internal/ls" |
| 7 | + "github.com/microsoft/typescript-go/internal/lsp/lsproto" |
| 8 | + "gotest.tools/v3/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestDocumentURIToFileName(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + tests := []struct { |
| 15 | + uri lsproto.DocumentUri |
| 16 | + fileName string |
| 17 | + }{ |
| 18 | + {"file:///path/to/file.ts", "/path/to/file.ts"}, |
| 19 | + {"file://server/share/file.ts", "//server/share/file.ts"}, |
| 20 | + {"file:///d%3A/work/tsgo932/lib/utils.ts", "d:/work/tsgo932/lib/utils.ts"}, |
| 21 | + {"file:///D%3A/work/tsgo932/lib/utils.ts", "d:/work/tsgo932/lib/utils.ts"}, |
| 22 | + {"file:///d%3A/work/tsgo932/app/%28test%29/comp/comp-test.tsx", "d:/work/tsgo932/app/(test)/comp/comp-test.tsx"}, |
| 23 | + {"file:///path/to/file.ts#section", "/path/to/file.ts"}, |
| 24 | + {"file:///c:/test/me", "c:/test/me"}, |
| 25 | + {"file://shares/files/c%23/p.cs", "//shares/files/c#/p.cs"}, |
| 26 | + {"file:///c:/Source/Z%C3%BCrich%20or%20Zurich%20(%CB%88zj%CA%8A%C9%99r%C9%AAk,/Code/resources/app/plugins/c%23/plugin.json", "c:/Source/Zürich or Zurich (ˈzjʊərɪk,/Code/resources/app/plugins/c#/plugin.json"}, |
| 27 | + {"file:///c:/test %25/path", "c:/test %/path"}, |
| 28 | + // {"file:?q", "/"}, |
| 29 | + {"file:///_:/path", "/_:/path"}, |
| 30 | + {"file:///users/me/c%23-projects/", "/users/me/c#-projects/"}, |
| 31 | + {"file://localhost/c%24/GitDevelopment/express", "//localhost/c$/GitDevelopment/express"}, |
| 32 | + {"file:///c%3A/test%20with%20%2525/c%23code", "c:/test with %25/c#code"}, |
| 33 | + |
| 34 | + {"untitled:Untitled-1", "^/untitled/ts-nul-authority/Untitled-1"}, |
| 35 | + {"untitled:Untitled-1#fragment", "^/untitled/ts-nul-authority/Untitled-1#fragment"}, |
| 36 | + {"untitled:c:/Users/jrieken/Code/abc.txt", "^/untitled/ts-nul-authority/c:/Users/jrieken/Code/abc.txt"}, |
| 37 | + {"untitled:C:/Users/jrieken/Code/abc.txt", "^/untitled/ts-nul-authority/c:/Users/jrieken/Code/abc.txt"}, |
| 38 | + } |
| 39 | + |
| 40 | + for _, test := range tests { |
| 41 | + t.Run(string(test.uri), func(t *testing.T) { |
| 42 | + t.Parallel() |
| 43 | + assert.Equal(t, ls.DocumentURIToFileName(test.uri), test.fileName) |
| 44 | + }) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func TestFileNameToDocumentURI(t *testing.T) { |
| 49 | + t.Parallel() |
| 50 | + |
| 51 | + tests := []struct { |
| 52 | + fileName string |
| 53 | + uri lsproto.DocumentUri |
| 54 | + }{ |
| 55 | + {"/path/to/file.ts", "file:///path/to/file.ts"}, |
| 56 | + {"//server/share/file.ts", "file://server/share/file.ts"}, |
| 57 | + {"d:/work/tsgo932/lib/utils.ts", "file:///d%3A/work/tsgo932/lib/utils.ts"}, |
| 58 | + {"d:/work/tsgo932/lib/utils.ts", "file:///d%3A/work/tsgo932/lib/utils.ts"}, |
| 59 | + {"d:/work/tsgo932/app/(test)/comp/comp-test.tsx", "file:///d%3A/work/tsgo932/app/%28test%29/comp/comp-test.tsx"}, |
| 60 | + {"/path/to/file.ts", "file:///path/to/file.ts"}, |
| 61 | + {"c:/test/me", "file:///c%3A/test/me"}, |
| 62 | + {"//shares/files/c#/p.cs", "file://shares/files/c%23/p.cs"}, |
| 63 | + {"c:/Source/Zürich or Zurich (ˈzjʊərɪk,/Code/resources/app/plugins/c#/plugin.json", "file:///c%3A/Source/Z%C3%BCrich%20or%20Zurich%20%28%CB%88zj%CA%8A%C9%99r%C9%AAk%2C/Code/resources/app/plugins/c%23/plugin.json"}, |
| 64 | + {"c:/test %/path", "file:///c%3A/test%20%25/path"}, |
| 65 | + {"/", "file:///"}, |
| 66 | + {"/_:/path", "file:///_%3A/path"}, |
| 67 | + {"/users/me/c#-projects/", "file:///users/me/c%23-projects/"}, |
| 68 | + {"//localhost/c$/GitDevelopment/express", "file://localhost/c%24/GitDevelopment/express"}, |
| 69 | + {"c:/test with %25/c#code", "file:///c%3A/test%20with%20%2525/c%23code"}, |
| 70 | + |
| 71 | + {"^/untitled/ts-nul-authority/Untitled-1", "untitled:Untitled-1"}, |
| 72 | + {"^/untitled/ts-nul-authority/c:/Users/jrieken/Code/abc.txt", "untitled:c:/Users/jrieken/Code/abc.txt"}, |
| 73 | + } |
| 74 | + |
| 75 | + for _, test := range tests { |
| 76 | + t.Run(test.fileName, func(t *testing.T) { |
| 77 | + t.Parallel() |
| 78 | + assert.Equal(t, ls.FileNameToDocumentURI(test.fileName), test.uri) |
| 79 | + }) |
| 80 | + } |
| 81 | +} |
0 commit comments