2019-10-21 22:37:42 +00:00
|
|
|
import { escapeForRegExp, escapeForHtml, unifyPath, hashCode } from "../utils";
|
2019-10-06 20:04:33 +00:00
|
|
|
|
2019-10-21 22:37:42 +00:00
|
|
|
describe("Utils", () => {
|
|
|
|
|
describe("escapeForRegExp", () => {
|
|
|
|
|
it("should escape markdown link text", () => {
|
|
|
|
|
const result = escapeForRegExp("[Link](https://diff2html.xyz)");
|
|
|
|
|
expect(result).toEqual("\\[Link\\]\\(https:\\/\\/diff2html\\.xyz\\)");
|
|
|
|
|
});
|
|
|
|
|
it("should escape all dangerous characters", () => {
|
|
|
|
|
const result = escapeForRegExp("-[]/{}()*+?.\\^$|");
|
|
|
|
|
expect(result).toEqual("\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("escapeForHtml", () => {
|
|
|
|
|
it("should escape & with &", () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = escapeForHtml("&");
|
2019-10-21 22:37:42 +00:00
|
|
|
expect(result).toEqual("&");
|
2019-10-06 20:04:33 +00:00
|
|
|
});
|
2019-10-21 22:37:42 +00:00
|
|
|
it("should escape < with <", () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = escapeForHtml("<");
|
2019-10-21 22:37:42 +00:00
|
|
|
expect(result).toEqual("<");
|
2019-10-06 20:04:33 +00:00
|
|
|
});
|
2019-10-21 22:37:42 +00:00
|
|
|
it("should escape > with >", () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = escapeForHtml(">");
|
2019-10-21 22:37:42 +00:00
|
|
|
expect(result).toEqual(">");
|
|
|
|
|
});
|
|
|
|
|
it('should escape " with "', () => {
|
|
|
|
|
const result = escapeForHtml('"');
|
|
|
|
|
expect(result).toEqual(""");
|
|
|
|
|
});
|
|
|
|
|
it("should escape ' with '", () => {
|
|
|
|
|
const result = escapeForHtml("'");
|
|
|
|
|
expect(result).toEqual("'");
|
2019-10-06 20:04:33 +00:00
|
|
|
});
|
2019-10-21 22:37:42 +00:00
|
|
|
it("should escape / with /", () => {
|
|
|
|
|
const result = escapeForHtml("/");
|
|
|
|
|
expect(result).toEqual("/");
|
|
|
|
|
});
|
|
|
|
|
it("should escape a string containing HTML code", () => {
|
|
|
|
|
const result = escapeForHtml(`<a href="/search?q=diff2html">Search 'Diff2Html'</a>`);
|
|
|
|
|
expect(result).toEqual(
|
|
|
|
|
"<a href="/search?q=diff2html">Search 'Diff2Html'</a>"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("unifyPath", () => {
|
|
|
|
|
it("should unify windows style path", () => {
|
|
|
|
|
const result = unifyPath("\\Users\\Downloads\\diff.html");
|
|
|
|
|
expect(result).toEqual("/Users/Downloads/diff.html");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("hashCode", () => {
|
|
|
|
|
it("should create consistent hash for a text piece", () => {
|
|
|
|
|
const string = "/home/diff2html/diff.html";
|
|
|
|
|
expect(hashCode(string)).toEqual(hashCode(string));
|
|
|
|
|
});
|
|
|
|
|
it("should create different hash for different text pieces", () => {
|
|
|
|
|
expect(hashCode("/home/diff2html/diff1.html")).not.toEqual(hashCode("/home/diff2html/diff2.html"));
|
|
|
|
|
});
|
2019-10-06 20:04:33 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|