|
1 | 1 | import * as assert from 'assert'; |
2 | | -import { getMatchingPropertyCount, getPropertyCount, isGlobalTSFile, isSymbolDescriptorMatch, JSONPTR } from '../util'; |
| 2 | +import { getMatchingPropertyCount, getPropertyCount, isGlobalTSFile, isSymbolDescriptorMatch, JSONPTR, path2uri, uri2path } from '../util'; |
3 | 3 |
|
4 | 4 | describe('util', () => { |
5 | 5 | describe('JSONPTR', () => { |
@@ -129,4 +129,47 @@ describe('util', () => { |
129 | 129 | assert.equal(isGlobalTSFile('/node_modules/@types/mocha/index.d.ts'), true); |
130 | 130 | }); |
131 | 131 | }); |
| 132 | + describe('path2uri()', () => { |
| 133 | + it('should throw an error if a non-absolute uri is passed in', () => { |
| 134 | + assert.throws(() => path2uri('baz/qux')); |
| 135 | + }); |
| 136 | + it('should convert a Unix file path to a URI', () => { |
| 137 | + const uri = path2uri('/baz/qux'); |
| 138 | + assert.equal(uri, 'file:///baz/qux'); |
| 139 | + }); |
| 140 | + it('should convert a Windows file path to a URI', () => { |
| 141 | + const uri = path2uri('C:\\baz\\qux'); |
| 142 | + assert.equal(uri, 'file:///C:/baz/qux'); |
| 143 | + }); |
| 144 | + it('should encode special characters', () => { |
| 145 | + const uri = path2uri('/💩'); |
| 146 | + assert.equal(uri, 'file:///%F0%9F%92%A9'); |
| 147 | + }); |
| 148 | + it('should encode unreserved special characters', () => { |
| 149 | + const uri = path2uri('/@baz'); |
| 150 | + assert.equal(uri, 'file:///%40baz'); |
| 151 | + }); |
| 152 | + }); |
| 153 | + describe('uri2path()', () => { |
| 154 | + it('should convert a Unix file URI to a file path', () => { |
| 155 | + const filePath = uri2path('file:///baz/qux'); |
| 156 | + assert.equal(filePath, '/baz/qux'); |
| 157 | + }); |
| 158 | + it('should convert a Windows file URI to a file path', () => { |
| 159 | + const filePath = uri2path('file:///c:/baz/qux'); |
| 160 | + assert.equal(filePath, 'c:\\baz\\qux'); |
| 161 | + }); |
| 162 | + it('should convert a Windows file URI with uppercase drive letter to a file path', () => { |
| 163 | + const filePath = uri2path('file:///C:/baz/qux'); |
| 164 | + assert.equal(filePath, 'C:\\baz\\qux'); |
| 165 | + }); |
| 166 | + it('should decode special characters', () => { |
| 167 | + const filePath = uri2path('file:///%F0%9F%92%A9'); |
| 168 | + assert.equal(filePath, '/💩'); |
| 169 | + }); |
| 170 | + it('should decode unreserved special characters', () => { |
| 171 | + const filePath = uri2path('file:///%40foo'); |
| 172 | + assert.equal(filePath, '/@foo'); |
| 173 | + }); |
| 174 | + }); |
132 | 175 | }); |
0 commit comments