Skip to content

Commit dc5bdee

Browse files
committed
test(compile): add test coverage
1 parent cf8f20c commit dc5bdee

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export { default as testArrayLocation } from './test/array-location.js';
1212
export { default as testArrayIndex } from './test/array-index.js';
1313
export { default as testArrayDash } from './test/array-dash.js';
1414

15+
export { default as compile } from './compile.js';
16+
1517
export { default as escape } from './escape.js';
1618
export { default as unescape } from './unescape.js';
1719

test/compile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)