UNPKG

@platform/cell.schema

Version:

URI and database schemas for the `cell.os`.

735 lines (734 loc) 33.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var test_1 = require("../test"); var _1 = require("."); describe('Uri', function () { describe('ids', function () { it('Uri.cuid', function () { var res = _1.Uri.cuid(); (0, test_1.expect)(res.length).to.greaterThan(15); }); it('Uri.slug', function () { var res = _1.Uri.slug(); (0, test_1.expect)(res.length).to.within(5, 10); }); }); describe('uri.kind', function () { it('NS', function () { var uri = _1.Uri.parse(' ns:foo '); (0, test_1.expect)(uri.ok).to.eql(true); (0, test_1.expect)(uri.type).to.eql('NS'); (0, test_1.expect)(uri.parts.type).to.eql(uri.type); (0, test_1.expect)(uri.toString()).to.eql('ns:foo'); (0, test_1.expect)(uri.parts.toString()).to.eql(uri.toString()); }); it('CELL', function () { var uri = _1.Uri.parse(' cell:foo:A1 '); (0, test_1.expect)(uri.ok).to.eql(true); (0, test_1.expect)(uri.type).to.eql('CELL'); (0, test_1.expect)(uri.parts.type).to.eql(uri.type); (0, test_1.expect)(uri.toString()).to.eql('cell:foo:A1'); (0, test_1.expect)(uri.parts.toString()).to.eql(uri.toString()); }); it('ROW', function () { var uri = _1.Uri.parse(' cell:foo:1 '); (0, test_1.expect)(uri.ok).to.eql(true); (0, test_1.expect)(uri.type).to.eql('ROW'); (0, test_1.expect)(uri.parts.type).to.eql(uri.type); (0, test_1.expect)(uri.toString()).to.eql('cell:foo:1'); (0, test_1.expect)(uri.parts.toString()).to.eql(uri.toString()); }); it('COLUMN', function () { var uri = _1.Uri.parse(' cell:foo:A '); (0, test_1.expect)(uri.ok).to.eql(true); (0, test_1.expect)(uri.type).to.eql('COLUMN'); (0, test_1.expect)(uri.parts.type).to.eql(uri.type); (0, test_1.expect)(uri.toString()).to.eql('cell:foo:A'); (0, test_1.expect)(uri.parts.toString()).to.eql(uri.toString()); }); it('FILE', function () { var uri = _1.Uri.parse(' file:foo:bar '); (0, test_1.expect)(uri.ok).to.eql(true); (0, test_1.expect)(uri.type).to.eql('FILE'); (0, test_1.expect)(uri.parts.type).to.eql(uri.type); (0, test_1.expect)(uri.toString()).to.eql('file:foo:bar'); (0, test_1.expect)(uri.parts.toString()).to.eql(uri.toString()); }); }); describe('ns: allowed identifiers', function () { afterEach(function () { _1.Uri.ALLOW = tslib_1.__assign({}, test_1.TEST_ALLOW); }); it('allows "foo*" (test)', function () { (0, test_1.expect)(_1.Uri.ALLOW.NS).to.eql(['foo*']); (0, test_1.expect)(_1.Uri.parse('ns:foo').ok).to.eql(true); }); it('allowed identifiers (ns)', function () { (0, test_1.expect)(_1.Uri.parse('ns:foo').ok).to.eql(true); (0, test_1.expect)(_1.Uri.parse('ns:foo.bar').ok).to.eql(true); }); it('fails when non-cuid identifier not on the ALLOW list', function () { _1.Uri.ALLOW.NS = ['foo*']; var uri1 = _1.Uri.parse('ns:foo'); var uri2 = _1.Uri.parse('ns:bonkers'); (0, test_1.expect)(uri1.ok).to.eql(true); (0, test_1.expect)(uri2.ok).to.eql(false); }); it('supports wildcards in ALLOW list ', function () { var test = function (allow, uri, ok) { _1.Uri.ALLOW.NS = [allow]; (0, test_1.expect)(_1.Uri.parse(uri).ok).to.eql(ok); }; test('sys*', 'ns:sys', true); test('sys*', 'ns:sys.foo', true); test('sys*', 'ns:foo.sys', false); test('*sys*', 'ns:foo.sys', true); test('*sys', 'ns:foo.sys', true); test('*sys', 'ns:foo.sys.bar', false); }); it('supports functions in ALLOW list ', function () { var test = function (allow, uri, ok) { _1.Uri.ALLOW.NS = [allow]; (0, test_1.expect)(_1.Uri.parse(uri).ok).to.eql(ok); }; test(function (input) { return input.startsWith('sys'); }, 'ns:sys', true); test(function (input) { return input.startsWith('sys'); }, 'ns:sys.foo', true); test(function (input) { return input.startsWith('sys'); }, 'ns:foo', false); }); }); describe('is', function () { it('is.uri', function () { var test = function (input, expected) { (0, test_1.expect)(_1.Uri.is.uri(input)).to.eql(expected, input); }; test('ns:foo', true); test('cell:foo:A1', true); test('cell:foo:1', true); test('cell:foo:A', true); test('file:foo:123', true); test('=cell:foo:A1', true); test(' =cell:foo:A1 ', true); test(' cell:foo:A1 ', true); test(undefined, false); test(null, false); test('', false); test(' ', false); test('ns:', false); test('cell:', false); test('file:', false); test('cell:foo', false); test('file:foo', false); test('file:foo.123', false); test('file:foo-123', false); test('boo:foo', false); test('row:', false); test('col:', false); }); it('is.type', function () { var test = function (type, input, expected) { (0, test_1.expect)(_1.Uri.is.type(type, input)).to.eql(expected, "".concat(type, " | input: ").concat(input)); }; test('NS', 'ns:foo', true); test('NS', '=ns:foo', true); test('CELL', 'cell:foo:A1', true); test('COLUMN', 'cell:foo:A', true); test('ROW', 'cell:foo:1', true); test('FILE', 'file:foo:123', true); test('UNKNOWN', 'foo:bar:1', true); test(['COLUMN', 'ROW', 'CELL'], 'cell:foo:A1', true); test(['COLUMN', 'ROW', 'CELL'], '=cell:foo:A1', true); test(['COLUMN', 'ROW', 'CELL'], 'cell:foo:1', true); test(['COLUMN', 'ROW', 'CELL'], 'cell:foo:A', true); test(['NS', 'FILE'], 'cell:foo:A1', false); test(['NS'], 'ns:foo', true); test(['COLUMN', 'ROW', 'CELL', 'NS'], 'ns:foo', true); test('NS', undefined, false); test('CELL', undefined, false); test('COLUMN', undefined, false); test('ROW', undefined, false); test('FILE', undefined, false); test('NS', '', false); test('CELL', '', false); test('COLUMN', '', false); test('ROW', '', false); test('FILE', '', false); }); it('is.ns', function () { var test = function (input, expected) { (0, test_1.expect)(_1.Uri.is.ns(input)).to.eql(expected); }; test('ns:foo', true); test('=ns:foo', true); test('', false); test(undefined, false); test('cell:foo:A1', false); test('cell:foo:1', false); test('cell:foo:A', false); test('ns:boo', false); }); it('is.file', function () { var test = function (input, expected) { (0, test_1.expect)(_1.Uri.is.file(input)).to.eql(expected); }; test('file:foo:123', true); test('=file:foo:123', true); test('file:foo', false); test('ns:foo', false); test('', false); test(undefined, false); }); it('is.cell', function () { var test = function (input, expected) { (0, test_1.expect)(_1.Uri.is.cell(input)).to.eql(expected); }; test('cell:foo:A1', true); test('=cell:foo:A1', true); test('', false); test(undefined, false); test('ns:foo', false); test('col:foo:A', false); test('cell:boo:A1', false); }); it('is.row', function () { var test = function (input, expected) { (0, test_1.expect)(_1.Uri.is.row(input)).to.eql(expected); }; test('cell:foo:1', true); test('=cell:foo:1', true); test('', false); test(undefined, false); test('ns:foo', false); test('cell:foo:A', false); test('cell:boo:A', false); }); it('is.column', function () { var test = function (input, expected) { (0, test_1.expect)(_1.Uri.is.column(input)).to.eql(expected); }; test('cell:foo:A', true); test('=cell:foo:A', true); test('', false); test(undefined, false); test('ns:foo', false); test('row:foo:1', false); test('cell:boo:1', false); }); }); describe('clean', function () { var test = function (input, expected) { var res = _1.Uri.clean(input); (0, test_1.expect)(res).to.eql(expected); }; it('strips whitespace', function () { test('', ''); test(' ', ''); test(undefined, ''); }); it('strips query-string', function () { test('foo?q=123', 'foo'); test(' foo?q=123 ', 'foo'); test(' foo ?q=123 ', 'foo'); }); it('strips "=" prefix', function () { test('=foo', 'foo'); test(' =foo ', 'foo'); test(' = foo ', 'foo'); test('=foo?q=123', 'foo'); }); it('strips quotes', function () { test("\"foo\"", 'foo'); test(" \"foo\" ", 'foo'); test("'foo'", 'foo'); test("'foo\"", 'foo'); test("=\"foo\" ", 'foo'); test(" = \"foo\" ", 'foo'); test("\"=foo\" ", 'foo'); test("\" = foo\" ", 'foo'); test("\"foo?q=123\"", 'foo'); test("\"foo?q=123\"", 'foo'); test("\"=foo?q=123\"", 'foo'); test("\" =foo?q=123 \"", 'foo'); }); }); describe('parse', function () { it('ns', function () { var res = _1.Uri.parse('ns:foo'); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.error).to.eql(undefined); (0, test_1.expect)(res.parts.type).to.eql('NS'); (0, test_1.expect)(res.parts.id).to.eql('foo'); (0, test_1.expect)(res.uri).to.eql('ns:foo'); (0, test_1.expect)(res.toString()).to.eql(res.uri); }); it('cell', function () { var res = _1.Uri.parse('cell:foo:A1'); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.error).to.eql(undefined); (0, test_1.expect)(res.parts.type).to.eql('CELL'); (0, test_1.expect)(res.parts.id).to.eql('foo:A1'); (0, test_1.expect)(res.parts.ns).to.eql('foo'); (0, test_1.expect)(res.parts.key).to.eql('A1'); (0, test_1.expect)(res.uri).to.eql('cell:foo:A1'); (0, test_1.expect)(res.toString()).to.eql(res.uri); }); it('lowercase key (cell | column)', function () { var test = function (input, uri) { var res = _1.Uri.parse(input); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.error).to.eql(undefined); (0, test_1.expect)(res.uri).to.eql(uri); }; test('cell:foo:a1', 'cell:foo:A1'); test('cell:foo:a', 'cell:foo:A'); }); it('cell (row)', function () { var res = _1.Uri.parse('cell:foo:1'); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.error).to.eql(undefined); (0, test_1.expect)(res.parts.type).to.eql('ROW'); (0, test_1.expect)(res.parts.id).to.eql('foo:1'); (0, test_1.expect)(res.parts.ns).to.eql('foo'); (0, test_1.expect)(res.parts.key).to.eql('1'); (0, test_1.expect)(res.uri).to.eql('cell:foo:1'); (0, test_1.expect)(res.toString()).to.eql(res.uri); }); it('cell (column)', function () { var res = _1.Uri.parse('cell:foo:A'); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.error).to.eql(undefined); (0, test_1.expect)(res.parts.type).to.eql('COLUMN'); (0, test_1.expect)(res.parts.id).to.eql('foo:A'); (0, test_1.expect)(res.parts.ns).to.eql('foo'); (0, test_1.expect)(res.parts.key).to.eql('A'); (0, test_1.expect)(res.uri).to.eql('cell:foo:A'); (0, test_1.expect)(res.toString()).to.eql(res.uri); }); it('file', function () { var res = _1.Uri.parse('file:foo:123'); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.error).to.eql(undefined); (0, test_1.expect)(res.parts.type).to.eql('FILE'); (0, test_1.expect)(res.parts.id).to.eql('foo:123'); (0, test_1.expect)(res.parts.ns).to.eql('foo'); (0, test_1.expect)(res.parts.file).to.eql('123'); (0, test_1.expect)(res.uri).to.eql('file:foo:123'); (0, test_1.expect)(res.toString()).to.eql(res.uri); }); it('strips query-string', function () { var test = function (uri) { var res = _1.Uri.parse(uri); (0, test_1.expect)(res.ok).to.eql(true); (0, test_1.expect)(res.uri).to.eql(uri.split('?')[0]); }; test('file:foo:123?hash=abc'); test('ns:foo?hash=abc'); test('cell:foo:A1?hash=abc'); test('cell:foo:A?hash=abc'); test('cell:foo:1?hash=abc'); }); describe('error', function () { it('error: UNKNOWN', function () { var test = function (input) { var res = _1.Uri.parse(input); (0, test_1.expect)(res.ok).to.eql(false); (0, test_1.expect)(res.parts.type).to.eql('UNKNOWN'); (0, test_1.expect)(res.uri).to.eql((input || '').trim()); }; test(undefined); test(''); test(' '); test('foo'); test('foo:bar'); }); it('no ":" seperated parts', function () { var res = _1.Uri.parse('foo'); (0, test_1.expect)(res.ok).to.eql(false); (0, test_1.expect)(res.error && res.error.message).to.contain('Not a valid multi-part URI'); }); it('ns: no ID', function () { var test = function (input) { var res = _1.Uri.parse(input); (0, test_1.expect)(res.ok).to.eql(false); (0, test_1.expect)(res.error && res.error.message).to.contain('Namespace URI identifier not found'); }; test('ns:'); test('ns: '); }); it('cell: no namespace', function () { var test = function (input) { var res = _1.Uri.parse(input); (0, test_1.expect)(res.ok).to.eql(false); (0, test_1.expect)(res.error && res.error.message).to.contain("ID of 'cell' not found"); }; test('cell:'); test('cell: '); test(' cell: '); }); it('cell: no key', function () { var res = _1.Uri.parse('cell:foo'); (0, test_1.expect)(res.ok).to.eql(false); (0, test_1.expect)(res.error && res.error.message).to.contain("does not have a coordinate address"); (0, test_1.expect)(res.parts.key).to.eql(''); (0, test_1.expect)(res.parts.ns).to.eql(''); }); it('file', function () { var test = function (input, error) { var res = _1.Uri.parse(input); (0, test_1.expect)(res.ok).to.eql(false); (0, test_1.expect)(res.error && res.error.message).to.contain(error); }; test('file:', 'File URI identifier not found'); test(' file: ', 'File URI identifier not found'); test('file:foo', 'File identifier within namespace "foo" not found'); }); }); }); describe('parseOrThrow (shorthand methods)', function () { it('ns', function () { var _a; var uri = _1.Uri.ns('ns:foo'); (0, test_1.expect)(uri.id).to.eql('foo'); (0, test_1.expect)(_1.Uri.ns(uri)).to.eql(uri); (0, test_1.expect)(function () { return _1.Uri.ns('cell:foo:A1'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.ns('cell:foo:A1', false); }).to.not.throw(); var res; _1.Uri.ns('cell:foo:A1', function (e) { return (res = e); }); (0, test_1.expect)((_a = res === null || res === void 0 ? void 0 : res.error) === null || _a === void 0 ? void 0 : _a.message).to.include("is not of type NS"); }); it('ns (no prefix)', function () { var uri = _1.Uri.ns('foo'); (0, test_1.expect)(uri.toString()).to.eql('ns:foo'); (0, test_1.expect)(uri.id).to.eql('foo'); (0, test_1.expect)(_1.Uri.ns(uri)).to.eql(uri); (0, test_1.expect)(function () { return _1.Uri.ns('cell:foo:A1'); }).to.throw(); }); it('ns (error variants)', function () { (0, test_1.expect)(function () { return _1.Uri.ns('cell:foo:A1'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.ns('ns:fail'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.ns('fail'); }).to.throw(); }); it('cell', function () { var _a; var uri = _1.Uri.cell('cell:foo:A1'); (0, test_1.expect)(uri.ns).to.eql('foo'); (0, test_1.expect)(uri.key).to.eql('A1'); (0, test_1.expect)(_1.Uri.cell(uri)).to.eql(uri); (0, test_1.expect)(function () { return _1.Uri.cell('cell:foo:A'); }).to.throw(); var res; _1.Uri.cell('cell:foo:A', function (e) { return (res = e); }); (0, test_1.expect)((_a = res === null || res === void 0 ? void 0 : res.error) === null || _a === void 0 ? void 0 : _a.message).to.include("is not of type CELL"); }); it('row', function () { var _a; var uri = _1.Uri.row('cell:foo:1'); (0, test_1.expect)(uri.ns).to.eql('foo'); (0, test_1.expect)(uri.key).to.eql('1'); (0, test_1.expect)(_1.Uri.row(uri)).to.eql(uri); (0, test_1.expect)(function () { return _1.Uri.row('cell:foo:A1'); }).to.throw(); var res; _1.Uri.row('cell:foo:A1', function (e) { return (res = e); }); (0, test_1.expect)((_a = res === null || res === void 0 ? void 0 : res.error) === null || _a === void 0 ? void 0 : _a.message).to.include("is not of type ROW"); }); it('column', function () { var _a; var uri = _1.Uri.column('cell:foo:A'); (0, test_1.expect)(uri.ns).to.eql('foo'); (0, test_1.expect)(uri.key).to.eql('A'); (0, test_1.expect)(_1.Uri.column(uri)).to.eql(uri); (0, test_1.expect)(function () { return _1.Uri.column('cell:foo:A1'); }).to.throw(); var res; _1.Uri.column('cell:foo:A1', function (e) { return (res = e); }); (0, test_1.expect)((_a = res === null || res === void 0 ? void 0 : res.error) === null || _a === void 0 ? void 0 : _a.message).to.include("is not of type COLUMN"); }); it('file', function () { var _a; var uri = _1.Uri.file('file:foo:123'); (0, test_1.expect)(uri.ns).to.eql('foo'); (0, test_1.expect)(uri.file).to.eql('123'); (0, test_1.expect)(_1.Uri.file(uri)).to.eql(uri); (0, test_1.expect)(function () { return _1.Uri.file('cell:foo:A1'); }).to.throw(); var res; _1.Uri.file('cell:foo:A1', function (e) { return (res = e); }); (0, test_1.expect)((_a = res === null || res === void 0 ? void 0 : res.error) === null || _a === void 0 ? void 0 : _a.message).to.include("is not of type FILE"); }); }); describe('create', function () { it('A1', function () { var res = _1.Uri.create.A1(); (0, test_1.expect)(_1.Uri.is.cell(res)).to.eql(true); (0, test_1.expect)(res.endsWith(':A1')).to.eql(true); (0, test_1.expect)(res).to.not.eql(_1.Uri.create.A1()); }); it('ns', function () { var test = function (id, expected) { var res = _1.Uri.create.ns(id); (0, test_1.expect)(res).to.eql(expected); }; test('foo', 'ns:foo'); test('ns:foo', 'ns:foo'); test(' ns::foo ', 'ns:foo'); }); it('file', function () { var test = function (ns, file, expected) { var res = _1.Uri.create.file(ns, file); (0, test_1.expect)(res).to.eql(expected); }; test('foo', '123', 'file:foo:123'); test(' foo ', ' 123 ', 'file:foo:123'); test('file:foo', '123', 'file:foo:123'); }); it('cell', function () { var test = function (ns, key, expected) { var res = _1.Uri.create.cell(ns, key); (0, test_1.expect)(res).to.eql(expected); }; test('foo', 'A1', 'cell:foo:A1'); test('foo', ':A1', 'cell:foo:A1'); test('foo', '::A1', 'cell:foo:A1'); }); it('row', function () { var test = function (ns, key, expected) { var res = _1.Uri.create.row(ns, key); (0, test_1.expect)(res).to.eql(expected); }; test('foo', '1', 'cell:foo:1'); test('foo', ':1', 'cell:foo:1'); test('foo', '::1', 'cell:foo:1'); }); it('column', function () { var test = function (ns, key, expected) { var res = _1.Uri.create.column(ns, key); (0, test_1.expect)(res).to.eql(expected); }; test('foo', 'A', 'cell:foo:A'); test('foo', ':A', 'cell:foo:A'); test('foo', '::A', 'cell:foo:A'); }); var ILLEGAL = { NS: '~`!@#$%^&*()_-+=,/?;|[]{}', }; it('throws: ns', function () { (0, test_1.expect)(function () { return _1.Uri.create.ns(':'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.ns('ns:'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.ns(' ns: '); }).to.throw(); ILLEGAL.NS.split('').forEach(function (char) { var uid = (0, test_1.cuid)(); var id = "".concat(uid.substring(0, 10)).concat(char).concat(uid.substring(11)); (0, test_1.expect)(function () { return _1.Uri.create.ns(id); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.ns("ns:".concat(id)); }).to.throw(); }); }); it('throws: ns (not cuid)', function () { var err = /URI contains an invalid "ns" identifier/; (0, test_1.expect)(function () { return _1.Uri.create.ns('fail'); }).to.throw(err); (0, test_1.expect)(function () { return _1.Uri.create.ns('ns:fail'); }).to.throw(err); var uri = _1.Uri.parse("ns:fail"); (0, test_1.expect)(uri.ok).to.eql(false); (0, test_1.expect)(uri.error && uri.error.message).to.match(err); }); it('throws: file', function () { (0, test_1.expect)(function () { return _1.Uri.create.file(':', 'fileid'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.file('ns:', 'fileid'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.file(' ns: ', 'fileid'); }).to.throw(); ILLEGAL.NS.split('').forEach(function (char) { var ns = "ns:foo".concat(char, "def"); (0, test_1.expect)(function () { return _1.Uri.create.file(ns, 'fileid'); }).to.throw(); }); ILLEGAL.NS.split('').forEach(function (char) { var file = "abc".concat(char, "def"); (0, test_1.expect)(function () { return _1.Uri.create.file('foo', file); }).to.throw(); }); }); it('throws: cell', function () { (0, test_1.expect)(function () { return _1.Uri.create.cell('', 'A1'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.cell('foo', ''); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.cell('foo', '!'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.cell('foo', 'A'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.cell('foo', '1'); }).to.throw(); }); it('throws: column', function () { (0, test_1.expect)(function () { return _1.Uri.create.column('', 'A'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.column('foo', ''); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.column('foo', '!'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.column('foo', 'A1'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.column('foo', '1'); }).to.throw(); }); it('throws: row', function () { (0, test_1.expect)(function () { return _1.Uri.create.row('', '1'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.row('foo', ''); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.row('foo', '!'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.row('foo', 'A1'); }).to.throw(); (0, test_1.expect)(function () { return _1.Uri.create.row('foo', 'A'); }).to.throw(); }); }); describe('strip', function () { it('strip.ns', function () { var test = function (input, expected) { var res = _1.Uri.strip.ns(input); (0, test_1.expect)(res).to.eql(expected); }; test(undefined, ''); test('', ''); test('foo', 'foo'); test(' foo ', 'foo'); test('ns:foo', 'foo'); test('ns', 'ns'); test(' ns:foo ', 'foo'); test('foo:123', 'foo:123'); test('cell:foo:A1', 'cell:foo:A1'); test('file:foo:123', 'file:foo:123'); }); it('strip.cell', function () { var test = function (input, expected) { var res = _1.Uri.strip.cell(input); (0, test_1.expect)(res).to.eql(expected); }; test(undefined, ''); test('', ''); test(' ', ''); test('foo', 'foo'); test('cell', 'cell'); test('cell:foo:A1', 'foo:A1'); test(' cell:foo:A ', 'foo:A'); test(' cell:foo:1 ', 'foo:1'); test('ns:foo', 'ns:foo'); test('file:foo:123', 'file:foo:123'); }); it('strip.file', function () { var test = function (input, expected) { var res = _1.Uri.strip.file(input); (0, test_1.expect)(res).to.eql(expected); }; test(undefined, ''); test('', ''); test(' ', ''); test('foo', 'foo'); test('file', 'file'); test('file:abc:123', 'abc:123'); test(' file:abc:123 ', 'abc:123'); test('cell:foo:A1', 'cell:foo:A1'); test('ns:foo', 'ns:foo'); }); }); describe('toNs', function () { it('converts to namespace', function () { var test = function (input) { var res = _1.Uri.toNs(input); (0, test_1.expect)(res.type).to.eql('NS'); (0, test_1.expect)(res.toString()).to.eql('ns:foo'); }; test('foo'); test(' ns:foo '); test('cell:foo:A1'); test('cell:foo:A'); test('cell:foo:1'); test('file:foo:abc'); test(_1.Uri.ns('foo')); test(_1.Uri.cell('cell:foo:A1')); test(_1.Uri.row('cell:foo:1')); test(_1.Uri.column('cell:foo:A')); test(_1.Uri.file('file:foo:abc')); }); it('generates namespace (undefined)', function () { var res = _1.Uri.toNs(); (0, test_1.expect)(res.type).to.eql('NS'); (0, test_1.expect)(_1.Uri.is.ns(res.toString())).to.eql(true); }); it('throws: non-supported URI', function () { var fn = function () { return _1.Uri.toNs('foo:bar:baz'); }; (0, test_1.expect)(fn).to.throw(/namespace cannot be derived/); }); it('throws: empty string', function () { var fn = function () { return _1.Uri.toNs(''); }; (0, test_1.expect)(fn).to.throw(/Namespace URI identifier not found/); }); }); describe('indexes', function () { it('toRowIndex', function () { var test = function (input, expected) { var res = _1.Uri.toRowIndex(input); (0, test_1.expect)(res).to.eql(expected); }; test(undefined, -1); test('', -1); test(' ', -1); test('FAIL', -1); test('ns:foo', -1); test('file:foo:123', -1); test('cell:foo:A', -1); test('cell:foo:1', 0); test('cell:foo:10', 9); test('cell:foo:A1', 0); test('cell:foo:Z9', 8); test('=cell:foo:10', 9); test(' =cell:foo:Z9 ', 8); }); it('toColumnIndex', function () { var test = function (input, expected) { var res = _1.Uri.toColumnIndex(input); (0, test_1.expect)(res).to.eql(expected); }; test(undefined, -1); test('', -1); test(' ', -1); test('FAIL', -1); test('ns:foo', -1); test('file:foo:123', -1); test('cell:foo:1', -1); test('cell:foo:A', 0); test('cell:foo:A1', 0); test('cell:foo:B9', 1); test('=cell:foo:C5', 2); test(' =cell:foo:C5 ', 2); }); }); describe('eq', function () { var test = function (a, b, expected) { (0, test_1.expect)(_1.Uri.eq(a, b)).to.eql(expected); (0, test_1.expect)(_1.Uri.eq(b, a)).to.eql(expected); }; it('empty (strings)', function () { test('', '', true); test(' ', '', true); }); it('undefined (illegal)', function () { test(undefined, undefined, true); test(null, null, true); test(undefined, null, true); test(undefined, 'ns:foo', false); test(null, 'ns:foo', false); }); it('namespace', function () { test('ns:foo', 'ns:foo', true); test('foo', 'ns:foo', true); test('foo', 'foo', true); test(' ns:foo ', 'ns:foo', true); test(_1.Uri.ns('foo'), 'ns:foo', true); test('ns:foo', 'ns:bar', false); test('foo', 'ns:bar', false); test('foo', 'bar', false); test('ns:foo', undefined, false); test(_1.Uri.ns('foo'), 'ns:bar', false); test(_1.Uri.ns('foo'), 'bar', false); test(_1.Uri.ns('foo'), undefined, false); }); it('cell | row | column', function () { test('cell:foo:A1', ' cell:foo:A1 ', true); test('cell:foo:A1', 'cell:foo:A1', true); test('cell:foo:A', 'cell:foo:A', true); test('cell:foo:1', 'cell:foo:1', true); test('cell:foo:A1', 'cell:foo:Z9', false); }); it('file', function () { test('file:foo:abc', 'file:foo:abc', true); test('file:foo:abc', ' file:foo:abc ', true); test('file:foo:abc', 'file:bar:abc', false); test('file:foo:abc', 'file:foo:123', false); test(_1.Uri.file('file:foo:abc'), _1.Uri.file('file:foo:abc'), true); test(_1.Uri.file('file:foo:abc'), 'file:foo:abc', true); test(_1.Uri.file('file:foo:abc'), 'file:foo:123', false); test(_1.Uri.file('file:foo:abc'), 'foo', false); }); }); });