Skip to content

Commit

Permalink
Add regex unit tests for getting faster feedback (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick authored Aug 27, 2024
1 parent bd9eb19 commit 5ae6a79
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"editorconfig.editorconfig",
"tekumara.typos-vscode",
"dprint.dprint",
"jnoortheen.nix-ide"
"jnoortheen.nix-ide",
"denoland.vscode-deno"
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
],
"url": "https://docs.renovatebot.com/renovate-schema.json"
}
]
],
"deno.enable": true,
"deno.lint": true
}
5 changes: 4 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ tasks:
default:
deps:
- task: fmt
- task: lint
- task: check
check:
deps:
- task: lint
cmds:
- renovate-config-validator default.json self.json
- deno test --allow-read
fmt:
cmds:
- dprint fmt
- git ls-files '*.nix' | xargs nix fmt
lint:
cmds:
- dprint check
- deno lint
- typos . .github .vscode
# nix fmt doesn't have check: https://github.com/NixOS/nix/issues/6918
- git ls-files '*.nix' | xargs nixfmt --check
Expand All @@ -31,3 +33,4 @@ tasks:
- typos --version
- nixfmt --version
- renovate --version
- deno --version
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
go-task
typos
gh

deno
])
++ (with unstables; [
dprint
Expand Down
35 changes: 35 additions & 0 deletions regex_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// https://github.com/google/re2-wasm is not updated in this few years, however it is easy to be used than node-re2 in deno
import { RE2 } from "npm:[email protected]";

import { assertEquals, assertExists } from "jsr:@std/assert@1";

import renovateDefault from "./default.json" with { type: "json" };

Deno.test("Given URL matches to correct depNameTemplate", async (t) => {
const urlToTemplate = new Map<string, string>([
[`"https://plugins.dprint.dev/typescript-0.91.6.wasm"`, "dprint/dprint-plugin-{{{pluginName}}}"],
[`"https://plugins.dprint.dev/json-0.19.3.wasm"`, "dprint/dprint-plugin-{{{pluginName}}}"],
[`"https://plugins.dprint.dev/markdown-0.17.8.wasm"`, "dprint/dprint-plugin-{{{pluginName}}}"],
[`"https://plugins.dprint.dev/toml-0.6.2.wasm"`, "dprint/dprint-plugin-{{{pluginName}}}"],
[`"https://plugins.dprint.dev/dockerfile-0.3.2.wasm"`, "dprint/dprint-plugin-{{{pluginName}}}"],
[`"https://plugins.dprint.dev/sql-0.2.0.wasm"`, "dprint/dprint-plugin-{{{pluginName}}}"],
[`"https://plugins.dprint.dev/g-plane/malva-v0.10.1.wasm"`, "{{{user}}}/{{{pluginName}}}"],
[`"https://plugins.dprint.dev/g-plane/markup_fmt-v0.12.0.wasm"`, "{{{user}}}/{{{pluginName}}}"],
[`"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm"`, "{{{user}}}/{{{pluginName}}}"],
[`"https://plugins.dprint.dev/g-plane/pretty_graphql-v0.2.0.wasm"`, "{{{user}}}/{{{pluginName}}}"],
[`"https://plugins.dprint.dev/kachick/kdl-0.2.0.wasm"`, "{{{user}}}/dprint-plugin-{{{pluginName}}}"],
]);

for (const [url, template] of urlToTemplate) {
await t.step(url, () => {
const manager = renovateDefault.customManagers.find((cm) =>
cm.matchStrings.some((matcher) => {
const re2 = new RE2(matcher, "u");
return re2.exec(url);
})
);
assertExists(manager);
assertEquals(manager.depNameTemplate, template);
});
}
});

0 comments on commit 5ae6a79

Please sign in to comment.