|
1 | 1 | import { join } from "path"; |
2 | 2 |
|
3 | 3 | import { |
| 4 | + containsPath, |
4 | 5 | gatherQlFiles, |
5 | 6 | getDirectoryNamesInsidePath, |
6 | 7 | pathsEqual, |
@@ -203,3 +204,98 @@ describe("pathsEqual", () => { |
203 | 204 | }, |
204 | 205 | ); |
205 | 206 | }); |
| 207 | + |
| 208 | +describe("containsPath", () => { |
| 209 | + const testCases: Array<{ |
| 210 | + path1: string; |
| 211 | + path2: string; |
| 212 | + platform: NodeJS.Platform; |
| 213 | + expected: boolean; |
| 214 | + }> = [ |
| 215 | + { |
| 216 | + path1: |
| 217 | + "/home/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 218 | + path2: |
| 219 | + "/home/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 220 | + platform: "linux", |
| 221 | + expected: true, |
| 222 | + }, |
| 223 | + { |
| 224 | + path1: |
| 225 | + "/HOME/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 226 | + path2: |
| 227 | + "/home/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 228 | + platform: "linux", |
| 229 | + expected: false, |
| 230 | + }, |
| 231 | + { |
| 232 | + path1: |
| 233 | + "/home/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 234 | + path2: |
| 235 | + "/home/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 236 | + platform: "linux", |
| 237 | + expected: false, |
| 238 | + }, |
| 239 | + { |
| 240 | + path1: |
| 241 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 242 | + path2: |
| 243 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 244 | + platform: "win32", |
| 245 | + expected: true, |
| 246 | + }, |
| 247 | + { |
| 248 | + path1: |
| 249 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 250 | + path2: |
| 251 | + "c:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 252 | + platform: "win32", |
| 253 | + expected: true, |
| 254 | + }, |
| 255 | + { |
| 256 | + path1: |
| 257 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 258 | + path2: |
| 259 | + "D:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 260 | + platform: "win32", |
| 261 | + expected: false, |
| 262 | + }, |
| 263 | + { |
| 264 | + path1: |
| 265 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript/example.ql", |
| 266 | + path2: |
| 267 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 268 | + platform: "win32", |
| 269 | + expected: false, |
| 270 | + }, |
| 271 | + { |
| 272 | + path1: |
| 273 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 274 | + path2: |
| 275 | + "C:\\Users\\github\\projects\\vscode-codeql-starter\\codeql-custom-queries-javascript\\example.ql", |
| 276 | + platform: "win32", |
| 277 | + expected: true, |
| 278 | + }, |
| 279 | + { |
| 280 | + path1: |
| 281 | + "C:/Users/github/projects/vscode-codeql-starter/codeql-custom-queries-javascript", |
| 282 | + path2: |
| 283 | + "D:\\Users\\github\\projects\\vscode-codeql-starter\\codeql-custom-queries-javascript\\example.ql", |
| 284 | + platform: "win32", |
| 285 | + expected: false, |
| 286 | + }, |
| 287 | + ]; |
| 288 | + |
| 289 | + test.each(testCases)( |
| 290 | + "$path1 contains $path2 on $platform = $expected", |
| 291 | + ({ path1, path2, platform, expected }) => { |
| 292 | + if (platform !== process.platform) { |
| 293 | + // We're using the platform-specific path.resolve, so we can't really run |
| 294 | + // these tests on all platforms. |
| 295 | + return; |
| 296 | + } |
| 297 | + |
| 298 | + expect(containsPath(path1, path2, platform)).toEqual(expected); |
| 299 | + }, |
| 300 | + ); |
| 301 | +}); |
0 commit comments