mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 18:26:16 +01:00
fix unit test
This commit is contained in:
@@ -26,16 +26,20 @@ import { regExpPattern } from "./remarkCommitLinksParser";
|
||||
|
||||
describe("Remark Commit Links RegEx Tests", () => {
|
||||
it("should match simple names", () => {
|
||||
expect("namespace/name@1a5s4w8a".match(regExpPattern)).toBeTruthy();
|
||||
const regExp = new RegExp(regExpPattern, "g");
|
||||
expect("namespace/name@1a5s4w8a".match(regExp)).toBeTruthy();
|
||||
});
|
||||
it("should match complex names", () => {
|
||||
expect("hitchhiker/heart-of-gold@c7237cb60689046990dc9dc2a388a517adb3e2b2".match(regExpPattern)).toBeTruthy();
|
||||
const regExp = new RegExp(regExpPattern, "g");
|
||||
expect("hitchhiker/heart-of-gold@c7237cb60689046990dc9dc2a388a517adb3e2b2".match(regExp)).toBeTruthy();
|
||||
});
|
||||
it("should replace match", () => {
|
||||
expect("Prefix namespace/name@42 suffix".replace(regExpPattern, "replaced")).toBe("Prefix replaced suffix");
|
||||
const regExp = new RegExp(regExpPattern, "g");
|
||||
expect("Prefix namespace/name@42 suffix".replace(regExp, "replaced")).toBe("Prefix replaced suffix");
|
||||
});
|
||||
it("should match groups", () => {
|
||||
const match = regExpPattern.exec("namespace/name@42");
|
||||
const regExp = new RegExp(regExpPattern, "g");
|
||||
const match = regExp.exec("namespace/name@42");
|
||||
expect(match).toBeTruthy();
|
||||
if (match) {
|
||||
expect(match[1]).toBe("namespace");
|
||||
@@ -44,15 +48,18 @@ describe("Remark Commit Links RegEx Tests", () => {
|
||||
}
|
||||
});
|
||||
it("should match multiple links in text", () => {
|
||||
const regExp = new RegExp(regExpPattern, "g");
|
||||
const text = "Prefix hitchhiker/heart-of-gold@42 some text hitchhiker/heart-of-gold@21 suffix";
|
||||
const matches = [];
|
||||
|
||||
let match = regExpPattern.exec(text);
|
||||
let match = regExp.exec(text);
|
||||
while (match !== null) {
|
||||
matches.push(match[0]);
|
||||
match = regExpPattern.exec(text);
|
||||
match = regExp.exec(text);
|
||||
}
|
||||
|
||||
console.log(matches)
|
||||
|
||||
expect(matches[0]).toBe("hitchhiker/heart-of-gold@42");
|
||||
expect(matches[1]).toBe("hitchhiker/heart-of-gold@21");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user