|
1 | 1 | import outdent from 'outdent'; |
2 | 2 | import { parseYamlToDocument } from '../../__tests__/utils.js'; |
3 | | -import { parseRef, refBaseName } from '../ref-utils.js'; |
| 3 | +import { escapePointer, parseRef, refBaseName, unescapePointerFromURI } from '../ref-utils.js'; |
4 | 4 | import { lintDocument } from '../lint.js'; |
5 | 5 | import { createConfig } from '../config/index.js'; |
6 | 6 | import { BaseResolver } from '../resolve.js'; |
@@ -139,4 +139,37 @@ describe('ref-utils', () => { |
139 | 139 | expect(refBaseName('abcdefg')).toStrictEqual('abcdefg'); |
140 | 140 | }); |
141 | 141 | }); |
| 142 | + |
| 143 | + describe('escapePointer', () => { |
| 144 | + it('should escape a pointer correctly', () => { |
| 145 | + expect(escapePointer('scope/complex~name')).toStrictEqual('scope~1complex~0name'); |
| 146 | + }); |
| 147 | + |
| 148 | + it('should escape a pointer with a number correctly', () => { |
| 149 | + expect(escapePointer(123)).toStrictEqual(123); |
| 150 | + }); |
| 151 | + |
| 152 | + it('should escape a pointer with a string correctly', () => { |
| 153 | + expect(escapePointer('scope/complex~name')).toStrictEqual('scope~1complex~0name'); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should not URI-encode special characters when escaping pointers', () => { |
| 157 | + // escapePointer should only handle JSON Pointer escaping, not URI encoding |
| 158 | + expect(escapePointer('activity_level_%')).toStrictEqual('activity_level_%'); |
| 159 | + }); |
| 160 | + }); |
| 161 | + |
| 162 | + describe('unescapePointerFromURI', () => { |
| 163 | + it('should unescape a pointer with a percent sign correctly', () => { |
| 164 | + expect(unescapePointerFromURI('activity_level_%25')).toStrictEqual('activity_level_%'); |
| 165 | + }); |
| 166 | + |
| 167 | + it('should unescape a pointer with a number correctly', () => { |
| 168 | + expect(unescapePointerFromURI('123')).toStrictEqual('123'); |
| 169 | + }); |
| 170 | + |
| 171 | + it('should unescape a pointer correctly', () => { |
| 172 | + expect(unescapePointerFromURI('scope~1complex~0name')).toStrictEqual('scope/complex~name'); |
| 173 | + }); |
| 174 | + }); |
142 | 175 | }); |
0 commit comments