|
| 1 | +import { createFilenameFromString } from "../../../src/common/filenames"; |
| 2 | + |
| 3 | +describe("createFilenameFromString", () => { |
| 4 | + const testCases: Array<{ |
| 5 | + input: string; |
| 6 | + filename: string; |
| 7 | + filenameWithoutDots?: string; |
| 8 | + }> = [ |
| 9 | + { |
| 10 | + input: "sql2o", |
| 11 | + filename: "sql2o", |
| 12 | + }, |
| 13 | + { |
| 14 | + input: "spring-boot", |
| 15 | + filename: "spring-boot", |
| 16 | + }, |
| 17 | + { |
| 18 | + input: "spring--boot", |
| 19 | + filename: "spring-boot", |
| 20 | + }, |
| 21 | + { |
| 22 | + input: "rt", |
| 23 | + filename: "rt", |
| 24 | + }, |
| 25 | + { |
| 26 | + input: "System.Runtime", |
| 27 | + filename: "system.runtime", |
| 28 | + filenameWithoutDots: "system-runtime", |
| 29 | + }, |
| 30 | + { |
| 31 | + input: "System..Runtime", |
| 32 | + filename: "system.runtime", |
| 33 | + filenameWithoutDots: "system-runtime", |
| 34 | + }, |
| 35 | + { |
| 36 | + input: "google/brotli", |
| 37 | + filename: "google-brotli", |
| 38 | + }, |
| 39 | + { |
| 40 | + input: "github/vscode-codeql", |
| 41 | + filename: "github-vscode-codeql", |
| 42 | + }, |
| 43 | + { |
| 44 | + input: "github/vscode---codeql--", |
| 45 | + filename: "github-vscode-codeql", |
| 46 | + }, |
| 47 | + { |
| 48 | + input: "github...vscode--c..odeql", |
| 49 | + filename: "github.vscode-c.odeql", |
| 50 | + filenameWithoutDots: "github-vscode-c-odeql", |
| 51 | + }, |
| 52 | + { |
| 53 | + input: "github\\vscode-codeql", |
| 54 | + filename: "github-vscode-codeql", |
| 55 | + }, |
| 56 | + { |
| 57 | + input: "uNetworking/uWebSockets.js", |
| 58 | + filename: "unetworking-uwebsockets.js", |
| 59 | + filenameWithoutDots: "unetworking-uwebsockets-js", |
| 60 | + }, |
| 61 | + ]; |
| 62 | + |
| 63 | + test.each(testCases)( |
| 64 | + "returns $filename if string is $input", |
| 65 | + ({ input, filename }) => { |
| 66 | + expect(createFilenameFromString(input)).toEqual(filename); |
| 67 | + }, |
| 68 | + ); |
| 69 | + |
| 70 | + test.each(testCases)( |
| 71 | + "returns $filename if string is $input and dots are not allowed", |
| 72 | + ({ input, filename, filenameWithoutDots }) => { |
| 73 | + expect( |
| 74 | + createFilenameFromString(input, { |
| 75 | + removeDots: true, |
| 76 | + }), |
| 77 | + ).toEqual(filenameWithoutDots ?? filename); |
| 78 | + }, |
| 79 | + ); |
| 80 | +}); |
0 commit comments