|
| 1 | +const { isExternal } = require('../../src/core/util'); |
| 2 | + |
| 3 | +// Core util |
| 4 | +// ----------------------------------------------------------------------------- |
| 5 | +describe('core/util', () => { |
| 6 | + // isExternal() |
| 7 | + // --------------------------------------------------------------------------- |
| 8 | + describe('isExternal()', () => { |
| 9 | + // cases non external |
| 10 | + test('non external local url with one /', () => { |
| 11 | + const result = isExternal(`/${location.host}/docsify/demo.md`); |
| 12 | + |
| 13 | + expect(result).toBeFalsy(); |
| 14 | + }); |
| 15 | + |
| 16 | + test('non external local url with two //', () => { |
| 17 | + const result = isExternal(`//${location.host}/docsify/demo.md`); |
| 18 | + |
| 19 | + expect(result).toBeFalsy(); |
| 20 | + }); |
| 21 | + |
| 22 | + test('non external local url with three ///', () => { |
| 23 | + const result = isExternal(`///${location.host}/docsify/demo.md`); |
| 24 | + |
| 25 | + expect(result).toBeFalsy(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('non external local url with more /', () => { |
| 29 | + const result = isExternal( |
| 30 | + `//////////////////${location.host}/docsify/demo.md` |
| 31 | + ); |
| 32 | + |
| 33 | + expect(result).toBeFalsy(); |
| 34 | + }); |
| 35 | + |
| 36 | + test('non external url with one /', () => { |
| 37 | + const result = isExternal('/example.github.io/docsify/demo.md'); |
| 38 | + |
| 39 | + expect(result).toBeFalsy(); |
| 40 | + }); |
| 41 | + |
| 42 | + // cases is external |
| 43 | + test('external url with two //', () => { |
| 44 | + const result = isExternal('/docsify/demo.md'); |
| 45 | + |
| 46 | + expect(result).toBeFalsy(); |
| 47 | + }); |
| 48 | + |
| 49 | + test('external url with three ///', () => { |
| 50 | + const result = isExternal('///example.github.io/docsify/demo.md'); |
| 51 | + |
| 52 | + expect(result).toBeTruthy(); |
| 53 | + }); |
| 54 | + |
| 55 | + test('external url with more /', () => { |
| 56 | + const result = isExternal( |
| 57 | + '//////////////////example.github.io/docsify/demo.md' |
| 58 | + ); |
| 59 | + |
| 60 | + expect(result).toBeTruthy(); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments