|
| 1 | +import { substituteConfigVariables } from "../../../src/common/config-template"; |
| 2 | + |
| 3 | +describe("substituteConfigVariables", () => { |
| 4 | + const values = { |
| 5 | + userHome: "/home/your-username", |
| 6 | + workspaceFolder: "/home/your-username/your-project", |
| 7 | + workspaceFolderBasename: "your-project", |
| 8 | + pathSeparator: "/", |
| 9 | + owner: "github", |
| 10 | + name: "vscode-codeql", |
| 11 | + language: "java", |
| 12 | + }; |
| 13 | + |
| 14 | + const testCases = [ |
| 15 | + { |
| 16 | + template: ".github/codeql/extensions/${name}-${language}", |
| 17 | + expected: ".github/codeql/extensions/vscode-codeql-java", |
| 18 | + }, |
| 19 | + { |
| 20 | + template: "${owner}/${name}-${language}", |
| 21 | + expected: "github/vscode-codeql-java", |
| 22 | + }, |
| 23 | + { |
| 24 | + template: "models/${group}.model.yml", |
| 25 | + expected: "models/.model.yml", |
| 26 | + }, |
| 27 | + { |
| 28 | + template: |
| 29 | + "${workspaceFolder}${pathSeparator}.github/workflows/codeql-analysis.yml", |
| 30 | + expected: |
| 31 | + "/home/your-username/your-project/.github/workflows/codeql-analysis.yml", |
| 32 | + }, |
| 33 | + { |
| 34 | + template: |
| 35 | + "${workspaceFolder/.github/codeql/extensions/${name}-${language}", |
| 36 | + expected: "workspaceFolder/.github/codeql/extensions/vscode-codeql-java", |
| 37 | + }, |
| 38 | + { |
| 39 | + template: "}${workspaceFolder}/.github/workflows/codeql-analysis.yml", |
| 40 | + expected: |
| 41 | + "}/home/your-username/your-project/.github/workflows/codeql-analysis.yml", |
| 42 | + }, |
| 43 | + { |
| 44 | + template: "Foo Bar", |
| 45 | + expected: "Foo Bar", |
| 46 | + }, |
| 47 | + { |
| 48 | + template: "Foo${}Bar", |
| 49 | + expected: "FooBar", |
| 50 | + }, |
| 51 | + { |
| 52 | + template: "$FooBar", |
| 53 | + expected: "", |
| 54 | + }, |
| 55 | + { |
| 56 | + template: "}FooBar", |
| 57 | + expected: "}FooBar", |
| 58 | + }, |
| 59 | + { |
| 60 | + template: "Foo ${name} Bar", |
| 61 | + expected: "Foo vscode-codeql Bar", |
| 62 | + }, |
| 63 | + { |
| 64 | + template: "Foo ${name} Bar ${owner}", |
| 65 | + expected: "Foo vscode-codeql Bar github", |
| 66 | + }, |
| 67 | + { |
| 68 | + template: "Foo ${nmae} Bar ${owner}", |
| 69 | + expected: "Foo Bar github", |
| 70 | + }, |
| 71 | + ]; |
| 72 | + |
| 73 | + test.each(testCases)( |
| 74 | + "result of $template is $expected", |
| 75 | + ({ template, expected }) => { |
| 76 | + expect(substituteConfigVariables(template, values)).toEqual(expected); |
| 77 | + }, |
| 78 | + ); |
| 79 | +}); |
0 commit comments