(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func TestSolutionFile(t *testing.T) { |
| 80 | testCases := []struct { |
| 81 | name, file, expectedPath, expectedURL string |
| 82 | }{ |
| 83 | { |
| 84 | name: "filename with special character", |
| 85 | file: "special-char-filename#.txt", |
| 86 | expectedPath: "special-char-filename#.txt", |
| 87 | expectedURL: "http://www.example.com/special-char-filename%23.txt", |
| 88 | }, |
| 89 | { |
| 90 | name: "filename with leading slash", |
| 91 | file: "/with-leading-slash.txt", |
| 92 | expectedPath: fmt.Sprintf("%cwith-leading-slash.txt", os.PathSeparator), |
| 93 | expectedURL: "http://www.example.com//with-leading-slash.txt", |
| 94 | }, |
| 95 | { |
| 96 | name: "filename with leading backslash", |
| 97 | file: "\\with-leading-backslash.txt", |
| 98 | expectedPath: fmt.Sprintf("%cwith-leading-backslash.txt", os.PathSeparator), |
| 99 | expectedURL: "http://www.example.com/%5Cwith-leading-backslash.txt", |
| 100 | }, |
| 101 | { |
| 102 | name: "filename with backslashes in path", |
| 103 | file: "\\backslashes\\in-path.txt", |
| 104 | expectedPath: fmt.Sprintf("%[1]cbackslashes%[1]cin-path.txt", os.PathSeparator), |
| 105 | expectedURL: "http://www.example.com/%5Cbackslashes%5Cin-path.txt", |
| 106 | }, |
| 107 | { |
| 108 | name: "path with a numeric suffix", |
| 109 | file: "/bogus-exercise-12345/numeric.txt", |
| 110 | expectedPath: fmt.Sprintf("%[1]cbogus-exercise-12345%[1]cnumeric.txt", os.PathSeparator), |
| 111 | expectedURL: "http://www.example.com//bogus-exercise-12345/numeric.txt", |
| 112 | }, |
| 113 | } |
| 114 | |
| 115 | for _, tc := range testCases { |
| 116 | t.Run(tc.name, func(t *testing.T) { |
| 117 | sf := solutionFile{ |
| 118 | path: tc.file, |
| 119 | baseURL: "http://www.example.com/", |
| 120 | } |
| 121 | |
| 122 | if sf.relativePath() != tc.expectedPath { |
| 123 | t.Fatalf("Expected path '%s', got '%s'", tc.expectedPath, sf.relativePath()) |
| 124 | } |
| 125 | |
| 126 | url, err := sf.url() |
| 127 | if err != nil { |
| 128 | t.Fatal(err) |
| 129 | } |
| 130 | |
| 131 | if url != tc.expectedURL { |
| 132 | t.Fatalf("Expected URL '%s', got '%s'", tc.expectedURL, url) |
| 133 | } |
| 134 | }) |
| 135 | } |
| 136 | } |
nothing calls this directly
no test coverage detected