|
| 1 | +import { assert } from 'chai'; |
| 2 | + |
| 3 | +import { compile } from '../src/index.js'; |
| 4 | + |
| 5 | +describe('compile', function () { |
| 6 | + it('should return an empty string for an empty array', function () { |
| 7 | + assert.strictEqual(compile([]), ''); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should compile a single reference token', function () { |
| 11 | + assert.strictEqual(compile(['foo']), '/foo'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should join multiple reference tokens with "/"', function () { |
| 15 | + assert.strictEqual(compile(['foo', 'bar', 'baz']), '/foo/bar/baz'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should escape "/" as "~1"', function () { |
| 19 | + assert.strictEqual(compile(['foo/bar']), '/foo~1bar'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should escape "~" as "~0"', function () { |
| 23 | + assert.strictEqual(compile(['foo~bar']), '/foo~0bar'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should escape both "/" and "~" correctly', function () { |
| 27 | + assert.strictEqual(compile(['foo/bar~baz']), '/foo~1bar~0baz'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should handle multiple occurrences of "/" and "~"', function () { |
| 31 | + assert.strictEqual(compile(['/foo~bar/', '/baz~qux/']), '/~1foo~0bar~1/~1baz~0qux~1'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return the same string if there are no special characters', function () { |
| 35 | + assert.strictEqual(compile(['foo-bar_baz']), '/foo-bar_baz'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should retain spaces and special symbols without escaping them', function () { |
| 39 | + assert.strictEqual(compile(['foo bar', 'baz@qux']), '/foo bar/baz@qux'); |
| 40 | + }); |
| 41 | +}); |
0 commit comments