2019-12-29 22:31:32 +00:00
|
|
|
import { escapeForRegExp, unifyPath, hashCode } from '../utils';
|
2019-10-06 20:04:33 +00:00
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
describe('Utils', () => {
|
|
|
|
|
describe('escapeForRegExp', () => {
|
|
|
|
|
it('should escape markdown link text', () => {
|
|
|
|
|
const result = escapeForRegExp('[Link](https://diff2html.xyz)');
|
2021-10-15 20:15:39 +00:00
|
|
|
expect(result).toBe('\\[Link\\]\\(https:\\/\\/diff2html\\.xyz\\)');
|
2019-10-21 22:37:42 +00:00
|
|
|
});
|
2019-12-29 22:31:32 +00:00
|
|
|
it('should escape all dangerous characters', () => {
|
|
|
|
|
const result = escapeForRegExp('-[]/{}()*+?.\\^$|');
|
2021-10-15 20:15:39 +00:00
|
|
|
expect(result).toBe('\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|');
|
2019-10-21 22:37:42 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
describe('unifyPath', () => {
|
|
|
|
|
it('should unify windows style path', () => {
|
|
|
|
|
const result = unifyPath('\\Users\\Downloads\\diff.html');
|
2021-10-15 20:15:39 +00:00
|
|
|
expect(result).toBe('/Users/Downloads/diff.html');
|
2019-10-21 22:37:42 +00:00
|
|
|
});
|
2019-11-26 09:44:09 +00:00
|
|
|
});
|
2019-10-21 22:37:42 +00:00
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
describe('hashCode', () => {
|
|
|
|
|
it('should create consistent hash for a text piece', () => {
|
|
|
|
|
const string = '/home/diff2html/diff.html';
|
2019-11-26 09:44:09 +00:00
|
|
|
expect(hashCode(string)).toEqual(hashCode(string));
|
2019-10-21 22:37:42 +00:00
|
|
|
});
|
2019-12-29 22:31:32 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|