firetruss
Version:
Advanced data sync layer for Firebase and Vue.js
24 lines (19 loc) • 798 B
JavaScript
import test from 'ava';
import {escapeKey, unescapeKey, joinPath, makePathMatcher} from './paths.js';
test('escapeKey', t => {
t.is(escapeKey('foo\\.$#[]/'), 'foo\\5c\\2e\\24\\23\\5b\\5d\\2f');
});
test('unescapeKey', t => {
t.is(unescapeKey('foo\\5c\\2e\\24\\23\\5b\\5d\\2f'), 'foo\\.$#[]/');
});
test('joinPath', t => {
t.is(joinPath('/foo', 'bar'), '/foo/bar');
t.is(joinPath('/', 'foo/bar', 'baz'), '/foo/bar/baz');
t.is(joinPath('/foo', '/bar'), '/bar');
});
test('PathMatcher', t => {
t.deepEqual(makePathMatcher('/foo/bar').match('/foo/bar'), {});
t.falsy(makePathMatcher('/foo/bar').match('/foo/qux'));
t.deepEqual(makePathMatcher('/foo/$bar').match('/foo/qux'), {$bar: 'qux'});
t.deepEqual(makePathMatcher('/foo/$bar/$*').match('/foo/qux/quuux'), {$bar: 'qux'});
});