mirror of https://github.com/jo/docuri.git
(closes #7) - implements arity and parts
`docuri.parts` array of components, without trailing `undefined` components `docuri.arity` length of parts.pull/9/head
parent
cdeea1fb4d
commit
4da8a2b0a2
@ -0,0 +1,36 @@
|
||||
var test = require('tap').test;
|
||||
var arity = require('..').arity;
|
||||
|
||||
test('arity of type string', function(t) {
|
||||
t.equal(arity('type'), 1, 'should return 1');
|
||||
t.end();
|
||||
});
|
||||
test('arity of type/id string', function(t) {
|
||||
t.equal(arity('type/id'), 2, 'should return 2');
|
||||
t.end();
|
||||
});
|
||||
test('arity of type/id/subtype string', function(t) {
|
||||
t.equal(arity('type/id/subtype'), 3, 'should return 3');
|
||||
t.end();
|
||||
});
|
||||
test('arity of type//subtype string', function(t) {
|
||||
t.equal(arity('type//subtype'), 3, 'should return 3');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('arity of type object', function(t) {
|
||||
t.equal(arity({ type: 'type' }), 1, 'should return 1');
|
||||
t.end();
|
||||
});
|
||||
test('arity of type/id object', function(t) {
|
||||
t.equal(arity({ type: 'type', id: 'id'}), 2, 'should return 2');
|
||||
t.end();
|
||||
});
|
||||
test('arity of type/id/subtype object', function(t) {
|
||||
t.equal(arity({ type: 'type', id: 'id', subtype: 'subtype' }), 3, 'should return 3');
|
||||
t.end();
|
||||
});
|
||||
test('arity of type//subtype object', function(t) {
|
||||
t.equal(arity({ type: 'type', subtype: 'subtype' }), 3, 'should return 3');
|
||||
t.end();
|
||||
});
|
@ -0,0 +1,28 @@
|
||||
var test = require('tap').test;
|
||||
var docuri = require('..');
|
||||
|
||||
test('default configuration', function(t) {
|
||||
t.deepEqual(docuri(), ['type', 'id', 'subtype', 'index', 'version'], 'should return default parts');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('set configuration', function(t) {
|
||||
var parts = ['my', 'parts'];
|
||||
t.type(docuri(parts).merge, 'function', 'should return docuri api: merge');
|
||||
t.type(docuri(parts).parse, 'function', 'should return docuri api: parse');
|
||||
t.type(docuri(parts).stringify, 'function', 'should return docuri api: stringify');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('change configuration', function(t) {
|
||||
var parts = ['my', 'parts'];
|
||||
docuri(parts);
|
||||
t.deepEqual(docuri(), parts, 'should return custom parts');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('use changed configuration', function(t) {
|
||||
var parts = ['my', 'parts'];
|
||||
t.deepEqual(docuri(parts).parse('one/two'), { my: 'one', parts: 'two'}, 'should use custom parts');
|
||||
t.end();
|
||||
});
|
@ -1,28 +1,36 @@
|
||||
var test = require('tap').test;
|
||||
var docuri = require('..');
|
||||
var parts = require('..').parts;
|
||||
|
||||
test('default configuration', function(t) {
|
||||
t.deepEqual(docuri(), ['type', 'id', 'subtype', 'index', 'version'], 'should return default parts');
|
||||
test('parts of type string', function(t) {
|
||||
t.deepEqual(parts('type'), ['type'], 'should return array including type');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('set configuration', function(t) {
|
||||
var parts = ['my', 'parts'];
|
||||
t.type(docuri(parts).merge, 'function', 'should return docuri api: merge');
|
||||
t.type(docuri(parts).parse, 'function', 'should return docuri api: parse');
|
||||
t.type(docuri(parts).stringify, 'function', 'should return docuri api: stringify');
|
||||
test('parts of type/id string', function(t) {
|
||||
t.deepEqual(parts('type/id'), ['type', 'id'], 'should return array including type and id');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('change configuration', function(t) {
|
||||
var parts = ['my', 'parts'];
|
||||
docuri(parts);
|
||||
t.deepEqual(docuri(), parts, 'should return custom parts');
|
||||
test('parts of type/id/subtype string', function(t) {
|
||||
t.deepEqual(parts('type/id/subtype'), ['type', 'id', 'subtype'], 'should return array including type, id and subtype');
|
||||
t.end();
|
||||
});
|
||||
test('parts of type//subtype string', function(t) {
|
||||
t.deepEqual(parts('type//subtype'), ['type', undefined, 'subtype'], 'should return array including type, undefined and subtype');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('use changed configuration', function(t) {
|
||||
var parts = ['my', 'parts'];
|
||||
t.deepEqual(docuri(parts).parse('one/two'), { my: 'one', parts: 'two'}, 'should use custom parts');
|
||||
test('parts of type object', function(t) {
|
||||
t.deepEqual(parts({ type: 'type' }), ['type'], 'should return array including type');
|
||||
t.end();
|
||||
});
|
||||
test('parts of type/id object', function(t) {
|
||||
t.deepEqual(parts({ type: 'type', id: 'id'}), ['type', 'id'], 'should return array including type and id');
|
||||
t.end();
|
||||
});
|
||||
test('parts of type/id/subtype object', function(t) {
|
||||
t.deepEqual(parts({ type: 'type', id: 'id', subtype: 'subtype' }), ['type', 'id', 'subtype'], 'should return array including type, id and subtype');
|
||||
t.end();
|
||||
});
|
||||
test('parts of type//subtype object', function(t) {
|
||||
t.deepEqual(parts({ type: 'type', subtype: 'subtype' }), ['type', undefined, 'subtype'], 'should return array including type, undefined and subtype');
|
||||
t.end();
|
||||
});
|
||||
|
Loading…
Reference in New Issue