-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathcore-util.test.js
More file actions
101 lines (77 loc) · 2.63 KB
/
Copy pathcore-util.test.js
File metadata and controls
101 lines (77 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { cached, isExternal } from '../../src/core/util/index.js';
// Core util
// -----------------------------------------------------------------------------
describe('core/util', () => {
describe('cached()', () => {
test('memoizes falsy return values', () => {
let calls = 0;
const fn = cached(() => {
calls += 1;
return '';
});
expect(fn('same-key')).toBe('');
expect(fn('same-key')).toBe('');
expect(calls).toBe(1);
});
test('memoizes undefined return values', () => {
let calls = 0;
const fn = cached(() => {
calls += 1;
return undefined;
});
expect(fn('same-key')).toBeUndefined();
expect(fn('same-key')).toBeUndefined();
expect(calls).toBe(1);
});
});
// isExternal()
// ---------------------------------------------------------------------------
describe('isExternal()', () => {
// cases non-external
test('non external local url with one /', () => {
const result = isExternal(`/${location.host}/docsify/demo.md`);
expect(result).toBeFalsy();
});
test('non external local url with two //', () => {
const result = isExternal(`//${location.host}/docsify/demo.md`);
expect(result).toBeFalsy();
});
test('non external local url with three ///', () => {
const result = isExternal(`///${location.host}/docsify/demo.md`);
expect(result).toBeFalsy();
});
test('non external local url with more /', () => {
const result = isExternal(
`//////////////////${location.host}/docsify/demo.md`,
);
expect(result).toBeFalsy();
});
test('non external url with one /', () => {
const result = isExternal('/example.github.io/docsify/demo.md');
expect(result).toBeFalsy();
});
// cases is external
test('external url with two //', () => {
const result = isExternal('/docsify/demo.md');
expect(result).toBeFalsy();
});
test('external url with three ///', () => {
const result = isExternal('///example.github.io/docsify/demo.md');
expect(result).toBeTruthy();
});
test('external url with more /', () => {
const result = isExternal(
'//////////////////example.github.io/docsify/demo.md',
);
expect(result).toBeTruthy();
});
test('external url with one \\', () => {
const result = isExternal('/\\example.github.io/docsify/demo.md');
expect(result).toBeTruthy();
});
test('external url with two \\', () => {
const result = isExternal('/\\\\example.github.io/docsify/demo.md');
expect(result).toBeTruthy();
});
});
});