This breaks backwards compatibility.
This removes .routes because it's not intuitive what the result value
of that must be, and users are free to .map over .route themselves.
Also, .routes was never tested.
Fixes#14.
9 years ago
13 changed files with 187 additions and 115 deletions
t.equal(docuri.content('page/mypage/content/mycontent',{id:'othercontent'}),'page/mypage/content/othercontent','merged content has "id" set to "othercontent"');
t.equal(content('page/mypage/content/mycontent',{id:'othercontent'}),'page/mypage/content/othercontent','merged content has "id" set to "othercontent"');
t.deepEqual(docuri.content('page/mypage/content/mycontent'),{page_id:'mypage',id:'mycontent'},'parsed content has "page_id" set to "mypage" and "id" set to "mycontent"');
t.equal(docuri.content({page_id:'mypage',id:'mycontent'}),'page/mypage/content/mycontent','stringified content results in "page/mypage/content/mycontent"');
t.deepEqual(content('page/mypage/content/mycontent'),{page_id:'mypage',id:'mycontent'},'parsed content has "page_id" set to "mypage" and "id" set to "mycontent"');
t.equal(content({page_id:'mypage',id:'mycontent'}),'page/mypage/content/mycontent','stringified content results in "page/mypage/content/mycontent"');
t.end();
});
test('named parameters replaced all at once',function(t){
varpage=docuri.route('page/:id/:bar');
t.equal(page({id:':bar',bar:'foo'}),'page/:bar/foo','url built correctly, no conflicts',{todo:true});
t.end();
});
test('named parameter followed by optional parameter',function(t){
docuri.route('page/:id(/:optional)','page');
varpage=docuri.route('page/:id(/:optional)');
t.deepEqual(page('page/mypage'),{id:'mypage'},'parsed page has "id" set to "mypage"');
t.equal(page({id:'mypage',optional:'number'}),'page/mypage/number','stringified page results in "page/mypage/number"');
t.end();
});
test('named parameter with colon in the content',function(t){
varpage=docuri.route('page/:id');
t.deepEqual(page(page({id:'value:colon'})),{id:'value:colon'},'parsed page has colon set back correctly');
t.end();
});
test('named parameter with slash in the content',function(t){
varpage=docuri.route('page/:id');
t.deepEqual(page(page({id:'value/slash'})),{id:'value/slash'},'parsed page has slash set back correctly');
t.end();
});
test('named parameter with parens in the content',function(t){
varpage=docuri.route('page/:id');
t.deepEqual(docuri.page('page/mypage'),{id:'mypage'},'parsed page has "id" set to "mypage"');
t.equal(docuri.page({id:'mypage',optional:'number'}),'page/mypage/number','stringified page results in "page/mypage/number"');
t.deepEqual(page(page({id:'value(slash)'})),{id:'value(slash)'},'parsed page has parens set back correctly',{todo:true});